Rubik's Cube Programming Assignment: Write a Program to Solve a Scrambled Rubik's Cube, Assignments of Computer Science

A programming assignment for a university course on artificial intelligence. Students are required to write a program to solve a rubik's cube by producing a sequence of moves given any initial configuration of the cube. Details on how to encode cube configurations and moves, and sets out the point allocation and bonus points for the assignment.

Typology: Assignments

Pre 2010

Uploaded on 03/18/2009

koofers-user-2n1
koofers-user-2n1 🇺🇸

10 documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CAP4621 Artificial Intelligence
Programming Assignment (10 points)
November 3, 2003
In this programming assignment you have to write a program, in your
language of choice (see the bonus section), to solve on of the most popular
puzzles of all time Rubik’s cube. Rubik’s cube, depicted in Figure 1,
is composed of a skeleton that keeps together the six central pieces whose
relative position can never be changed, eight corner pieces and 12 middle-
side pieces. In it’s solved state, all the 9 independent squares composing
the face of the cube have the same color. Each of the faces can be rotated
independently, ration that will change the configuration of the cube. Your
assignment, at a very high level, is to write a program that will produce a
sequence of such moves given any initial configuration of the cube.
Figure 1: Picture of Rubik’s cube.
In order to be more specific about your assignment we have to formalize
1
pf3
pf4
pf5

Partial preview of the text

Download Rubik's Cube Programming Assignment: Write a Program to Solve a Scrambled Rubik's Cube and more Assignments Computer Science in PDF only on Docsity!

CAP4621 – Artificial Intelligence

Programming Assignment (10 points)

November 3, 2003

In this programming assignment you have to write a program, in your language of choice (see the bonus section), to solve on of the most popular puzzles of all time – Rubik’s cube. Rubik’s cube, depicted in Figure 1, is composed of a skeleton that keeps together the six central pieces whose relative position can never be changed, eight corner pieces and 12 middle- side pieces. In it’s solved state, all the 9 independent squares composing the face of the cube have the same color. Each of the faces can be rotated independently, ration that will change the configuration of the cube. Your assignment, at a very high level, is to write a program that will produce a sequence of such moves given any initial configuration of the cube.

Figure 1: Picture of Rubik’s cube.

In order to be more specific about your assignment we have to formalize

the way we encode cube configurations and moves. One possibility is to use a flattened representation of the cube, depicted in Figure 2, as a guide for the formalization. In this standard representation, the six faces are drawn in a cross shape. The names of the faces are Front (white), Up (blue), Down(green), bacK(yellow), Left(orange) and Right(red). We will use only the bold letters in the name to designate the face as well as the color of the pieces (with respect to the solved puzzle). Now, to encode any scrambled state of the cube – one such state is represented in Figure 3 – it is enough to specify the color of 6 × 8 = 54 squares (there is no reason to specify the color of the central squares for any of the faces since no move can change these squares). Using the representation we adopted for the cube, we can specify the entire state by enumerating all the colors top-down and left-right. The encoding of the state of the state in Figure 3 is thus: LLLLLLLFFFU- UUKKKFFUUKKFFFUUUKKKRRRRRRRRDDDDDDDD. Now that we have a representation for the state we need a representation for the moves. First, we have 6 × 2 possible moves: rotate each of the faces clock-wise or counter-clock-wise. Since this is still slightly interpretable, we use the diagram in Figure 4 to specify the moves. If the move is performed in the direction indicated by the arrows, we use the upper case letter desig- nating the color of the center piece. If the move is in the inverse direction, we use the lower case letter. For example, by performing the F move on the state in Figure 3 we obtainer the state in Figure 5. We can now be very specific about what you have to do in this program- ming assignment: write a program that takes as input cube states of the form LLLLLLLFFFUUUKKKFFUUKKFFFUUUKKKRRRRRRRRD- DDDDDDD and produces sequences of actions of the form rLRlFuFu that, when executed, unscramble the cube. More specifically, the point allo- cation is the following:

  • Correct modeling of the cube [2pt]
  • Providing correct solutions under 2 minutes of computational time [6pt]
  • Good software design (commented code, easily extendable) [2pt]

The programming assignment is due in the last day of class. In addition to these basic requirements, you can earn bonus points if you:

  • Write your program in PROLOG and it is working correctly [5pt]

U

L F

D

K

R

Figure 2: Flat representation of the cube.

U U

U

U

U

U

U

U

L R

U

D

K

R R R

R

R R R

R

F

F F F

F

F F F

F

K K K

K

K K K

K

D D D

D

D D D

D

L L L

L

L L L

L

Figure 3: Representation of the scrambled cube.

U U

U

U U U

U U

L R

U

D

K

F

K

K

K

F F

F

F

D D

D

D D D

D

F

R R R

R

R

R

R

R K

K

K K K

L L L

L L

L

L

L

F F F

D

Figure 5: Result of applying the F move to the cube in state in Figure 3