The magazine of the Melbourne PC User Group
Rubik's Cube - Part 4 of 5
Solution Continues
Ken Holmes |
 |
Middle
Layer Edge Cubes
In Part 3, we sorted the top layer and we now invert the whole cube to put it on the bottom. We only have to
deal with edge cubes in the middle layer and these may be at any of eight positions with two possible
orientations in the top or middle layers. We must preserve the bottom layer and any previously sorted middle
edge cubes but can freely use the top layer. Transferring a cube between top and middle layers involves seven
face rotations which need close study if you wish to understand them. They exhibit a sort of asymmetry due to
the need to reverse later any rotations which disturb already sorted cubes.
In Listing 8, you may note that,
in SUB Edges2(), we first check the middle layer for the 1/f cube and, unless it is already correct, move it
to the top layer. Next, we check the top layer for the 1/f cube and move it to u/r. From here, there are two
alternative routines, in SUB Edges2a(), to transfer it to its correct position and orientation.
Top Corners
Unless something has gone seriously wrong, the four top corner cubes are now in the top layer but probably
not in correct position or orientation. Each has one face the same colour as the centre of the U face, with
the other faces the same as the centres of two adjacent side faces. In accordance with the procedure in Don
Taylor's book, we need to get them into one of four patterns and then apply an appropriate sequence of moves
to get them into correct position. At this stage, we ignore their orientation as this will be corrected later
in SUB Twirl().
|

Figure 4. Bottom and middle layers completely sorted
|
To
identify the pattern we will use a four digit variable called "order" in which the thousands digit will be 1
if the a/r/f cube is correct, the hundreds digit 1 if u/r/b is correct, the tens digit 1 if u/l/b is correct
and the units digit 1 if u/l/f is correct. If we get "order" equal to 1111, all cubes are in position. The
patterns which can be used to go to a proper sorting have u/r/f correct but u/r/b incorrect; if we don't meet
this condition, we rotate the U face until we do so. In Listing 9,
to achieve this we use a DO LOOP which we don't even enter if order = 1111. The useful values for "order" are
1010, 1001 and 1000 so we look for 900 < order < 1100 to exclude values like 1100 and 0100 which don't
suit us. Orders 1010 and 1001 entail a swap of two cubes but 1000 entails a circulation of three cubes in
either clockwise or anticlockwise direction.
If we need to go through the loop more than once the whole cube is rotated 90 deg. about the vertical axis
which might convert, say, a 0100 pattern to 1000. Of course, you could devise a correction sequence directly
from 0100 and it is purely for convenience, and minimising code, that we adopt this approach. Note that the
correction sequences under SELECT CASE are quite complex and expert cube twiddlers no doubt find the face
mnemonics useful in memorising them. It is simpler to position the cube first in 10?? order to avoid a
further three sets of four sequences.
The Story So Far
Fig 4 shows our progress - the bottom and middle layers are completely sorted and we have the top corner
cubes in position but not necessarily correctly oriented. In Part 5, we will position the top edge cubes,
ignoring orientation. Then we will check the top edge cubes and, if necessary, flip them to match faces, and
finally return to the top corner cubes to twirl them, clockwise or anticlockwise as necessary, so that their
colours end up on the proper faces.
Note: Concluded in PC Update Onlinefor June 2000 with full listings and files.
Reprinted from the May 2000 issue of PC Update, the magazine of
Melbourne PC User Group, Australia
|