Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
'First 55 lines of code are to open and read from a file that was written by the cube recognition program
'The recongition program was written in python running on a raspberry pi
'It was orginally intended that it would run as a webserver using flask and this Small Basic program would use the Network.GetWebPageContents to get the data
'the file has 12 lines, 6 sets of 2 pairs of lines. First line is which face it is and the second line is a string of 9 char of the colors of that face
'We have 6 arrays that are 2 dimentional 3 x 3 (row,colum) to store the colors
For line = 1 To 6
dataface = File.ReadLine("C:\Data\Robitics\MacTwist.txt",line*2-1)
datatile = File.ReadLine("C:\Data\Robitics\MacTwist.txt",line*2)
If line = 1 Then
For colum = 1 To 3
For row = 1 to 3
face[row][colum] = Text.GetSubText(datatile, colum + (row-1) *3,1)
Endfor
EndFor
EndIf
If line = 2 Then
For colum = 1 To 3
For row = 1 to 3
down[row][colum] = Text.GetSubText(datatile, colum + (row-1) *3,1)
Endfor
EndFor
EndIf
If line = 3 Then
For colum = 1 To 3
For row = 1 to 3
left[row][colum] = Text.GetSubText(datatile, colum + (row-1) *3,1)
Endfor
EndFor
EndIf
If line = 4 Then
For colum = 1 To 3
For row = 1 to 3
right[row][colum] = Text.GetSubText(datatile, colum + (row-1) *3,1)
Endfor
EndFor
EndIf
If line = 5 Then
For colum = 1 To 3
For row = 1 to 3
top[row][colum] = Text.GetSubText(datatile, colum + (row-1) *3,1)
Endfor
EndFor
EndIf
If line = 6 Then
For colum = 1 To 3
For row = 1 to 3
back[row][colum] = Text.GetSubText(datatile, colum + (row-1) *3,1)
Endfor
EndFor
EndIf
EndFor
'A motor = Top - for CW
'B motor = Down + for CW
'C motor = Face - for CW
'D motor = Left - for CW
'2A motor = Right + for CW
'2B motor = back + for CW
'these are just the setting for the motor speeds for the Motor.SchedulePower whenturning the faces to try to get the motors to turn exacly 90 degrees
Apos1 = 25
Apos2 = 65
Aneg1 = 25
Aneg2 = 65
Bpos1 = 10
Bpos2 = 80
Bneg1 = 45
Bneg2 = 45
Cpos1 = 45
Cpos2 = 45
Cneg1 = 45
Cneg2 = 45
Dpos1 = 20
Dpos2 = 70
Dneg1 = 50
Dneg2 = 40
A2pos1 = 65
A2pos2 = 25
A2neg1 = 50
A2neg2 = 40
B2pos1 = 50
B2pos2 = 40
B2neg1 = 60
B2neg2 = 30
'initlize the graphics window for the display of what the program is doing
GraphicsWindow.CanResize = "FALSE"
GraphicsWindow.BackgroundColor = "Black"
GraphicsWindow.Title = "MacTwist"
GraphicsWindow.Top = 0
GraphicsWindow.Left = 0
GraphicsWindow.Width = 1400
GraphicsWindow.Height = 700
'All sub rountine can be found at the end of the code
'call the subroutine that draw the current faces on the screen
WriteCube()
'STEP 1 - The White Cross
'first thing we do is look to see if there is a white tile already on the top and if so then turn the top face to place that tile in correct plave based upon what the tile colour is on the side of that tile
If top[1][2] = "W" Then
If back[1][2] = "O" Then
Ti()
Elseif back[1][2] = "G" Then
T()
T()
ELseif back[1][2] = "R" Then
T()
EndIf
Elseif top[2][1] = "W" Then
If left[1][2] = "B" Then
T()
Elseif left[1][2] = "R" Then
T()
T()
ELseif left[1][2] = "G" Then
Ti()
EndIf
Elseif top[2][3] = "W" Then
If right[1][2] = "G" Then
T()
Elseif right[1][2] = "O" Then
T()
T()
ElseIF right[1][2] = "B" Then
Ti()
EndIf
Elseif top[3][2] = "W" Then
If face[1][2] = "O" Then
T()
ELseif face[1][2] = "B" Then
T()
T()
ELseif face[1][2] = "R" Then
Ti()
EndIF
EndIf
'This is the main loop for step one. It has the most amount of testing as it has the most amount ofm possible places the needed tiles can be
'As we get though each step then more tiles become in corretc place so ther is less places to look for incorrect tiles
'Small basic doesn't have a loop until so we have to use a loop while and we use a exit flag call step2exit and it is set to true and when we want to exit the loop we change it to false
step1exit = "TRUE"
While step1exit
'We will check the 4 possible places on bottom face for the tiles we are looking and if we find one then place it in correct place on top face.
If down[1][2] = "W" Then
If face[3][2] = "G" Then
F()
F()
ElseIf face[3][2] = "R" Then
D()
R()
R()
ElseIf face[3][2] = "O" Then
Di()
L()
L()
ElseIf face[3][2] = "B" Then
D()
D()
B()
B()
EndIf
ElseIf down[2][1] = "W" Then
If left[3][2] = "O" Then
L()
L()
ElseIf left[3][2] = "G" Then
D()
F()
F()
ElseIf left[3][2] = "R" Then
D()
D()
R()
R()
ElseIf left[3][2] = "B" Then
Di()
B()
B()
EndIf
ElseIf down[2][3] = "W" Then
If right[3][2] = "R" Then
R()
R()
ElseIf right[3][2] = "B" Then
D()
B()
B()
ElseIF right[3][2] = "O" Then
D()
D()
L()
L()
ElseIf right[3][2] = "G" Then
Di()
F()
F()
EndIf
ElseIf down[3][2] = "W" Then
If back[3][2] = "B" Then
B()
B()
ELseIf back[3][2] = "R" Then
Di()
R()
R()
ElseIF back[3][2] = "O" Then
D()
L()
L()
ElseIF back[3][2] = "G" Then
D()
D()
F()
F()
EndIf
'If we haven't found any on bottom face then we will chech the 4 faces around the sides in the 2nd row of the cube and place then on the bottom so that next time we loop around we will find them and place then on top face
ElseIF face[2][1] = "W" Then
L()
D()
Li()
ElseIf face[2][3] = "W" Then
Ri()
Di()
R()
ELseIf right[2][1] = "W" Then
F()
D()
Fi()
ElseIf right[2][3] = "W" Then
Bi()
Di()
B()
ElseIf left[2][1] = "W" Then
B()
D()
Bi()
ElseIf left[2][3] = "W" Then
Fi()
D()
F()
ElseIf back[2][1] = "W" Then
R()
D()
Ri()
ElseIf back[2][3] = "W" Then
Li()
D()
L()
'if none was in the 2nd row then we look on the top row and place them on the second row so that next time we loop around it will find them
ElseIf face[1][2] = "W" Then
F()
ELseIf right[1][2] = "W" Then
R()
ElseIf left[1][2] = "W" Then
L()
ElseIf back[1][2] = "W" Then
B()
'If none found on 1st row look on bottom and place into 2nd row of a face that doesn't have a correct tile on top face turn that face to place tile in row 2 so that it will be found next loop around
ElseIf face[3][2] = "W" Then
If top[3][2] <> "W" Then
F()
ElseIf top[2][1] <> "W" Then
Di()
Li()
ElseIf top[2][3] <> "W" Then
D()
R()
ELseIf top[1][2] <> "W" Then
D()
D()
B()
EndIf
ElseIf left[3][2] = "W" Then
If top[2][1] <> "W" Then
Li()
ElseIf top[3][2] <> "W" Then
D()
F()
Elseif top[1][2] <> "W" Then
Di()
B()
ElseIf top[2][3] <> "W" Then
D()
D()
R()
EndIf
ElseIf right[3][2] = "W" Then
If top[2][3] <> "W" Then
R()
ElseIf top[3][2] <>"W" Then
Di()
F()
ElseIf top[1][2] <> "W" Then
D()
B()
ElseIf top[2][1] <> "W" Then
D()
D()
L()
EndIf
ElseIf back[3][2] = "W" Then
If top[1][2] <> "W"Then
B()
ElseIf top[2][1] <> "W" Then
D()
L()
ElseIf top[2][3] <> "W" Then
Di()
R()
ElseIf top[3][2] <> "W" Then
D()
D()
F()
EndIf
'If none found there then check top face for a correct tile on top but wronf tile on side face and turn it to bootom face to be found next loop around
ElseIf top[1][2] = "W" And back[1][2] <> "B" Then
B()
B()
ElseIf top[2][1] = "W" ANd left[1][2] <> "O" Then
L()
L()
ElseIf top[2][3] = "W" And right[1][2] <> "R" Then
R()
R()
ElseIf top[3][2] = "W" And face[1][2] <> "G" Then
F()
F()
EndIf
'test to see if top cross is complete if it is then switch the exit flag to exit loop
If top[1][2] = "W" And back[1][2] = "B" And top[2][1] = "W" And left[1][2] = "O" And top[2][3] = "W" And right[1][2] = "R" And top[3][2] = "W" And face[1][2] = "G" Then
step1exit = "FALSE"
EndIf
'write the updated cube to the screen for user to see
WriteCube()
EndWhile
'now that we have exited the loop because top cross is complete write the cube to the screen and also write that the top cross is completed to screen as well
WriteCube()
GraphicsWindow.FontSize = 20
GraphicsWindow.BrushColor = "White"
GraphicsWindow.DrawText(50,50,"TOP CROSS COMPLETED!")
'STEP 2 - The White Corners
'set exit flag for loop same as first loop
step2exit = "TRUE"
While step2exit
'check the 3rd row of each of the 4 side faces for the needed tile and move to correct place on top face.
If face[3][1] = "W" Then
If left[3][3] = "G" Then
D()
D()
F()
Di()
Fi()
ElseIf left[3][3] = "O" Then
D()
L()
Di()
Li()
ElseIf left[3][3] = "R" Then
Di()
R()
Di()
Ri()
ElseIf left[3][3] = "B" Then
B()
Di()
Bi()
EndIf
ElseIf face[3][3] = "W" Then
If right[3][1] = "R" Then
Di()
Ri()
D()
R()
ElseIf right[3][1] = "G" Then
Di()
Di()
Fi()
D()
F()
ElseIf right[3][1] = "O" Then
D()
Li()
D()
L()
ElseIf right[3][1] = "B" Then
Bi()
D()
B()
EndIf
ElseIf right[3][1] = "W" Then
If face[3][3] = "G" Then
D()
F()
Di()
Fi()
ElseIf face[3][3] = "O" Then
L()
Di()
Li()
Elseif face[3][3] = "R" Then
D()
D()
R()
Di()
Ri()
Elseif face[3][3] = "B" Then
Di()
B()
Di()
Bi()
EndIf
ElseIf right [3][3] = "W" THen
If back[3][1] = "O" THen
Li()
D()
L()
ElseIf back[3][1] = "G" Then
D()
Fi()
D()
F()
ElseIf back[3][1] = "R" Then
D()
D()
Ri()
D()
R()
ELseIf back[3][1] = "B" Then
Di()
Bi()
D()
B()
EndIf
ElseIf left[3][1] = "W" Then
If back[3][3] = "O" Then
D()
D()
L()
Di()
Li()
ElseIf back[3][3] = "G" Then
Di()
F()
Di()
Fi()
ElseIf back[3][3] = "R" Then
R()
Di()
Ri()
ElseIf back[3][3] = "B" Then
D()
B()
Di()
Bi()
EndIf
ElseIf left[3][3] = "W" Then
If face[3][1] = "O" Then
Di()
Di()
Li()
D()
L()
ElseIf face[3][1] = "G" Then
Di()
Fi()
D()
F()
ElseIf face[3][1] = "R" Then
Ri()
D()
R()
ElseIf face[3][1] = "B" Then
D()
Bi()
D()
B()
EndIf
ElseIf back[3][1] = "W" Then
If right[3][3] = "O" Then
Di()
L()
Di()
Li()
ElseIf right[3][3] = "G" Then
F()
Di()
Fi()
ELseIf right[3][3] = "R" Then
D()
R()
Di()
Ri()
ElseIf right[3][3] = "B" Then
D()
D()
B()
Di()
Bi()
EndIf
ElseIf back[3][3] = "W" Then
If left[3][1] = "O" Then
Di()
Li()
D()
L()
ElseIf left[3][1] = "G" Then
Fi()
D()
F()
Elseif left[3][1] = "R" Then
D()
Ri()
D()
R()
ElseIf left[3][1] = "B" Then
D()
D()
Bi()
D()
B()
EndIf
'if none was found in rows of side faces check row 1 of side faces and shift to row 3 to be found next loop around
ElseIf face[1][1] = "W" Then
Fi()
Di()
F()
ElseIf face[1][3] = "W" Then
F()
D()
Fi()
ElseIf right[1][1] = "W" Then
Ri()
Di()
R()
ElseIf right[1][3] = "W" Then
R()
D()
Ri()
ElseIf left[1][1] = "W" Then
Li()
Di()
L()
ElseIf left[1][3] = "W" Then
L()
D()
Li()
ElseIf back[1][1] = "W" Then
Bi()
Di()
B()
ElseIf back[1][3] = "W" Then
B()
D()
Bi()
'if none found then check bottom face and move to row 3 of side face to be found next loop around
ElseIf down[1][1] = "W" Then
If top[3][1] <> "W" Then
L()
D()
Li()
ElseIf top[1][1] <> "W" Then
Di()
Li()
D()
L()
ElseIf top[1][3] <> "W" Then
D()
D()
R()
Di()
Ri()
ElseIf top[3][3] <> "W" Then
D()
Ri()
D()
R()
EndIf
ElseIf down[1][3] = "W" Then
If top[1][1] <> "W" Then
D()
D()
Li()
D()
L()
ElseIf top[1][3] <> "W" Then
D()
R()
Di()
Ri()
ElseIf top[3][1] <> "W" Then
Di()
L()
Di()
Li()
ElseIf top[3][3] <> "W" Then
Ri()
D()
R()
EndIf
ELseIf down[3][1] = "W" Then
If top[1][1] <> "W" Then
B()
Di()
Bi()
ELseIf top[1][3] <> "W" Then
Di()
R()
Di()
Ri()
ElseIf top[3][1] <> "W" Then
D()
L()
Di()
Li()
ElseIf top[3][3] <>"W" Then
D()
D()
Ri()
D()
R()
EndIf
ElseIf down[3][3] = "W" Then
If top[1][1] <> "W" THen
D()
Li()
D()
L()
ElseIf top[1][3] <> "W" Then
R()
Di()
Ri()
ElseIf top[3][1] <> "W" Then
D()
D()
Fi()
D()
F()
ELseIf top[3][3] <> "W" Then
Di()
Ri()
D()
R()
EndIf
'if none found so far then check for a correct top tile with wrong side tile and move to row 3 of side face to be found next loop around
ElseIf left[1][3] <> "O" Or face[1][1] <> "G" And top[3][1] = "W" Then
Fi()
Di()
F()
ElseIf face[1][3] <> "G" Or right[1][1] <> "R" ANd top[3][3] = "W" Then
Ri()
Di()
R()
ElseIf right[1][3] <> "R" Or back[1][1] <> "B" And top[1][3] = "W" Then
R()
D()
Ri()
ElseIf left[1][1] <> "O" Or back[1][3] <> "B" And top[1][1] = "W" Then
B()
D()
Bi()
EndIf
'check to see if top coners are complete and if so then switch exit flag
If top[1][1] = "W" And top[1][3] = "W" And top[3][1] = "W" And top[3][3] = "W" And face[1][1] = "G" And face[1][3] = "G" And left[1][1] = "O" And left[1][3] = "O" And right[1][1] = "R" And right[1][3] = "R" And back[1][1] = "B" And back[1][3] = "B" Then
step2exit = "FALSE"
EndIf
'update cube to screen and also write top corners completed to screen
WriteCube()
EndWhile
WriteCube()
GraphicsWindow.FontSize = 20
GraphicsWindow.BrushColor = "White"
GraphicsWindow.DrawText(50,100,"TOP CORNERS COMPLETED!")
'STEP 3 - The Middle Layer
'set exit flag
step3exit = "TRUE"
While step3exit
'set flag that lets me know if something was moved to false
moved = "FALSE"
'check the 4 possible place on the bottom face of any needed tiles and move then to correct place and switch moved flag to true
If face[3][2] = "O" Then
If down[1][2] = "B" Then
B()
Di()
Bi()
Di()
Li()
D()
L()
moved = "TRUE"
ElseIf down[1][2] = "G" Then
D()
D()
Fi()
D()
F()
D()
L()
Di()
Li()
moved = "TRUE"
EndIf
EndIf
If face[3][2] = "G" Then
If down[1][2] = "O" Then
D()
L()
Di()
Li()
Di()
Fi()
D()
F()
moved = "TRUE"
ElseIf down[1][2] = "R" Then
Di()
Ri()
D()
R()
D()
F()
Di()
Fi()
moved = "TRUE"
EndIf
EndIf
If face[3][2] = "R" Then
If down[1][2] = "G" Then
D()
D()
F()
Di()
Fi()
Di()
Ri()
D()
R()
moved = "TRUE"
ElseIf down[1][2] = "B" Then
Bi()
D()
B()
D()
R()
Di()
Ri()
moved = "TRUE"
EndIf
EndIf
If face[3][2] = "B" Then
If down[1][2] = "R" Then
Di()
R()
Di()
Ri()
Di()
Bi()
D()
B()
moved = "TRUE"
ElseIf down[1][2] = "O" Then
D()
Li()
D()
L()
D()
B()
Di()
Bi()
moved = "TRUE"
EndIf
EndIf
If right[3][2] = "R" Then
If down[2][3] = "G" Then
D()
F()
Di()
Fi()
Di()
Ri()
D()
R()
moved = "TRUE"
ElseIf down[2][3] = "B" Then
Di()
Bi()
D()
B()
D()
R()
Di()
Ri()
moved = "TRUE"
EndIf
EndIf
If right[3][2] = "G" Then
If down[2][3] = "O" Then
L()
Di()
Li()
Di()
Fi()
D()
F()
moved = "TRUE"
ElseIf down[2][3] = "R" Then
D()
D()
Ri()
D()
R()
D()
F()
Di()
Fi()
moved = "TRUE"
EndIf
EndIf
If right[3][2] = "O" Then
If down[2][3] = "B" Then
Di()
B()
Di()
Bi()
Di()
Li()
D()
L()
moved = "TRUE"
ElseIf down[2][3] = "G" Then
D()
Fi()
D()
F()
D()
L()
Di()
Li()
moved = "TRUE"
EndIf
EndIf
If right[3][2] = "B" Then
If down[2][3] = "R" Then
D()
D()
R()
Di()
Ri()
Di()
Bi()
D()
B()
moved = "TRUE"
ElseIf down[2][3] = "O" Then
Li()
D()
L()
D()
B()
Di()
Bi()
moved = "TRUE"
EndIf
EndIf
If left[3][2] = "O" Then
If down[2][1] = "B" Then
D()
B()
Di()
Bi()
Di()
Li()
D()
L()
moved = "TRUE"
ElseIf down[2][1] = "G" Then
Di()
Fi()
D()
F()
D()
L()
Di()
Li()
moved = "TRUE"
EndIf
EndIf
If left[3][2] = "G" Then
If down[2][1] = "O" Then
D()
D()
L()
Di()
Li()
Di()
Fi()
D()
F()
moved = "TRUE"
ElseIf down[2][1] = "R" Then
Ri()
D()
R()
D()
F()
Di()
Fi()
moved = "TRUE"
EndIf
EndIf
If left[3][2] = "B" Then
If down[2][1] = "O" Then
D()
D()
Li()
D()
L()
D()
B()
Di()
Bi()
moved = "TRUE"
ElseIf down[2][1] = "R" Then
R()
Di()
Ri()
Di()
Bi()
D()
B()
moved = "TRUE"
EndIf
EndIf
If left[3][2] = "R" Then
If down[2][1] = "G" Then
Di()
F()
Di()
Fi()
Di()
Ri()
D()
R()
moved = "TRUE"
ElseIf down[3][2] = "B" Then
D()
Bi()
D()
B()
D()
R()
Di()
Ri()
moved = "TRUE"
EndIf
EndIf
If back[3][2] = "B" Then
If down[3][2] = "O" Then
Di()
Li()
D()
L()
D()
B()
Di()
Bi()
moved = "TRUE"
ElseIf down[3][2] = "R" Then
D()
R()
Di()
Ri()
Di()
Bi()
D()
B()
moved = "TRUE"
EndIf
EndIf
If back[3][2] = "O" Then
If down[3][2] = "B" Then
D()
D()
B()
Di()
Bi()
Di()
Li()
D()
L()
moved = "TRUE"
ElseIf down[3][2] = "G" Then
Fi()
D()
F()
D()
L()
Di()
Li()
moved = "TRUE"
EndIf
EndIf
If back[3][2] = "G" Then
If down[3][2] = "O" Then
Di()
L()
Di()
Li()
Di()
Fi()
D()
F()
moved = "TRUE"
ElseIf down[3][2] = "R" Then
D()
Ri()
D()
R()
D()
F()
Di()
Fi()
moved = "TRUE"
EndIf
EndIf
If back[3][2] = "R" Then
If down[3][2] = "G" Then
F()
Di()
Fi()
Di()
Ri()
D()
R()
moved = "TRUE"
ElseIf down[3][2] = "B" Then
D()
D()
Bi()
D()
B()
D()
R()
Di()
Ri()
moved = "TRUE"
EndIf
EndIf
'If nothing found and moved from botom face then look for needed tile in row 2 of side faces and move it to bottom face to be found next loop around
If moved = "FALSE" Then
If face[2][1] <> "G" Or left[2][3] <> "O" And face[2][1] <> "Y" And left[2][3] <> "Y" Then
Fi()
D()
F()
D()
L()
Di()
Li()
ElseIf face[2][3] <> "G" Or right[2][1] <> "R" ANd face[2][3] <>"Y" And right[2][1] <> "Y" Then
Ri()
D()
R()
D()
F()
Di()
Fi()
ElseIf right[2][3] <> "R" Or back[2][1] <> "B" ANd right[2][3] <> "Y" And back[2][1] <> "Y" Then
R()
Di()
Ri()
Di()
Bi()
D()
B()
ELseIf left[2][1] <> "O" Or back[2][3] <> "B" ANd left[2][1] <> "Y" And back[2][3] <> "Y" Then
Li()
D()
L()
D()
B()
Di()
Bi()
ENdIf
EndIf
'write updated cube to screen
WriteCube()
'test if row 2 of side faces is complete and if so then switch exit flag
If face[2][1] = "G" ANd face[2][3] = "G" And right[2][1] = "R" ANd right[2][3] = "R" ANd left[2][1] = "O" ANd left[2][3] = "O" And back[2][1] = "B" And back[2][3] = "B" Then
step3exit = "FALSE"
EndIf
EndWhile
GraphicsWindow.FontSize = 20
GraphicsWindow.BrushColor = "White"
GraphicsWindow.DrawText(50,150,"MIDDLE LAYERS COMPLETED!")
'STEP 4 - The Yellow Cross
step4exit = "TRUE"
While step4exit
'count up number of correct tiles on bottom cross
yellowcount = 0
If down[1][2] = "Y" Then
yellowcount = yellowcount + 1
EndIf
If down[2][1] = "Y" Then
yellowcount = yellowcount + 1
EndIf
If down[2][3] = "Y" Then
yellowcount = yellowcount + 1
EndIf
If down[3][2] = "Y" Then
yellowcount = yellowcount + 1
EndIf
'based upon the number of coreect tiles the take needed action
If yellowcount = 0 Then
F()
D()
L()
Di()
Li()
Fi()
EndIf
If yellowcount = 2 Then
If down[1][2] = "Y" ANd down[2][1] = "Y" Then
D()
D()
EndIf
If down[1][2] = "Y" And down[2][3] = "Y" Then
D()
EndIf
If down[3][2] = "Y" And down[2][1] = "Y" Then
Di()
EndIf
EndIf
If yellowcount = 2 And down[2][3] = "Y" And down[3][2] = "Y" Then
F()
D()
L()
Di()
Li()
Fi()
EndIf
yellowcount = 0
If down[1][2] = "Y" Then
yellowcount = yellowcount + 1
EndIf
If down[2][1] = "Y" Then
yellowcount = yellowcount + 1
EndIf
If down[2][3] = "Y" Then
yellowcount = yellowcount + 1
EndIf
If down[3][2] = "Y" Then
yellowcount = yellowcount + 1
EndIf
If yellowcount = 2 And down[1][2] = "Y" And down[3][2] = "Y" Then
D()
EndIf
If yellowcount = 2 And down[2][1] = "Y" And down[2][3] = "Y" Then
F()
L()
D()
Li()
Di()
Fi()
EndIf
'test if all 4 yellow are correct then switch exit flag
If yellowcount = 4 Then
step4exit = "FALSE"
EndIf
WriteCube()
EndWhile
GraphicsWindow.FontSize = 20
GraphicsWindow.BrushColor = "White"
GraphicsWindow.DrawText(50,200,"YELLOW CROSS COMPLETED!")
'STEP 5 - The Yellow Corners
step5exit = "TRUE"
While step5exit
'count up the number of yellow tiles on corners
yellowcount = 0
If down[1][1] = "Y" Then
yellowcount = yellowcount+1
EndIf
If down[1][3] = "Y" Then
yellowcount = yellowcount+1
EndIf
If down[3][1] = "Y" Then
yellowcount = yellowcount+1
EndIf
If down[3][3] = "Y" Then
yellowcount = yellowcount+1
EndIf
'based upon the number of yellow tiles take needed action
If yellowcount = 0 Then
If back[3][1] = "Y" Then
Di()
ElseIf left[3][1] = "Y" Then
D()
D()
ElseIf face[3][1] = "Y" Then
D()
EndIf
L()
D()
Li()
D()
L()
D()
D()
Li()
EndIf
'after action taken then recount yellow corners
yellowcount = 0
If down[1][1] = "Y" Then
yellowcount = yellowcount+1
EndIf
If down[1][3] = "Y" Then
yellowcount = yellowcount+1
EndIf
If down[3][1] = "Y" Then
yellowcount = yellowcount+1
EndIf
If down[3][3] = "Y" Then
yellowcount = yellowcount+1
EndIf
'based upon the number of yellow corners take needed action
If yellowcount = 1 Then
If down[1][1] = "Y" Then
D()
ElseIf down[3][1] = "Y" Then
Di()
Di()
ElseIf down[3][3] = "Y" Then
Di()
ENdIf
L()
D()
Li()
D()
L()
D()
D()
Li()
EndIf
'count up yellow corner again
yellowcount = 0
If down[1][1] = "Y" Then
yellowcount = yellowcount+1
EndIf
If down[1][3] = "Y" Then
yellowcount = yellowcount+1
EndIf
If down[3][1] = "Y" Then
yellowcount = yellowcount+1
EndIf
If down[3][3] = "Y" Then
yellowcount = yellowcount+1
EndIf
'take needed action
If yellowcount=2 Then
If right[3][3] = "Y" then
Di()
EndIf
L()
D()
Li()
D()
L()
D()
D()
Li()
EndIf
'if all 4 yellow corners are correct then switch exit flag
If yellowcount = 4 Then
step5exit = "FALSE"
EndIf
WriteCube()
EndWhile
GraphicsWindow.FontSize = 20
GraphicsWindow.BrushColor = "White"
GraphicsWindow.DrawText(50,250,"YELLOW CORNERS COMPLETED!")
'STEP 6 - The Bottom Corners
step6exit = "TRUE"
While step6exit
'count up the number of side faces that have both row 3 corners correct
cornermatch = 0
If face[3][1] = face[3][3] Then
cornermatch = cornermatch + 1
EndIf
If right[3][1] = right[3][3] Then
cornermatch = cornermatch + 1
EndIf
If left[3][1] = left[3][3] Then
cornermatch = cornermatch + 1
EndIf
If back[3][1] = back[3][3] Then
cornermatch = cornermatch + 1
EndIf
'based upon corner match take needed action
If cornermatch = 1 Then
If left[3][1] = left[3][3] Then
Di()
ElseIf face[3][1] = face[3][3] Then
D()
D()
ElseIf right[3][1] = right[3][3] Then
D()
EndIf
Li()
F()
Li()
B()
B()
L()
Fi()
Li()
B()
B()
L()
L()
Di()
EndIf
cornermatch = 0
If face[3][1] = face[3][3] Then
cornermatch = cornermatch + 1
EndIf
If right[3][1] = right[3][3] Then
cornermatch = cornermatch + 1
EndIf
If left[3][1] = left[3][3] Then
cornermatch = cornermatch + 1
EndIf
If back[3][1] = back[3][3] Then
cornermatch = cornermatch + 1
EndIf
If cornermatch = 0 Then
Li()
F()
Li()
B()
B()
L()
Fi()
Li()
B()
B()
L()
L()
Di()
EndIf
'if all 4 match then switch exit flag
If cornermatch = 4 Then
step6exit = "FALSE"
EndIf
WriteCube()
EndWhile
GraphicsWindow.FontSize = 20
GraphicsWindow.BrushColor = "White"
GraphicsWindow.DrawText(50,300,"BOTTOM CORNERS COMPLETED!")
'STEP 7 - The Bottom Edges
step7exit = "TRUE"
While step7exit
edgeconter = 0
If face[3][1] = face[3][2] And face[3][1] = face[3][3] Then
edgeconter = edgeconter + 1
EndIf
If right[3][1] = right[3][2] And right[3][1] = right[3][3] Then
edgeconter = edgeconter + 1
EndIf
If left[3][1] = left[3][2] And left[3][1] = left[3][3] Then
edgeconter = edgeconter + 1
EndIf
If back[3][1] = back[3][2] And back[3][1] = back[3][3] Then
edgeconter = edgeconter + 1
EndIf
If edgeconter = 0 Then
F()
F()
D()
R()
Li()
F()
F()
Ri()
L()
D()
F()
F()
EndIf
edgeconter = 0
If face[3][1] = face[3][2] And face[3][1] = face[3][3] Then
edgeconter = edgeconter + 1
EndIf
If right[3][1] = right[3][2] And right[3][1] = right[3][3] Then
edgeconter = edgeconter + 1
EndIf
If left[3][1] = left[3][2] And left[3][1] = left[3][3] Then
edgeconter = edgeconter + 1
EndIf
If back[3][1] = back[3][2] And back[3][1] = back[3][3] Then
edgeconter = edgeconter + 1
EndIf
If edgeconter = 1 Then
If face[3][1] = face[3][2] And face[3][1] = face[3][3] Then
D()
D()
ELseIf right[3][1] = right[3][2] And right[3][1] = right[3][3] Then
D()
ElseIf left[3][1] = left[3][2] And left[3][1] = left[3][3] Then
Di()
EndIf
F()
F()
D()
R()
Li()
F()
F()
Ri()
L()
D()
F()
F()
EndIf
WriteCube()
If edgeconter = 4 Then
step7exit = "FALSE"
EndIf
EndWhile
If face[3][1] = "R" Then
D()
ElseIf face[3][1] = "O" Then
Di()
ElseIf face[3][1] = "B" Then
Di()
Di()
EndIf
WriteCube()
GraphicsWindow.FontSize = 20
GraphicsWindow.BrushColor = "White"
GraphicsWindow.DrawText(50,350,"BOTTOM EDGES COMPLETED!")
GraphicsWindow.DrawText(50,400,"CUBE SOLVED!")
'sub rountine for writing cube to screen
Sub WriteCube
GraphicsWindow.FontSize = 30
GraphicsWindow.BrushColor = "White"
topx = 600
topy = 50
GraphicsWindow.DrawText(topx+85,topy,"TOP")
For r = 1 To 3
For c = 1 To 3
If top[r][c] = "R" Then
GraphicsWindow.BrushColor = "Red"
ElseIf top[r][c] = "B" Then
GraphicsWindow.BrushColor = "Blue"
ElseIf top[r][c] = "O" Then
GraphicsWindow.BrushColor = "Orange"
ElseIf top[r][c] = "G" Then
GraphicsWindow.BrushColor = "Green"
ElseIf top[r][c] = "Y" Then
GraphicsWindow.BrushColor = "Yellow"
ElseIf top[r][c] = "W" Then
GraphicsWindow.BrushColor = "White"
EndIf
GraphicsWindow.FillRectangle(c*50 + topx,r*50 + topy,40,40)
EndFor
EndFor
GraphicsWindow.BrushColor = "Green"
facex = 600
facey = 250
GraphicsWindow.DrawText(facex+85,facey,"FACE")
For r = 1 To 3
For c = 1 To 3
If face[r][c] = "R" Then
GraphicsWindow.BrushColor = "Red"
ElseIf face[r][c] = "B" Then
GraphicsWindow.BrushColor = "Blue"
ElseIf face[r][c] = "O" Then
GraphicsWindow.BrushColor = "Orange"
ElseIf face[r][c] = "G" Then
GraphicsWindow.BrushColor = "Green"
ElseIf face[r][c] = "Y" Then
GraphicsWindow.BrushColor = "Yellow"
ElseIf face[r][c] = "W" Then
GraphicsWindow.BrushColor = "White"
EndIf
GraphicsWindow.FillRectangle(c*50 + facex,r*50 + facey,40,40)
EndFor
EndFor
GraphicsWindow.BrushColor = "Yellow"
downx = 600
downy = 450
GraphicsWindow.DrawText(downx+70,downy,"DOWN")
For r = 1 To 3
For c = 1 To 3
If down[r][c] = "R" Then
GraphicsWindow.BrushColor = "Red"
ElseIf down[r][c] = "B" Then
GraphicsWindow.BrushColor = "Blue"
ElseIf down[r][c] = "O" Then
GraphicsWindow.BrushColor = "Orange"
ElseIf down[r][c] = "G" Then
GraphicsWindow.BrushColor = "Green"
ElseIf down[r][c] = "Y" Then
GraphicsWindow.BrushColor = "Yellow"
ElseIf down[r][c] = "W" Then
GraphicsWindow.BrushColor = "White"
EndIf
GraphicsWindow.FillRectangle(c*50 + downx,r*50 + downy,40,40)
EndFor
EndFor
GraphicsWindow.BrushColor = "Orange"
leftx = 400
lefty = 250
GraphicsWindow.DrawText(leftx+80,lefty,"LEFT")
For r = 1 To 3
For c = 1 To 3
If left[r][c] = "R" Then
GraphicsWindow.BrushColor = "Red"
ElseIf left[r][c] = "B" Then
GraphicsWindow.BrushColor = "Blue"
ElseIf left[r][c] = "O" Then
GraphicsWindow.BrushColor = "Orange"
ElseIf left[r][c] = "G" Then
GraphicsWindow.BrushColor = "Green"
ElseIf left[r][c] = "Y" Then
GraphicsWindow.BrushColor = "Yellow"
ElseIf left[r][c] = "W" Then
GraphicsWindow.BrushColor = "White"
EndIf
GraphicsWindow.FillRectangle(c*50 + leftx,r*50 +lefty,40,40)
EndFor
EndFor
GraphicsWindow.BrushColor = "Red"
rightx = 800
righty = 250
GraphicsWindow.DrawText(rightx+80,righty,"RIGHT")
For r = 1 To 3
For c = 1 To 3
If right[r][c] = "R" Then
GraphicsWindow.BrushColor = "Red"
ElseIf right[r][c] = "B" Then
GraphicsWindow.BrushColor = "Blue"
ElseIf right[r][c] = "O" Then
GraphicsWindow.BrushColor = "Orange"
ElseIf right[r][c] = "G" Then
GraphicsWindow.BrushColor = "Green"
ElseIf right[r][c] = "Y" Then
GraphicsWindow.BrushColor = "Yellow"
ElseIf right[r][c] = "W" Then
GraphicsWindow.BrushColor = "White"
EndIf
GraphicsWindow.FillRectangle(c*50 + rightx,r*50 +righty,40,40)
EndFor
EndFor
GraphicsWindow.BrushColor = "Blue"
backx = 1000
backy = 250
GraphicsWindow.DrawText(backx+80,backy,"BACK")
For r = 1 To 3
For c = 1 To 3
If back[r][c] = "R" Then
GraphicsWindow.BrushColor = "Red"
ElseIf back[r][c] = "B" Then
GraphicsWindow.BrushColor = "Blue"
ElseIf back[r][c] = "O" Then
GraphicsWindow.BrushColor = "Orange"
ElseIf back[r][c] = "G" Then
GraphicsWindow.BrushColor = "Green"
ElseIf back[r][c] = "Y" Then
GraphicsWindow.BrushColor = "Yellow"
ElseIf back[r][c] = "W" Then
GraphicsWindow.BrushColor = "White"
EndIf
GraphicsWindow.FillRectangle(c*50 + backx,r*50 +backy,40,40)
EndFor
EndFor
EndSub
'next number of sub rountines are to move the faces. It not only moves motors to turn faces in real life but also updates all the needed arrays
Sub R
Motor.Schedule("2A",100,0,A2pos1,A2pos2,"True")
Motor.Wait("2A")
For r = 1 To 3
For c = 1 To 3
oldright[r][c] = right[r][c]
EndFor
EndFor
For r = 1 To 3
oldtop[r] = top[r][3]
oldface[r] = face[r][3]
olddown[r] = down[r][3]
oldback[r] = back [r][1]
EndFor
right[1][1] = oldright[3][1]
right[1][2] = oldright[2][1]
right[1][3] = oldright[1][1]
right[2][1] = oldright[3][2]
right[2][3] = oldright[1][2]
right[3][1] = oldright[3][3]
right[3][2] = oldright[2][3]
right[3][3] = oldright[1][3]
For r = 1 To 3
top[r][3] = oldface[r]
face[r][3] = olddown[r]
EndFor
down[1][3] = oldback[3]
down[2][3] = oldback[2]
down[3][3] = oldback[1]
back[1][1] = oldtop[3]
back[2][1] = oldtop[2]
back[3][1] = oldtop[1]
EndSub
Sub Ri
Motor.Schedule("2A",-100,0,A2neg1,A2neg2,"True")
Motor.Wait("2A")
For r = 1 To 3
For c = 1 To 3
oldright[r][c] = right[r][c]
EndFor
EndFor
For r = 1 To 3
oldtop[r] = top[r][3]
oldface[r] = face[r][3]
olddown[r] = down[r][3]
oldback[r] = back[r][1]
EndFor
right[1][1] = oldright[1][3]
right[1][2] = oldright[2][3]
right[1][3] = oldright[3][3]
right[2][1] = oldright[1][2]
right[2][3] = oldright[3][2]
right[3][1] = oldright[1][1]
right[3][2] = oldright[2][1]
right[3][3] = oldright[3][1]
For r = 1 To 3
face[r][3] = oldtop[r]
down[r][3] = oldface[r]
EndFor
top[1][3] = oldback[3]
top[2][3] = oldback[2]
top[3][3] = oldback[1]
back[1][1] = olddown[3]
back[2][1] = olddown[2]
back[3][1] = olddown[1]
EndSub
Sub F
Motor.Schedule("C",-100,0,Cneg1,Cneg2,"True")
Motor.Wait("C")
For r = 1 To 3
For c = 1 To 3
oldface[r][c] = face[r][c]
EndFor
EndFor
For r = 1 To 3
oldtop[r] = top[3][r]
oldleft[r] = left[r][3]
olddown[r] = down[1][r]
oldright[r] = right[r][1]
EndFor
face[1][1] = oldface[3][1]
face[1][2] = oldface[2][1]
face[1][3] = oldface[1][1]
face[2][1] = oldface[3][2]
face[2][3] = oldface[1][2]
face[3][1] = oldface[3][3]
face[3][2] = oldface[2][3]
face[3][3] = oldface[1][3]
For r = 1 To 3
left[r][3] = olddown[r]
right[r][1] = oldtop[r]
EndFor
top[3][1] = oldleft[3]
top[3][2] = oldleft[2]
top[3][3] = oldleft[1]
down[1][1] = oldright[3]
down[1][2] = oldright[2]
down[1][3] = oldright[1]
EndSub
Sub Fi
Motor.Schedule("C",100,0,Cpos1,Cpos2,"True")
Motor.Wait("C")
For r = 1 To 3
For c = 1 To 3
oldface[r][c] = face[r][c]
EndFor
EndFor
For r = 1 To 3
oldtop[r] = top[3][r]
oldleft[r] = left[r][3]
olddown[r] = down[1][r]
oldright[r] = right[r][1]
EndFor
face[1][1] = oldface[1][3]
face[1][2] = oldface[2][3]
face[1][3] = oldface[3][3]
face[2][1] = oldface[1][2]
face[2][3] = oldface[3][2]
face[3][1] = oldface[1][1]
face[3][2] = oldface[2][1]
face[3][3] = oldface[3][1]
For r = 1 to 3
top[3][r] = oldright[r]
down[1][r] = oldleft[r]
EndFor
left[1][3] = oldtop[3]
left[2][3] = oldtop[2]
left[3][3] = oldtop[1]
right[1][1] = olddown[3]
right[2][1] = olddown[2]
right[3][1] = olddown[1]
EndSub
Sub L
Motor.Schedule("D",-100,0,Dneg1,Dneg2,"True")
Motor.Wait("D")
For r = 1 To 3
For c = 1 To 3
oldleft[r][c] = left[r][c]
EndFor
EndFor
For r = 1 To 3
oldtop[r] = top[r][1]
oldback[r] = back[r][3]
olddown[r] = down[r][1]
oldface[r] = face[r][1]
EndFor
left[1][1] = oldleft[3][1]
left[1][2] = oldleft[2][1]
left[1][3] = oldleft[1][1]
left[2][1] = oldleft[3][2]
left[2][3] = oldleft[1][2]
left[3][1] = oldleft[3][3]
left[3][2] = oldleft[2][3]
left[3][3] = oldleft[1][3]
For r = 1 To 3
face[r][1] = oldtop[r]
down[r][1] = oldface[r]
EndFor
top[1][1] = oldback[3]
top[2][1] = oldback[2]
top[3][1] = oldback[1]
back[1][3] = olddown[3]
back[2][3] = olddown[2]
back[3][3] = olddown[1]
EndSub
Sub Li
Motor.Schedule("D",100,0,Dpos1,Dpos2,"True")
Motor.Wait("D")
For r = 1 To 3
For c = 1 To 3
oldleft[r][c] = left[r][c]
EndFor
EndFor
For r = 1 To 3
oldtop[r] = top[r][1]
oldback[r] = back[r][3]
olddown[r] = down[r][1]
oldface[r] = face[r][1]
EndFor
left[1][1] = oldleft[1][3]
left[1][2] = oldleft[2][3]
left[1][3] = oldleft[3][3]
left[2][1] = oldleft[1][2]
left[2][3] = oldleft[3][2]
left[3][1] = oldleft[1][1]
left[3][2] = oldleft[2][1]
left[3][3] = oldleft[3][1]
For r = 1 To 3
top[r][1] = oldface[r]
face[r][1] = olddown[r]
EndFor
back[1][3] = oldtop[3]
back[2][3] = oldtop[2]
back[3][3] = oldtop[1]
down[1][1] = oldback[3]
down[2][1] = oldback[2]
down[3][1] = oldback[1]
EndSub
Sub T
Motor.Schedule("A",-100,0,Aneg1,Aneg2,"True")
Motor.Wait("A")
For r = 1 To 3
For c = 1 To 3
oldtop[r][c] = top[r][c]
EndFor
EndFor
For r = 1 To 3
oldleft[r] = left[1][r]
oldback[r] = back[1][r]
oldright[r] = right[1][r]
oldface[r] = face[1][r]
EndFor
top[1][1] = oldtop[3][1]
top[1][2] = oldtop[2][1]
top[1][3] = oldtop[1][1]
top[2][1] = oldtop[3][2]
top[2][3] = oldtop[1][2]
top[3][1] = oldtop[3][3]
top[3][2] = oldtop[2][3]
top[3][3] = oldtop[1][3]
For r = 1 To 3
left[1][r] = oldface[r]
face[1][r] = oldright[r]
back[1][r] = oldleft[r]
right[1][r] = oldback[r]
EndFor
EndSub
Sub Ti
Motor.Schedule("A",100,0,Apos1,Apos2,"True")
Motor.Wait("A")
For r = 1 To 3
For c = 1 To 3
oldtop[r][c] = top[r][c]
EndFor
EndFor
For r = 1 To 3
oldleft[r] = left[1][r]
oldback[r] = back[1][r]
oldright[r] = right[1][r]
oldface[r] = face[1][r]
EndFor
top[1][1] = oldtop[1][3]
top[1][2] = oldtop[2][3]
top[1][3] = oldtop[3][3]
top[2][1] = oldtop[1][2]
top[2][3] = oldtop[3][2]
top[3][1] = oldtop[1][1]
top[3][2] = oldtop[2][1]
top[3][3] = oldtop[3][1]
For r = 1 To 3
face[1][r] = oldleft[r]
left[1][r] = oldback[r]
right[1][r] = oldface[r]
back[1][r] = oldright[r]
EndFor
EndSub
Sub D
Motor.Schedule("B",100,0,Bpos1,Bpos2,"True")
Motor.Wait("B")
For r = 1 To 3
For c = 1 To 3
olddown[r][c] = down[r][c]
EndFor
EndFor
For r = 1 To 3
oldleft[r] = left[3][r]
oldback[r] = back[3][r]
oldright[r] = right[3][r]
oldface[r] = face[3][r]
EndFor
down[1][1] = olddown[3][1]
down[1][2] = olddown[2][1]
down[1][3] = olddown[1][1]
down[2][1] = olddown[3][2]
down[2][3] = olddown[1][2]
down[3][1] = olddown[3][3]
down[3][2] = olddown[2][3]
down[3][3] = olddown[1][3]
For r = 1 to 3
face[3][r] = oldleft[r]
right[3][r] = oldface[r]
left[3][r] = oldback[r]
back[3][r] = oldright[r]
EndFor
EndSub
Sub Di
Motor.Schedule("B",-100,0,Bneg1,Bneg2,"True")
Motor.Wait("B")
For r = 1 To 3
For c = 1 To 3
olddown[r][c] = down[r][c]
EndFor
EndFor
For r = 1 To 3
oldleft[r] = left[3][r]
oldback[r] = back[3][r]
oldright[r] = right[3][r]
oldface[r] = face[3][r]
EndFor
down[1][1] = olddown[1][3]
down[1][2] = olddown[2][3]
down[1][3] = olddown[3][3]
down[2][1] = olddown[1][2]
down[2][3] = olddown[3][2]
down[3][1] = olddown[1][1]
down[3][2] = olddown[2][1]
down[3][3] = olddown[3][1]
For r = 1 to 3
face[3][r] = oldright[r]
right[3][r] = oldback[r]
left[3][r] = oldface[r]
back[3][r] = oldleft[r]
EndFor
EndSub
Sub B
Motor.Schedule("2B",100,0,B2pos1,B2pos2,"True")
Motor.Wait("2B")
For r = 1 To 3
For c = 1 To 3
oldback[r][c] = back[r][c]
EndFor
EndFor
For r = 1 To 3
oldleft[r] = left[r][1]
oldtop[r] = top[1][r]
oldright[r] = right[r][3]
olddown[r] = down[3][r]
EndFor
back[1][1] = oldback[3][1]
back[1][2] = oldback[2][1]
back[1][3] = oldback[1][1]
back[2][1] = oldback[3][2]
back[2][3] = oldback[1][2]
back[3][1] = oldback[3][3]
back[3][2] = oldback[2][3]
back[3][3] = oldback[1][3]
For r = 1 To 3
top[1][r] = oldright[r]
down[3][r] = oldleft[r]
EndFor
left[1][1] = oldtop[3]
left[2][1] = oldtop[2]
left[3][1] = oldtop[1]
right[1][3] = olddown[3]
right[2][3] = olddown[2]
right[3][3] = olddown[1]
EndSub
Sub Bi
Motor.Schedule("2B",-100,0,B2neg1,B2neg2,"True")
Motor.Wait("2B")
For r = 1 To 3
For c = 1 To 3
oldback[r][c] = back[r][c]
EndFor
EndFor
For r = 1 To 3
oldleft[r] = left[r][1]
oldtop[r] = top[1][r]
oldright[r] = right[r][3]
olddown[r] = down[3][r]
EndFor
back[1][1] = oldback[1][3]
back[1][2] = oldback[2][3]
back[1][3] = oldback[3][3]
back[2][1] = oldback[1][2]
back[2][3] = oldback[3][2]
back[3][1] = oldback[1][1]
back[3][2] = oldback[2][1]
back[3][3] = oldback[3][1]
For r = 1 To 3
right[r][3] = oldtop[r]
left[r][1] = olddown[r]
EndFor
top[1][1] = oldleft[3]
top[1][2] = oldleft[2]
top[1][3] = oldleft[1]
down[3][1] = oldright[3]
down[3][2] = oldright[2]
down[3][3] = oldright[1]
EndSub
Owner

flyboy74 commented Feb 15, 2017

This is where we got the 6 steps we use from
https://www.rubiks.com/blog/how-to-solve-the-rubiks-cube

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment