Visual Basic 2010 (Console) Guide
Pocket Cube - Moves

Using the Indexing functions and the helper arrays we wrote earlier, we can write functions to calculate the permutation or orientation of the puzzle after a move has been applied to a given cube state.

These functions become quite straightforward to write when we have those other details in place. As always, the hard work is in the preparation and not the doing.

To map the permutations, we use,

' Calculate Positions After A Given Move F = 0, R = 1, U = 2
Function DoPermMap(ByVal pos As Integer, ByVal move As Integer) As Integer
   Dim perms() As Byte = IndexToPermutation(pos, 7)
   Dim newperms(7) As Byte
   For i As Integer = 1 To 7
      newperms(i) = perms(mapPerm(move, i))
   Next
   Return PermutationToIndex(newperms, 7)
End Function

To map the orientations, we also have to account for the movement of the pieces,

'Calculate Orientations After A Given Move F = 0, R = 1, U = 2
Function DoOrientationMap(ByVal pos As Integer, ByVal move As Integer) As Integer
   Dim oris() As Byte = IdxToOrientation(pos, 7, 3)
   Dim neworis(7) As Byte
   For i As Integer = 1 To 7
      neworis(i) = oris(mapPerm(move, i))
      neworis(i) = (neworis(i) + mapOri(move, i)) Mod 3
   Next
   Return OrientationToIdx(neworis, 7, 3)
End Function

One thing that hasn't been made clear so far. We don't need to have separate code for F, F2 and F'. F2 is the result of doing F twice. F' is the equivalent of 3 F moves. By applying these functions more than once, all 9 of our valid moves can be achieved.