Last active
August 29, 2015 14:01
-
-
Save LizardLeliel/b335a653aefd633c627f to your computer and use it in GitHub Desktop.
A module of the two classes that were used for building the rubix cube program for the Saint Mary University's 2014 hackathon competition.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'The two classes here were used in "The Interactive Rubix Cube", created by Evan Larose and Tristan Murphy, | |
'for the SMU 2014 hackathon | |
'All code comments below were included in the actual module | |
Module RubixClasses | |
'The sides represent each face of the Rubix Cube. They're used in the cube class before. | |
'They have a string variable to represent what colour they are, as well as | |
'a 3x3 array of string that represent each square on the side | |
'They feature methods for rotating the face, as well as replacing rows/columns which are useful when building the cube | |
'class. The sidegrid array's data type was changed to a Visual Basic item called Observable String Grids. | |
Public Class Side | |
'Declare Instance variables, sideColour (to determine which colour this side is) and sideGrid (Which would contain squares) | |
Public sideColour As String | |
Public sideGrid(2, 2) As String | |
Public Sub New(ByRef strColour As String) | |
'Initialze every point of the grid | |
sideGrid(0, 0) = strColour | |
sideGrid(0, 1) = strColour | |
sideGrid(0, 2) = strColour | |
sideGrid(1, 0) = strColour | |
sideGrid(1, 1) = strColour | |
sideGrid(1, 2) = strColour | |
sideGrid(2, 0) = strColour | |
sideGrid(2, 1) = strColour | |
sideGrid(2, 2) = strColour | |
End Sub | |
Public Sub RotateClockwise() | |
Dim sideUnload(2, 2) As String | |
'Determins how the rotation would like in a copy | |
sideUnload(0, 0) = Me.sideGrid(2, 0) | |
sideUnload(0, 1) = Me.sideGrid(1, 0) | |
sideUnload(0, 2) = Me.sideGrid(0, 0) | |
sideUnload(1, 0) = Me.sideGrid(2, 1) | |
sideUnload(1, 1) = Me.sideGrid(1, 1) | |
sideUnload(1, 2) = Me.sideGrid(0, 1) | |
sideUnload(2, 0) = Me.sideGrid(2, 2) | |
sideUnload(2, 1) = Me.sideGrid(1, 2) | |
sideUnload(2, 2) = Me.sideGrid(0, 2) | |
'Put the copy into the original grid | |
Me.sideGrid(0, 0) = sideUnload(0, 0) | |
Me.sideGrid(0, 1) = sideUnload(0, 1) | |
Me.sideGrid(0, 2) = sideUnload(0, 2) | |
Me.sideGrid(1, 0) = sideUnload(1, 0) | |
Me.sideGrid(1, 1) = sideUnload(1, 1) | |
Me.sideGrid(1, 2) = sideUnload(1, 2) | |
Me.sideGrid(2, 0) = sideUnload(2, 0) | |
Me.sideGrid(2, 1) = sideUnload(2, 1) | |
Me.sideGrid(2, 2) = sideUnload(2, 2) | |
End Sub | |
Public Sub RotateCounterClockwise() | |
Dim sideUnload(2, 2) As String | |
'Determines how the rotation would like in a copy | |
sideUnload(0, 0) = Me.sideGrid(0, 2) | |
sideUnload(0, 1) = Me.sideGrid(1, 2) | |
sideUnload(0, 2) = Me.sideGrid(2, 2) | |
sideUnload(1, 0) = Me.sideGrid(0, 1) | |
sideUnload(1, 1) = Me.sideGrid(1, 1) | |
sideUnload(1, 2) = Me.sideGrid(2, 1) | |
sideUnload(2, 0) = Me.sideGrid(0, 0) | |
sideUnload(2, 1) = Me.sideGrid(1, 0) | |
sideUnload(2, 2) = Me.sideGrid(2, 0) | |
'Put the copy into the original grid | |
Me.sideGrid(0, 0) = sideUnload(0, 0) | |
Me.sideGrid(0, 1) = sideUnload(0, 1) | |
Me.sideGrid(0, 2) = sideUnload(0, 2) | |
Me.sideGrid(1, 0) = sideUnload(1, 0) | |
Me.sideGrid(1, 1) = sideUnload(1, 1) | |
Me.sideGrid(1, 2) = sideUnload(1, 2) | |
Me.sideGrid(2, 0) = sideUnload(2, 0) | |
Me.sideGrid(2, 1) = sideUnload(2, 1) | |
Me.sideGrid(2, 2) = sideUnload(2, 2) | |
End Sub | |
Public Sub TopRowReplace(ByVal strRP1 As String, ByVal strRP2 As String, ByVal strRP3 As String) | |
'Replaces the top row (for rubric cube rotations) | |
Me.sideGrid(0, 0) = strRP1 | |
Me.sideGrid(0, 1) = strRP2 | |
Me.sideGrid(0, 2) = strRP3 | |
End Sub | |
Public Sub BottomRowReplace(ByVal strRP1 As String, ByVal strRP2 As String, ByVal strRP3 As String) | |
'Replaces the top row (for rubric cube rotations) | |
Me.sideGrid(2, 0) = strRP1 | |
Me.sideGrid(2, 1) = strRP2 | |
Me.sideGrid(2, 2) = strRP3 | |
End Sub | |
Public Sub LeftColumnReplace(ByVal strRP1 As String, ByVal strRP2 As String, ByVal strRP3 As String) | |
'Repleaces the left column (for rubric cube rotations) | |
Me.sideGrid(0, 0) = strRP1 | |
Me.sideGrid(1, 0) = strRP2 | |
Me.sideGrid(2, 0) = strRP3 | |
End Sub | |
Public Sub RightColumnReplace(ByVal strRP1 As String, ByVal strRP2 As String, ByVal strRP3 As String) | |
'Replaces the right column (for rubric cube rotations) | |
Me.sideGrid(0, 2) = strRP1 | |
Me.sideGrid(1, 2) = strRP2 | |
Me.sideGrid(2, 2) = strRP3 | |
End Sub | |
End Class | |
'The cube class - this creates six instances of the side glass, one for each coloured side of a rubix cube. | |
'Contains 12 methods for each of the possible rotation on a Rubix cube - as well as a variable | |
'to store a string describing the last rotation the cube has done. And lastly, a random rotation method | |
'for having the computer do a series of random rotations. | |
Public Class Cube | |
'Declaring Public Variables | |
Public Red As Side = New Side("R") | |
Public Yellow As Side = New Side("Y") | |
Public Blue As Side = New Side("B") | |
Public White As Side = New Side("W") | |
Public Green As Side = New Side("G") | |
Public Orange As Side = New Side("O") | |
Public strRotation As String | |
'Rotates the red face clockwise | |
Public Sub RedClockwise() | |
Me.Red.RotateClockwise() | |
Dim strBuffer1 As String = Me.Yellow.sideGrid(2, 0) | |
Dim strBuffer2 As String = Me.Yellow.sideGrid(2, 1) | |
Dim strBuffer3 As String = Me.Yellow.sideGrid(2, 2) | |
Me.Yellow.BottomRowReplace(Me.Blue.sideGrid(2, 2), Me.Blue.sideGrid(1, 2), Me.Blue.sideGrid(0, 2)) | |
Me.Blue.RightColumnReplace(Me.White.sideGrid(0, 0), Me.White.sideGrid(0, 1), Me.White.sideGrid(0, 2)) | |
Me.White.TopRowReplace(Me.Green.sideGrid(2, 0), Me.Green.sideGrid(1, 0), Me.Green.sideGrid(0, 0)) | |
Me.Green.LeftColumnReplace(strBuffer1, strBuffer2, strBuffer3) | |
Me.DoThis("Red Clockwise") | |
End Sub | |
'Rotates the red face counterclockwise | |
Public Sub RedCounterClockwise() | |
Me.Red.RotateCounterClockwise() | |
Dim strBuffer1 As String = Me.Yellow.sideGrid(2, 0) | |
Dim strBuffer2 As String = Me.Yellow.sideGrid(2, 1) | |
Dim strBuffer3 As String = Me.Yellow.sideGrid(2, 2) | |
Me.Yellow.BottomRowReplace(Me.Green.sideGrid(0, 0), Me.Green.sideGrid(1, 0), Me.Green.sideGrid(2, 0)) | |
Me.Green.LeftColumnReplace(Me.White.sideGrid(0, 2), Me.White.sideGrid(0, 1), Me.White.sideGrid(0, 0)) | |
Me.White.TopRowReplace(Me.Blue.sideGrid(0, 2), Me.Blue.sideGrid(1, 2), Me.Blue.sideGrid(2, 2)) | |
Me.Blue.RightColumnReplace(strBuffer3, strBuffer2, strBuffer1) | |
Me.DoThis("Red Counter Clockwise") | |
End Sub | |
'Rotates the yellow face clockwise | |
Public Sub YellowClockwise() | |
Me.Yellow.RotateClockwise() | |
Dim strBuffer1 As String = Me.Red.sideGrid(0, 0) | |
Dim strBuffer2 As String = Me.Red.sideGrid(0, 1) | |
Dim strBuffer3 As String = Me.Red.sideGrid(0, 2) | |
Me.Red.TopRowReplace(Me.Green.sideGrid(0, 0), Me.Green.sideGrid(0, 1), Me.Green.sideGrid(0, 2)) | |
Me.Green.TopRowReplace(Me.Orange.sideGrid(0, 0), Me.Orange.sideGrid(0, 1), Me.Orange.sideGrid(0, 2)) | |
Me.Orange.TopRowReplace(Me.Blue.sideGrid(0, 0), Me.Blue.sideGrid(0, 1), Me.Blue.sideGrid(0, 2)) | |
Me.Blue.TopRowReplace(strBuffer1, strBuffer2, strBuffer3) | |
Me.DoThis("Yellow Clockwise") | |
End Sub | |
'Rotates the yellow face counterclockwise | |
Public Sub YellowCounterClockwise() | |
Me.Yellow.RotateCounterClockwise() | |
Dim strBuffer1 As String = Me.Red.sideGrid(0, 0) | |
Dim strBuffer2 As String = Me.Red.sideGrid(0, 1) | |
Dim strBuffer3 As String = Me.Red.sideGrid(0, 2) | |
Me.Red.TopRowReplace(Me.Blue.sideGrid(0, 0), Me.Blue.sideGrid(0, 1), Me.Blue.sideGrid(0, 2)) | |
Me.Blue.TopRowReplace(Me.Orange.sideGrid(0, 0), Me.Orange.sideGrid(0, 1), Me.Orange.sideGrid(0, 2)) | |
Me.Orange.TopRowReplace(Me.Green.sideGrid(0, 0), Me.Green.sideGrid(0, 1), Me.Green.sideGrid(0, 2)) | |
Me.Green.TopRowReplace(strBuffer1, strBuffer2, strBuffer3) | |
Me.DoThis("Yellow Counter Clockwise") | |
End Sub | |
'Rotate the white face clockwise | |
Public Sub WhiteClockwise() | |
Me.White.RotateClockwise() | |
Dim strBuff1 As String = Me.Red.sideGrid(2, 0) | |
Dim strBuff2 As String = Me.Red.sideGrid(2, 1) | |
Dim strBuff3 As String = Me.Red.sideGrid(2, 2) | |
Me.Red.BottomRowReplace(Me.Blue.sideGrid(2, 0), Me.Blue.sideGrid(2, 1), Me.Blue.sideGrid(2, 2)) | |
Me.Blue.BottomRowReplace(Me.Orange.sideGrid(2, 0), Me.Orange.sideGrid(2, 1), Me.Orange.sideGrid(2, 2)) | |
Me.Orange.BottomRowReplace(Me.Green.sideGrid(2, 0), Me.Green.sideGrid(2, 1), Me.Green.sideGrid(2, 2)) | |
Me.Green.BottomRowReplace(strBuff1, strBuff2, strBuff3) | |
Me.DoThis("White Clockwise") | |
End Sub | |
'Rotate the white face counterclockwise | |
Public Sub WhiteCounterClockwise() | |
Me.White.RotateCounterClockwise() | |
Dim strBuff1 As String = Me.Red.sideGrid(2, 0) | |
Dim strBuff2 As String = Me.Red.sideGrid(2, 1) | |
Dim strBuff3 As String = Me.Red.sideGrid(2, 2) | |
Me.Red.BottomRowReplace(Me.Green.sideGrid(2, 0), Me.Green.sideGrid(2, 1), Me.Green.sideGrid(2, 2)) | |
Me.Green.BottomRowReplace(Me.Orange.sideGrid(2, 0), Me.Orange.sideGrid(2, 1), Me.Orange.sideGrid(2, 2)) | |
Me.Orange.BottomRowReplace(Me.Blue.sideGrid(2, 0), Me.Blue.sideGrid(2, 1), Me.Blue.sideGrid(2, 2)) | |
Me.Blue.BottomRowReplace(strBuff1, strBuff2, strBuff3) | |
Me.DoThis("White Counter Clockwise") | |
End Sub | |
'Roatate the blue face clockwise | |
Public Sub BlueClockwise() | |
Me.Blue.RotateClockwise() | |
Dim strBuff1 As String = Me.Red.sideGrid(0, 0) | |
Dim strBuff2 As String = Me.Red.sideGrid(1, 0) | |
Dim strBuff3 As String = Me.Red.sideGrid(2, 0) | |
Me.Red.LeftColumnReplace(Me.Yellow.sideGrid(0, 0), Me.Yellow.sideGrid(1, 0), Me.Yellow.sideGrid(2, 0)) | |
Me.Yellow.LeftColumnReplace(Me.Orange.sideGrid(2, 2), Me.Orange.sideGrid(1, 2), Me.Orange.sideGrid(0, 2)) | |
Me.Orange.RightColumnReplace(Me.White.sideGrid(2, 0), Me.White.sideGrid(1, 0), Me.White.sideGrid(0, 0)) | |
Me.White.LeftColumnReplace(strBuff1, strBuff2, strBuff3) | |
Me.DoThis("Blue Clockwise") | |
End Sub | |
'Rotate the blue face counter-clockwise | |
Public Sub BlueCounterClockwise() | |
Me.Blue.RotateCounterClockwise() | |
Dim strBuff1 As String = Me.Red.sideGrid(0, 0) | |
Dim strBuff2 As String = Me.Red.sideGrid(1, 0) | |
Dim strBuff3 As String = Me.Red.sideGrid(2, 0) | |
Me.Red.LeftColumnReplace(Me.White.sideGrid(0, 0), Me.White.sideGrid(1, 0), Me.White.sideGrid(2, 0)) | |
Me.White.LeftColumnReplace(Me.Orange.sideGrid(2, 2), Me.Orange.sideGrid(1, 2), Me.Orange.sideGrid(0, 2)) | |
Me.Orange.RightColumnReplace(Me.Yellow.sideGrid(2, 0), Me.Yellow.sideGrid(1, 0), Me.Yellow.sideGrid(0, 0)) | |
Me.Yellow.LeftColumnReplace(strBuff1, strBuff2, strBuff3) | |
Me.DoThis("Blue Counter Clockwise") | |
End Sub | |
'Rotate the green face clockwise | |
Public Sub GreenClockwise() | |
Me.Green.RotateClockwise() | |
Dim strBuff1 As String = Me.Red.sideGrid(0, 2) | |
Dim strBuff2 As String = Me.Red.sideGrid(1, 2) | |
Dim strBuff3 As String = Me.Red.sideGrid(2, 2) | |
Me.Red.RightColumnReplace(Me.White.sideGrid(0, 2), Me.White.sideGrid(1, 2), Me.White.sideGrid(2, 2)) | |
Me.White.RightColumnReplace(Me.Orange.sideGrid(2, 0), Me.Orange.sideGrid(1, 0), Me.Orange.sideGrid(0, 0)) | |
Me.Orange.LeftColumnReplace(Me.Yellow.sideGrid(2, 2), Me.Yellow.sideGrid(1, 2), Me.Yellow.sideGrid(0, 2)) | |
Me.Yellow.RightColumnReplace(strBuff1, strBuff2, strBuff3) | |
Me.DoThis("Green Clockwise") | |
End Sub | |
'Rotate the green face counter clockwise | |
Public Sub GreenCounterClockwise() | |
Me.Green.RotateCounterClockwise() | |
Dim strBuff1 As String = Me.Red.sideGrid(0, 2) | |
Dim strBuff2 As String = Me.Red.sideGrid(1, 2) | |
Dim strBuff3 As String = Me.Red.sideGrid(2, 2) | |
Me.Red.RightColumnReplace(Me.Yellow.sideGrid(0, 2), Me.Yellow.sideGrid(1, 2), Me.Yellow.sideGrid(2, 2)) | |
Me.Yellow.RightColumnReplace(Me.Orange.sideGrid(2, 0), Me.Orange.sideGrid(1, 0), Me.Orange.sideGrid(0, 0)) | |
Me.Orange.LeftColumnReplace(Me.White.sideGrid(2, 2), Me.White.sideGrid(1, 2), Me.White.sideGrid(0, 2)) | |
Me.White.RightColumnReplace(strBuff1, strBuff2, strBuff3) | |
Me.DoThis("Green Counter Clockwise") | |
End Sub | |
'Rotate the orange side clockwise | |
Public Sub OrangeClockwise() | |
Me.Orange.RotateClockwise() | |
Dim strBuff1 As String = Me.Yellow.sideGrid(0, 0) | |
Dim strBuff2 As String = Me.Yellow.sideGrid(0, 1) | |
Dim strBuff3 As String = Me.Yellow.sideGrid(0, 2) | |
Me.Yellow.TopRowReplace(Me.Green.sideGrid(0, 2), Me.Green.sideGrid(1, 2), Me.Green.sideGrid(2, 2)) | |
Me.Green.RightColumnReplace(Me.White.sideGrid(2, 2), Me.White.sideGrid(2, 1), Me.White.sideGrid(2, 0)) | |
Me.White.BottomRowReplace(Me.Blue.sideGrid(0, 0), Me.Blue.sideGrid(1, 0), Me.Blue.sideGrid(2, 0)) | |
Me.Blue.LeftColumnReplace(strBuff3, strBuff2, strBuff1) | |
Me.DoThis("Orange Clockwise") | |
End Sub | |
'Rotate the orange side counter clockwise | |
Public Sub OrangeCounterClockwise() | |
Me.Orange.RotateCounterClockwise() | |
Dim strBuff1 As String = Me.Yellow.sideGrid(0, 0) | |
Dim strBuff2 As String = Me.Yellow.sideGrid(0, 1) | |
Dim strBuff3 As String = Me.Yellow.sideGrid(0, 2) | |
Me.Yellow.TopRowReplace(Me.Blue.sideGrid(2, 0), Me.Blue.sideGrid(1, 0), Me.Blue.sideGrid(0, 0)) | |
Me.Blue.LeftColumnReplace(Me.White.sideGrid(2, 0), Me.White.sideGrid(2, 1), Me.White.sideGrid(2, 2)) | |
Me.White.BottomRowReplace(Me.Green.sideGrid(2, 2), Me.Green.sideGrid(1, 2), Me.Green.sideGrid(0, 2)) | |
Me.Green.RightColumnReplace(strBuff1, strBuff2, strBuff3) | |
Me.DoThis("Orange Counter Clockwise") | |
End Sub | |
'Do random rotations on the cube | |
Public Sub RandomMoves(ByVal intInteger As Integer) | |
Dim iloop As Integer | |
Randomize() | |
For iloop = 1 To intInteger | |
Dim intDecision As Integer = Int((12 - 1 + 1) * Rnd() + 1) | |
Select Case intDecision | |
Case 1 | |
Me.RedClockwise() | |
Case 2 | |
Me.RedCounterClockwise() | |
Case 3 | |
Me.YellowClockwise() | |
Case 4 | |
Me.YellowCounterClockwise() | |
Case 5 | |
Me.BlueClockwise() | |
Case 6 | |
Me.BlueCounterClockwise() | |
Case 7 | |
Me.GreenClockwise() | |
Case 8 | |
Me.GreenCounterClockwise() | |
Case 9 | |
Me.WhiteClockwise() | |
Case 10 | |
Me.WhiteCounterClockwise() | |
Case 11 | |
Me.OrangeClockwise() | |
Case 12 | |
Me.OrangeCounterClockwise() | |
End Select | |
Next | |
End Sub | |
Public Sub DoThis(ByVal Rotation As String) | |
'Assign lest rotation string variable | |
Me.strRotation = Rotation | |
End Sub | |
End Class | |
End Module |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment