Skip to content

Instantly share code, notes, and snippets.

@LizardLeliel
Last active August 29, 2015 14:01
Show Gist options
  • Save LizardLeliel/0df14a6fce5ca766324f to your computer and use it in GitHub Desktop.
Save LizardLeliel/0df14a6fce5ca766324f to your computer and use it in GitHub Desktop.
A few sub procedures in Visual Basic using Visual Studio meant to solve a Rubix cube (where the Rubix cube is an instance of a cube class from the rubix cube module from another gist here. Cube is named "dub" in this program, for that was the easist to type)
'This sub procedure (which is linked to a wpf button in Visual Studio) solves a rubix cube by using
'Algorithms that prodecurally solve it.
'I put a lot of hours in it; taking most of my week evenings to code it, and taking time during class to write down pseudocode.
'However, I still manage to complete the entire code in just a week. However, despite it working as supsected (once
'I've got the final revision on it, I have not had it lock up once on proper cubes), there's still many things
'about the code that could be improved. I feel most of it's unfineness was a result in a pressure to finish it. However, some
'of the problems include:
'-The entire thing is nested in one big while statement. Although I originally had intentions for having it in
'that way, I eventually found it unnessecary, although I was afraid to remove it due to the distance of the opening
'and closing keywords
'-Since none of the peices of the cube are unaware of their orientation in relation to the whole cube, there
'are repitions of a similar pattern, with minor changes.
'-I also had to type "me.update" after every rotation in order for the text box in our final application to display
'the text of what rotation it did. I wish I could have it so each rotation method on the cube updated it as so,
'but I couldn't figure out how to do it so.
'-And I didn't start properly code commenting it until what I felt was a quarter way through
'That being said, this works extremly well, especially given this was all written and debugged in a week. I have
'Not come across it breaking ever since I got it to start properly solving, and it solves them in about ~150 turns. Takes
'one second to calculate it. And it is all coded by me, using my own experience of knowledge of solving cubes
'That I have attained from various sources over the years.
'All code comments below have very little edits to them from the original code.
Private Sub cmdSolve_Click(sender As Object, e As RoutedEventArgs) Handles cmdSolve.Click
'Declare Local Variables
Dim intCountCheck As Integer
Dim boolEscape As Boolean = False
Dim boolSolved As Boolean = False
Me.scrRotations.Text &= ">COMPUTER SOLUTION BEGINS<" & vbCrLf
'Do until solved - or debug bool has passed
Me.scrRotations.Text &= ">SOLVING FOR RED CROSS<" & vbCrLf
Do Until boolEscape = True Or boolSolved = True
'SOLVE CROSS
Do Until dub.Red.sideGrid(0, 1) = "R" And dub.Red.sideGrid(1, 0) = "R" And dub.Red.sideGrid(2, 1) = "R" And dub.Red.sideGrid(1, 2) = "R" _
And dub.Yellow.sideGrid(2, 1) = "Y" And dub.Blue.sideGrid(1, 2) = "B" And dub.White.sideGrid(0, 1) = "W" And dub.Green.sideGrid(1, 0) = "G"
'If there's any reds on the top face that are unmatching, set them to the bottom
If (dub.Red.sideGrid(0, 1) = "R" And Not dub.Yellow.sideGrid(2, 1) = "Y") Or _
(dub.Red.sideGrid(1, 0) = "R" And Not dub.Blue.sideGrid(1, 2) = "B") Or _
(dub.Red.sideGrid(2, 1) = "R" And Not dub.White.sideGrid(0, 1) = "W") Or _
(dub.Red.sideGrid(1, 2) = "R" And Not dub.Green.sideGrid(1, 0) = "G") Then
'Decide which ones are incorrect (NO CONTINUE DO)
If (dub.Red.sideGrid(0, 1) = "R" And Not dub.Yellow.sideGrid(2, 1) = "Y") Then
dub.YellowClockwise()
Me.Update()
dub.YellowClockwise()
Me.Update()
ElseIf (dub.Red.sideGrid(2, 0) = "R" And Not dub.Blue.sideGrid(1, 2) = "B") Then
dub.BlueClockwise()
Me.Update()
dub.BlueClockwise()
Me.Update()
ElseIf (dub.Red.sideGrid(2, 1) = "R" And Not dub.White.sideGrid(0, 1) = "W") Then
dub.WhiteClockwise()
Me.Update()
dub.WhiteClockwise()
Me.Update()
ElseIf (dub.Red.sideGrid(1, 2) = "R" And Not dub.Green.sideGrid(1, 0) = "G") Then
dub.GreenClockwise()
Me.Update()
dub.GreenClockwise()
Me.Update()
'Continue Do
End If
End If
'If any are on the bottom, solve for those
Do While dub.Orange.sideGrid(0, 1) = "R" Or dub.Orange.sideGrid(1, 0) = "R" Or _
dub.Orange.sideGrid(2, 1) = "R" Or dub.Orange.sideGrid(1, 2) = "R"
'Rotate if things line up
If dub.Orange.sideGrid(0, 1) = "R" And dub.Yellow.sideGrid(0, 1) = "Y" Then
dub.YellowClockwise()
Me.Update()
dub.YellowClockwise()
Me.Update()
ElseIf dub.Orange.sideGrid(1, 0) = "R" And dub.Green.sideGrid(1, 2) = "G" Then
dub.GreenClockwise()
Me.Update()
dub.GreenClockwise()
Me.Update()
ElseIf dub.Orange.sideGrid(2, 1) = "R" And dub.White.sideGrid(2, 1) = "W" Then
dub.WhiteClockwise()
Me.Update()
dub.WhiteClockwise()
Me.Update()
ElseIf dub.Orange.sideGrid(1, 2) = "R" And dub.Blue.sideGrid(1, 0) = "B" Then
dub.BlueClockwise()
Me.Update()
dub.BlueClockwise()
Me.Update()
'Pu
End If
'Rotate orange, and go through again
dub.OrangeClockwise()
Me.Update()
'Loop for solve bottom
Loop
'Solve to fix mid-layed reds
'I should remove below, but I don't wanna change the pseudo code and mess things up from what I'm certain about ):
If (dub.Yellow.sideGrid(1, 0) = "R" Or dub.Blue.sideGrid(0, 1) = "R") Or _
(dub.Blue.sideGrid(2, 1) = "R" Or dub.White.sideGrid(1, 0) = "R") Or _
(dub.White.sideGrid(1, 2) = "R" Or dub.Green.sideGrid(2, 1) = "R") Or _
(dub.Green.sideGrid(0, 1) = "R" Or dub.Yellow.sideGrid(1, 2) = "R") Then
'DOWN BELOW, DO INDIVIDUAL COMBINATIONS
'Between Yellow and blue, facing yellow
'Look her!
If dub.Yellow.sideGrid(1, 0) = "R" Then
dub.BlueCounterClockwise()
Me.Update()
dub.OrangeClockwise()
Me.Update()
dub.BlueClockwise()
Me.Update()
'V Between yellow and blue, facing blue
ElseIf dub.Blue.sideGrid(0, 1) = "R" Then
dub.YellowClockwise()
Me.Update()
dub.OrangeClockwise()
Me.Update()
dub.YellowCounterClockwise()
Me.Update()
'V Between blue and yellow facing blue
ElseIf dub.Blue.sideGrid(2, 1) = "R" Then
dub.WhiteCounterClockwise()
Me.Update()
dub.OrangeCounterClockwise()
Me.Update()
dub.WhiteClockwise()
Me.Update()
'V Between blue and white facing white
ElseIf dub.White.sideGrid(1, 0) = "R" Then
dub.BlueClockwise()
Me.Update()
dub.OrangeClockwise()
Me.Update()
dub.BlueCounterClockwise()
Me.Update()
'V Between White and green facing white
ElseIf dub.White.sideGrid(1, 2) = "R" Then
dub.GreenCounterClockwise()
Me.Update()
dub.OrangeCounterClockwise()
Me.Update()
dub.GreenClockwise()
Me.Update()
'V Between white and green facing green
ElseIf dub.Green.sideGrid(2, 1) = "R" Then
dub.WhiteClockwise()
Me.Update()
dub.OrangeClockwise()
Me.Update()
dub.WhiteCounterClockwise()
'V Between yellow and green facing Green
ElseIf dub.Green.sideGrid(0, 1) = "R" Then
dub.YellowCounterClockwise()
Me.Update()
dub.OrangeCounterClockwise()
Me.Update()
dub.YellowClockwise()
Me.Update()
'V Between yellow and green facing yellow
ElseIf dub.Yellow.sideGrid(1, 2) = "R" Then
dub.GreenClockwise()
Me.Update()
dub.OrangeClockwise()
Me.Update()
dub.GreenCounterClockwise()
Me.Update()
'End for decisions on individual mid-layer reds
End If
Continue Do
'V Ends mega-if for mid-layerv(Even though above thingy exits it)
End If
'If there's a red in the top layer
If dub.Yellow.sideGrid(2, 1) = "R" Or _
dub.Blue.sideGrid(1, 2) = "R" Or _
dub.White.sideGrid(0, 1) = "R" Or _
dub.Green.sideGrid(1, 0) = "R" Then
'Rotate indiviual top layer reds
'For Yellow
If dub.Yellow.sideGrid(2, 1) = "R" Then
dub.YellowClockwise()
Me.Update()
dub.YellowClockwise()
Me.Update()
'For Blue
ElseIf dub.Blue.sideGrid(1, 2) = "R" Then
dub.BlueClockwise()
Me.Update()
dub.BlueClockwise()
Me.Update()
'For White
ElseIf dub.White.sideGrid(0, 1) = "R" Then
dub.WhiteClockwise()
Me.Update()
dub.WhiteClockwise()
Me.Update()
'For Green
ElseIf dub.Green.sideGrid(1, 0) = "R" Then
dub.GreenClockwise()
Me.Update()
dub.GreenClockwise()
Me.Update()
'End if Red is on top
End If
'End from "oh no, red on top layer"
End If
'--------------------------------------------
'Solve for reds on the bottom layer
Do While (dub.Yellow.sideGrid(0, 1) = "R") Or _
(dub.Blue.sideGrid(1, 0) = "R") Or _
(dub.White.sideGrid(2, 1) = "R") Or _
(dub.Green.sideGrid(1, 2) = "R")
'If Red and yellow allign
If dub.Yellow.sideGrid(0, 1) = "R" And dub.Orange.sideGrid(0, 1) = "Y" Then
dub.OrangeClockwise()
Me.Update()
dub.BlueClockwise()
Me.Update()
dub.YellowCounterClockwise()
Me.Update()
dub.BlueCounterClockwise()
Me.Update()
dub.OrangeCounterClockwise()
Me.Update()
End If
'If red and green allign
If dub.Green.sideGrid(1, 2) = "R" And dub.Orange.sideGrid(1, 0) = "G" Then
dub.OrangeClockwise()
Me.Update()
dub.BlueClockwise()
Me.Update()
dub.GreenCounterClockwise()
Me.Update()
dub.YellowCounterClockwise()
Me.Update()
dub.OrangeCounterClockwise()
Me.Update()
End If
'if red and white allign
If dub.White.sideGrid(2, 1) = "R" And dub.Orange.sideGrid(2, 1) = "W" Then
dub.OrangeClockwise()
Me.Update()
dub.GreenClockwise()
Me.Update()
dub.WhiteCounterClockwise()
Me.Update()
dub.GreenCounterClockwise()
Me.Update()
dub.OrangeCounterClockwise()
Me.Update()
End If
'If red and Blue allign
If dub.Blue.sideGrid(1, 0) = "R" And dub.Orange.sideGrid(1, 2) = "B" Then
dub.OrangeClockwise()
Me.Update()
dub.GreenClockwise()
Me.Update()
dub.WhiteCounterClockwise()
Me.Update()
dub.GreenCounterClockwise()
Me.Update()
dub.OrangeCounterClockwise()
Me.Update()
End If
dub.OrangeClockwise()
Loop
Loop
'==================================================================
'==================================================================
Me.scrRotations.Text &= ">SOLVING FOR RED CORNERS<" & vbCrLf
'SOLVE FOR CORNERS
Do Until dub.Red.sideGrid(0, 0) = "R" And dub.Red.sideGrid(0, 2) = "R" And _
dub.Red.sideGrid(2, 0) = "R" And dub.Red.sideGrid(2, 2) = "R" And _
dub.Yellow.sideGrid(2, 0) = "Y" And dub.Yellow.sideGrid(2, 2) = "Y" And _
dub.Blue.sideGrid(0, 2) = "B" And dub.Blue.sideGrid(2, 2) = "B" And _
dub.White.sideGrid(0, 0) = "W" And dub.White.sideGrid(0, 2) = "W" And _
dub.Green.sideGrid(0, 0) = "G" And dub.Green.sideGrid(2, 0) = "G"
'Do while there's reds on the orange row
Do While dub.Yellow.sideGrid(0, 2) = "R" Or dub.Yellow.sideGrid(0, 0) = "R" Or _
dub.Blue.sideGrid(0, 0) = "R" Or dub.Blue.sideGrid(2, 0) = "R" Or _
dub.White.sideGrid(2, 0) = "R" Or dub.White.sideGrid(2, 2) = "R" Or _
dub.Green.sideGrid(0, 2) = "R" Or dub.Green.sideGrid(2, 2) = "R"
'Between blue and yellow facing yellow
If dub.Yellow.sideGrid(0, 0) = "R" And dub.Blue.sideGrid(0, 0) = "B" Then
dub.OrangeCounterClockwise()
Me.Update()
dub.BlueCounterClockwise()
Me.Update()
dub.OrangeClockwise()
Me.Update()
dub.BlueClockwise()
Me.Update()
End If
'Between blue and white facing blue
If dub.Blue.sideGrid(2, 0) = "R" And dub.White.sideGrid(2, 0) = "W" Then
dub.OrangeCounterClockwise()
Me.Update()
dub.WhiteCounterClockwise()
Me.Update()
dub.OrangeClockwise()
Me.Update()
dub.WhiteClockwise()
Me.Update()
End If
'Between White and green facing white
If dub.White.sideGrid(2, 2) = "R" And dub.Green.sideGrid(2, 2) = "G" Then
dub.OrangeCounterClockwise()
Me.Update()
dub.GreenCounterClockwise()
Me.Update()
dub.OrangeClockwise()
Me.Update()
dub.GreenClockwise()
Me.Update()
End If
'BEtween yellow and green facing green
If dub.Yellow.sideGrid(0, 2) = "Y" And dub.Green.sideGrid(0, 2) = "R" Then
dub.OrangeCounterClockwise()
Me.Update()
dub.YellowCounterClockwise()
Me.Update()
dub.OrangeClockwise()
Me.Update()
dub.YellowClockwise()
Me.Update()
End If
'BEtween yellow and blue facing blue
If dub.Yellow.sideGrid(0, 0) = "Y" And dub.Blue.sideGrid(0, 0) = "R" Then
dub.OrangeClockwise()
Me.Update()
dub.YellowClockwise()
Me.Update()
dub.OrangeCounterClockwise()
Me.Update()
dub.YellowCounterClockwise()
Me.Update()
End If
'Between Blue and white facing white
If dub.Blue.sideGrid(2, 0) = "B" And dub.White.sideGrid(2, 0) = "R" Then
dub.OrangeClockwise()
Me.Update()
dub.BlueClockwise()
Me.Update()
dub.OrangeCounterClockwise()
Me.Update()
dub.BlueCounterClockwise()
Me.Update()
End If
'Between White and green facing Green
If dub.Green.sideGrid(2, 2) = "R" And dub.White.sideGrid(2, 2) = "W" Then
dub.OrangeClockwise()
Me.Update()
dub.WhiteClockwise()
Me.Update()
dub.OrangeCounterClockwise()
Me.Update()
dub.WhiteCounterClockwise()
Me.Update()
End If
'Between green and yellow facing yellow
If dub.Yellow.sideGrid(0, 2) = "R" And dub.Green.sideGrid(0, 2) = "G" Then
dub.OrangeClockwise()
Me.Update()
dub.GreenClockwise()
Me.Update()
dub.OrangeCounterClockwise()
Me.Update()
dub.GreenCounterClockwise()
Me.Update()
End If
dub.OrangeClockwise()
Me.Update()
Loop
'End solve misaligned red side red corners
'--------------------------------------------------------------------
'solve misaligned red side red corners
'between blue and white
If dub.Red.sideGrid(2, 0) = "R" And Not dub.Blue.sideGrid(2, 2) = "B" And Not dub.White.sideGrid(0, 0) = "W" Then
dub.BlueClockwise()
Me.Update()
dub.OrangeClockwise()
Me.Update()
dub.BlueCounterClockwise()
Me.Update()
Continue Do
End If
'If between White and Green
If dub.Red.sideGrid(2, 2) = "R" And Not dub.White.sideGrid(0, 2) = "W" And Not dub.Green.sideGrid(2, 0) = "G" Then
dub.WhiteClockwise()
Me.Update()
dub.OrangeClockwise()
Me.Update()
dub.WhiteCounterClockwise()
Me.Update()
Continue Do
End If
'If between Green and yellow
If dub.Red.sideGrid(0, 2) = "R" And Not dub.Yellow.sideGrid(2, 2) = "Y" And Not dub.Green.sideGrid(0, 0) = "G" Then
dub.GreenClockwise()
Me.Update()
dub.OrangeClockwise()
Me.Update()
dub.GreenCounterClockwise()
Me.Update()
Continue Do
End If
'If between Blue and yellow
If dub.Red.sideGrid(0, 0) = "R" And Not dub.Yellow.sideGrid(2, 0) = "Y" And Not dub.Blue.sideGrid(0, 2) = "B" Then
dub.YellowClockwise()
Me.Update()
dub.OrangeClockwise()
Me.Update()
dub.YellowCounterClockwise()
Me.Update()
Continue Do
End If
'--------------------------------------------------
'Next step: Fixing reds wedged into the top row
'1) Between Green and yellow facing yellow
If dub.Yellow.sideGrid(2, 2) = "R" Then
dub.YellowCounterClockwise()
Me.Update()
dub.OrangeCounterClockwise()
Me.Update()
dub.YellowClockwise()
Me.Update()
Continue Do
End If
'2) Between Yellow and Blue facing yellow
If Me.dub.Yellow.sideGrid(2, 0) = "R" Then
dub.YellowClockwise()
Me.Update()
dub.OrangeClockwise()
Me.Update()
dub.YellowCounterClockwise()
Me.Update()
Continue Do
End If
'3) Between yellow and green facing green
If dub.Green.sideGrid(0, 0) = "R" Then
dub.GreenClockwise()
Me.Update()
dub.OrangeClockwise()
Me.Update()
dub.GreenCounterClockwise()
Me.Update()
Continue Do
End If
'4) Between Yellow and blue facing Blue
If dub.Blue.sideGrid(0, 2) = "R" Then
dub.BlueCounterClockwise()
Me.Update()
dub.OrangeCounterClockwise()
Me.Update()
dub.BlueClockwise()
Continue Do
End If
'5) between blue and white facing white
If dub.White.sideGrid(0, 0) = "R" Then
dub.WhiteCounterClockwise()
Me.Update()
dub.OrangeCounterClockwise()
Me.Update()
dub.WhiteClockwise()
Me.Update()
Continue Do
End If
'6) between blue and white facing blue
If dub.Blue.sideGrid(2, 2) = "R" Then
dub.BlueClockwise()
Me.Update()
dub.OrangeClockwise()
Me.Update()
dub.BlueCounterClockwise()
Me.Update()
Continue Do
End If
'7) between white and green facing white
If dub.White.sideGrid(0, 2) = "R" Then
dub.WhiteClockwise()
Me.Update()
dub.OrangeClockwise()
Me.Update()
dub.WhiteCounterClockwise()
Me.Update()
Continue Do
End If
'8) Between white and green facing green
If dub.Green.sideGrid(2, 0) = "R" Then
dub.GreenCounterClockwise()
Me.Update()
dub.OrangeCounterClockwise()
Me.Update()
dub.GreenClockwise()
Me.Update()
Continue Do
End If
'--------------------------------------------------------
'Get rid of all the bottom corner reds
'1) Between green and white
If dub.Orange.sideGrid(2, 0) = "R" Then
dub.GreenCounterClockwise()
Me.Update()
dub.OrangeClockwise()
Me.Update()
dub.GreenClockwise()
Me.Update()
Continue Do
End If
'2) Between yellow and green
If dub.Orange.sideGrid(0, 0) = "R" Then
dub.YellowCounterClockwise()
Me.Update()
dub.OrangeClockwise()
Me.Update()
dub.YellowClockwise()
Me.Update()
Continue Do
End If
'3) between yellow and blue
If dub.Orange.sideGrid(0, 2) = "R" Then
dub.BlueCounterClockwise()
Me.Update()
dub.OrangeClockwise()
Me.Update()
dub.BlueClockwise()
Me.Update()
Continue Do
End If
'4) Between blue and white
If dub.Orange.sideGrid(2, 2) = "R" Then
dub.WhiteCounterClockwise()
Me.Update()
dub.OrangeClockwise()
Me.Update()
dub.WhiteClockwise()
Me.Update()
End If
Loop
'Done corners
'=============================================================================
'============================================================================
Me.scrRotations.Text &= ">SOLVING FOR MID-LAYER SIDES<" & vbCrLf
Do Until (dub.Yellow.sideGrid(1, 0) = "Y" And dub.Blue.sideGrid(0, 1) = "B") And _
(dub.Blue.sideGrid(2, 1) = "B" And dub.White.sideGrid(1, 0) = "W") And _
(dub.White.sideGrid(1, 2) = "W" And dub.Green.sideGrid(2, 1) = "G") And _
(dub.Green.sideGrid(0, 1) = "G" And dub.Yellow.sideGrid(1, 2) = "Y")
'Loop until atleast one orange on the top
Do Until (dub.Yellow.sideGrid(0, 1) = "O" Or dub.Orange.sideGrid(0, 1) = "O") And _
(dub.Green.sideGrid(1, 2) = "O" Or dub.Orange.sideGrid(1, 0) = "O") And _
(dub.White.sideGrid(2, 1) = "O" Or dub.Orange.sideGrid(2, 1) = "O") And _
(dub.Blue.sideGrid(1, 0) = "O" Or dub.Orange.sideGrid(1, 2) = "O")
'1) Yellow alligns; green ontop
If dub.Yellow.sideGrid(0, 1) = "Y" And dub.Orange.sideGrid(0, 1) = "G" Then
dub.OrangeClockwise()
Me.Update()
dub.GreenClockwise()
Me.Update()
dub.OrangeCounterClockwise()
Me.Update()
dub.GreenCounterClockwise()
Me.Update()
dub.OrangeCounterClockwise()
Me.Update()
dub.YellowCounterClockwise()
Me.Update()
dub.OrangeClockwise()
Me.Update()
dub.YellowClockwise()
Me.Update()
End If
'2) Yellow alligns and blue ontop
If dub.Yellow.sideGrid(0, 1) = "Y" And dub.Orange.sideGrid(0, 1) = "B" Then
dub.OrangeCounterClockwise()
Me.Update()
dub.BlueCounterClockwise()
Me.Update()
dub.OrangeClockwise()
Me.Update()
dub.BlueClockwise()
Me.Update()
dub.OrangeClockwise()
Me.Update()
dub.YellowClockwise()
Me.Update()
dub.OrangeCounterClockwise()
Me.Update()
dub.YellowCounterClockwise()
Me.Update()
End If
'3) Blue alligns and yellow on top
If dub.Blue.sideGrid(1, 0) = "B" And dub.Orange.sideGrid(1, 2) = "Y" Then
dub.OrangeClockwise()
Me.Update()
dub.YellowClockwise()
Me.Update()
dub.OrangeCounterClockwise()
Me.Update()
dub.YellowCounterClockwise()
Me.Update()
dub.OrangeCounterClockwise()
Me.Update()
dub.BlueCounterClockwise()
Me.Update()
dub.OrangeClockwise()
Me.Update()
dub.BlueClockwise()
Me.Update()
End If
'4) If blue alligns and white is on top
If dub.Blue.sideGrid(1, 0) = "B" And dub.Orange.sideGrid(1, 2) = "W" Then
dub.OrangeCounterClockwise()
Me.Update()
dub.WhiteCounterClockwise()
Me.Update()
dub.OrangeClockwise()
Me.Update()
dub.WhiteClockwise()
Me.Update()
dub.OrangeClockwise()
Me.Update()
dub.BlueClockwise()
Me.Update()
dub.OrangeCounterClockwise()
Me.Update()
dub.BlueCounterClockwise()
Me.Update()
End If
'5) If white alligns and blue is on top
If dub.White.sideGrid(2, 1) = "W" And dub.Orange.sideGrid(2, 1) = "B" Then
dub.OrangeClockwise()
Me.Update()
dub.BlueClockwise()
Me.Update()
dub.OrangeCounterClockwise()
Me.Update()
dub.BlueCounterClockwise()
Me.Update()
dub.OrangeCounterClockwise()
Me.Update()
dub.WhiteCounterClockwise()
Me.Update()
dub.OrangeClockwise()
Me.Update()
dub.WhiteClockwise()
Me.Update()
End If
'6) If white alligns and the top is green
If dub.White.sideGrid(2, 1) = "W" And dub.Orange.sideGrid(2, 1) = "G" Then
dub.OrangeCounterClockwise()
Me.Update()
dub.GreenCounterClockwise()
Me.Update()
dub.OrangeClockwise()
Me.Update()
dub.GreenClockwise()
Me.Update()
dub.OrangeClockwise()
Me.Update()
dub.WhiteClockwise()
Me.Update()
dub.OrangeCounterClockwise()
Me.Update()
dub.WhiteCounterClockwise()
Me.Update()
End If
'7) If Green alligns and white is on top
If dub.Green.sideGrid(1, 2) = "G" And dub.Orange.sideGrid(1, 0) = "W" Then
dub.OrangeClockwise()
Me.Update()
dub.WhiteClockwise()
Me.Update()
dub.OrangeCounterClockwise()
Me.Update()
dub.WhiteCounterClockwise()
Me.Update()
dub.OrangeCounterClockwise()
Me.Update()
dub.GreenCounterClockwise()
Me.Update()
dub.OrangeClockwise()
Me.Update()
dub.GreenClockwise()
Me.Update()
End If
'8) If green align and yellow is on top
If dub.Green.sideGrid(1, 2) = "G" And dub.Orange.sideGrid(1, 0) = "Y" Then
dub.OrangeCounterClockwise()
Me.Update()
dub.YellowCounterClockwise()
Me.Update()
dub.OrangeClockwise()
Me.Update()
dub.YellowClockwise()
Me.Update()
dub.OrangeClockwise()
Me.Update()
dub.GreenClockwise()
Me.Update()
dub.OrangeCounterClockwise()
Me.Update()
dub.GreenCounterClockwise()
Me.Update()
End If
dub.OrangeClockwise()
Me.Update()
Loop
'-------------------------------------------------------------
'For non-oranges wedged incorrectly between side
'1) If wedged between green and yellow
If Not (dub.Yellow.sideGrid(1, 2) = "Y" And dub.Green.sideGrid(0, 1) = "G") And _
Not (dub.Yellow.sideGrid(1, 2) = "O" Or dub.Green.sideGrid(0, 1) = "O") Then
dub.OrangeClockwise()
Me.Update()
dub.GreenClockwise()
Me.Update()
dub.OrangeCounterClockwise()
Me.Update()
dub.GreenCounterClockwise()
Me.Update()
dub.OrangeCounterClockwise()
Me.Update()
dub.YellowCounterClockwise()
Me.Update()
dub.OrangeClockwise()
Me.Update()
dub.YellowClockwise()
Me.Update()
Continue Do
End If
'2) If wedged between blue and yellow
If Not (dub.Yellow.sideGrid(1, 0) = "Y" And dub.Blue.sideGrid(0, 1) = "B") And _
Not (dub.Yellow.sideGrid(1, 0) = "O" Or dub.Blue.sideGrid(0, 1) = "O") Then
dub.OrangeClockwise()
Me.Update()
dub.YellowClockwise()
Me.Update()
dub.OrangeCounterClockwise()
Me.Update()
dub.YellowCounterClockwise()
Me.Update()
dub.OrangeCounterClockwise()
Me.Update()
dub.BlueCounterClockwise()
Me.Update()
dub.OrangeClockwise()
Me.Update()
dub.BlueClockwise()
Me.Update()
Continue Do
End If
'3) If wedged between blue and white
If Not (dub.Blue.sideGrid(2, 1) = "B" And dub.White.sideGrid(1, 0) = "W") And _
Not (dub.Blue.sideGrid(2, 1) = "O" Or dub.White.sideGrid(1, 0) = "O") Then
dub.OrangeClockwise()
Me.Update()
dub.BlueClockwise()
Me.Update()
dub.OrangeCounterClockwise()
Me.Update()
dub.BlueCounterClockwise()
Me.Update()
dub.OrangeCounterClockwise()
Me.Update()
dub.WhiteCounterClockwise()
Me.Update()
dub.OrangeClockwise()
Me.Update()
dub.WhiteClockwise()
Me.Update()
Continue Do
End If
'4) If wedged between white and green
If Not (dub.White.sideGrid(1, 2) = "W" And dub.Green.sideGrid(2, 1) = "G") And _
Not (dub.White.sideGrid(1, 2) = "O" Or dub.Green.sideGrid(2, 1) = "O") Then
dub.OrangeClockwise()
Me.Update()
dub.WhiteClockwise()
Me.Update()
dub.OrangeCounterClockwise()
Me.Update()
dub.WhiteCounterClockwise()
Me.Update()
dub.OrangeCounterClockwise()
Me.Update()
dub.GreenCounterClockwise()
Me.Update()
dub.OrangeClockwise()
Me.Update()
dub.GreenClockwise()
Me.Update()
Continue Do
End If
Loop
'==========================================================
'==========================================================
'Solve for Orange t
'If there are no oranges on top
Me.scrRotations.Text &= ">SOLVING FOR ORANGE CROSS<" & vbCrLf
If Not dub.Orange.sideGrid(0, 1) = "O" And _
Not dub.Orange.sideGrid(1, 0) = "O" And _
Not dub.Orange.sideGrid(2, 1) = "O" And _
Not dub.Orange.sideGrid(1, 2) = "O" Then
Call OrangeSide()
End If
'---------------------------------------------------------
Do Until dub.Orange.sideGrid(0, 1) = "O" And _
dub.Orange.sideGrid(1, 0) = "O" And _
dub.Orange.sideGrid(2, 1) = "O" And _
dub.Orange.sideGrid(1, 2) = "O"
Do Until dub.Orange.sideGrid(1, 0) = "O" And Not dub.Orange.sideGrid(0, 1) = "O"
dub.OrangeClockwise()
Me.Update()
Loop
Call OrangeSide()
Loop
'=========================================================
'=========================================================
'Solving for orange face
'If no orange people
Do Until dub.Orange.sideGrid(0, 0) = "O" And _
dub.Orange.sideGrid(0, 2) = "O" And _
dub.Orange.sideGrid(2, 0) = "O" And _
dub.Orange.sideGrid(2, 2) = "O"
'If no orange people
Do While Not dub.Orange.sideGrid(0, 0) = "O" And _
Not dub.Orange.sideGrid(0, 2) = "O" And _
Not dub.Orange.sideGrid(2, 0) = "O" And _
Not dub.Orange.sideGrid(2, 2) = "O"
'Rotate until orange is in posistion
Do Until dub.Yellow.sideGrid(0, 2) = "O"
dub.OrangeClockwise()
Me.Update()
Loop
'If two on two face
If dub.Yellow.sideGrid(0, 0) = "O" And
dub.White.sideGrid(2, 0) = "O" And
dub.White.sideGrid(2, 2) = "O" And
dub.Yellow.sideGrid(0, 2) = "O" Then
dub.OrangeClockwise()
Me.Update()
Call OrangeCorner()
Else
Call OrangeCorner()
End If
Loop
'-------------------------
'A orange is on top
'Get orange in good posistion
Do Until dub.Orange.sideGrid(0, 0) = "O"
dub.OrangeClockwise()
Continue Do
Loop
'Solve if two oranges are on top
If dub.Orange.sideGrid(2, 0) = "O" Or _
dub.Orange.sideGrid(2, 2) = "O" Then
Call OrangeCorner()
Continue Do
'solve if one orange on top
Else
dub.OrangeClockwise()
Call OrangeCorner()
Continue Do
End If
Loop
'=====================================================
'=====================================================
Me.scrRotations.Text &= ">ALIGNING ORANGE CORNERS<" & vbCrLf
'If no two corners are alligned
If Not (dub.Yellow.sideGrid(0, 0) = dub.Yellow.sideGrid(0, 2) Or
dub.Green.sideGrid(0, 2) = dub.Green.sideGrid(2, 2) Or
dub.White.sideGrid(2, 0) = dub.White.sideGrid(2, 2) Or
dub.Blue.sideGrid(0, 0) = dub.Blue.sideGrid(2, 0)) Then
Call OrangeAllignCorners()
End If
'Until alligned corners are in the back
Do Until dub.White.sideGrid(2, 0) = dub.White.sideGrid(2, 2)
dub.OrangeClockwise()
Me.Update()
Loop
'Allign
If Not (dub.Yellow.sideGrid(0, 0) = dub.Yellow.sideGrid(0, 2) And
dub.Green.sideGrid(0, 2) = dub.Green.sideGrid(2, 2) And
dub.White.sideGrid(2, 0) = dub.White.sideGrid(2, 2) And
dub.Blue.sideGrid(0, 0) = dub.Blue.sideGrid(2, 0)) Then
Call OrangeAllignCorners()
End If
'=====================================================
'=====================================================
Me.scrRotations.Text &= ">ALIGNING ORANGE SIDES<" & vbCrLf
'Making sure to skip if it happens to be solved
' dub
If Not ((dub.Yellow.sideGrid(0, 1) = dub.Yellow.sideGrid(0, 0) And dub.Yellow.sideGrid(0, 1) = dub.Yellow.sideGrid(0, 2)) And _
(dub.Green.sideGrid(1, 2) = dub.Green.sideGrid(0, 2) And dub.Green.sideGrid(0, 2) = dub.Green.sideGrid(0, 2)) And _
(dub.White.sideGrid(2, 1) = dub.White.sideGrid(2, 2) And dub.White.sideGrid(2, 1) = dub.White.sideGrid(2, 0)) And _
(dub.Blue.sideGrid(1, 0) = dub.Blue.sideGrid(0, 0) And dub.Blue.sideGrid(1, 0) = dub.Blue.sideGrid(2, 0))) Then
'If there are no three straight faces in the row;
If Not ((dub.Yellow.sideGrid(0, 1) = dub.Yellow.sideGrid(0, 0) And dub.Yellow.sideGrid(0, 1) = dub.Yellow.sideGrid(0, 2)) Or _
(dub.Green.sideGrid(1, 2) = dub.Green.sideGrid(0, 2) And dub.Green.sideGrid(1, 2) = dub.Green.sideGrid(0, 2)) Or _
(dub.White.sideGrid(2, 1) = dub.White.sideGrid(2, 2) And dub.White.sideGrid(2, 1) = dub.White.sideGrid(2, 0)) Or _
(dub.Blue.sideGrid(1, 0) = dub.Blue.sideGrid(0, 0) And dub.Blue.sideGrid(1, 0) = dub.Blue.sideGrid(2, 0))) Then
dub.OrangeClockwise()
Me.Update()
Call LastStepToLeft()
End If
'Get both corners on to the right side
Do Until dub.White.sideGrid(2, 1) = dub.White.sideGrid(2, 0) And dub.White.sideGrid(2, 1) = dub.White.sideGrid(2, 2)
dub.OrangeClockwise()
Me.Update()
Loop
'dub.Yellow.sideGrid(0, 1) = dub.Green.sideGrid(0, 2)
If dub.Yellow.sideGrid(0, 1) = dub.Green.sideGrid(0, 2) Then
'We need to move the last thing left
Call LastStepToLeft()
ElseIf dub.Yellow.sideGrid(0, 1) = dub.Blue.sideGrid(0, 0) Then
'We need to move the last thing right
Call LastStepToRight()
End If
End If
'==========================================
'==========================================
'Rotate the last face counter clockwise until it is SOLVED
If Not dub.White.sideGrid(2, 1) = "W" Then
Me.scrRotations.Text &= ">THE FINAL ROTATIONS<" & vbCrLf
End If
Do Until dub.White.sideGrid(2, 1) = "W"
dub.OrangeClockwise()
Me.Update()
Loop
Me.scrRotations.Text &= ">SOLVED<" & vbCrLf
'Finalize
Me.dub.strRotation = Nothing
Me.Update()
boolEscape = True
Loop
End Sub
'Fixed algorithm; meant to get every orange squares on the side to the top of the orange face
Private Sub OrangeSide()
dub.YellowClockwise()
Me.Update()
dub.GreenClockwise()
Me.Update()
dub.OrangeCounterClockwise()
Me.Update()
dub.GreenCounterClockwise()
Me.Update()
dub.YellowCounterClockwise()
Me.Update()
dub.BlueCounterClockwise()
Me.Update()
dub.OrangeClockwise()
Me.Update()
dub.BlueClockwise()
Me.Update()
End Sub
'Fixed algorithm; meant to get ever corner orange to the top of the orange face
Private Sub OrangeCorner()
dub.GreenClockwise()
Me.Update()
dub.OrangeClockwise()
Me.Update()
dub.GreenCounterClockwise()
Me.Update()
dub.OrangeClockwise()
Me.Update()
dub.GreenClockwise()
Me.Update()
dub.OrangeCounterClockwise()
Me.Update()
dub.OrangeCounterClockwise()
Me.Update()
dub.GreenCounterClockwise()
Me.Update()
End Sub
'Meant to get the corners alligned
Private Sub OrangeAllignCorners()
dub.GreenCounterClockwise()
Me.Update()
dub.YellowClockwise()
Me.Update()
dub.GreenCounterClockwise()
Me.Update()
dub.WhiteClockwise()
Me.Update()
dub.WhiteClockwise()
Me.Update()
dub.GreenClockwise()
Me.Update()
dub.YellowCounterClockwise()
Me.Update()
dub.GreenCounterClockwise()
Me.Update()
dub.WhiteClockwise()
Me.Update()
dub.WhiteClockwise()
Me.Update()
dub.GreenClockwise()
Me.Update()
dub.GreenClockwise()
Me.Update()
End Sub
'Does final step left-wise
Private Sub LastStepToLeft()
dub.YellowClockwise()
Me.Update()
dub.YellowClockwise()
Me.Update()
dub.OrangeCounterClockwise()
Me.Update()
dub.GreenCounterClockwise()
Me.Update()
dub.BlueClockwise()
Me.Update()
dub.YellowClockwise()
Me.Update()
dub.YellowClockwise()
Me.Update()
dub.GreenClockwise()
Me.Update()
dub.BlueCounterClockwise()
Me.Update()
dub.OrangeCounterClockwise()
Me.Update()
dub.YellowClockwise()
Me.Update()
dub.YellowClockwise()
Me.Update()
End Sub
'Does final right-wise
Private Sub LastStepToRight()
dub.YellowClockwise()
Me.Update()
dub.YellowClockwise()
Me.Update()
dub.OrangeClockwise()
Me.Update()
dub.GreenCounterClockwise()
Me.Update()
dub.BlueClockwise()
Me.Update()
dub.YellowClockwise()
Me.Update()
dub.YellowClockwise()
Me.Update()
dub.GreenClockwise()
Me.Update()
dub.BlueCounterClockwise()
Me.Update()
dub.OrangeClockwise()
Me.Update()
dub.YellowClockwise()
Me.Update()
dub.YellowClockwise()
Me.Update()
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment