I've defined the colors of the faces to match the physical cube that I have (with blue on top... for now). The locations are given by a two dimensional array. The first dimension gives the face (0 = U, 1 = L, 2 = F, 3 = R, 4 = B, 5 = D) and the second dimension gives the position (0-8 starting from the top left and working across the rows and down the columns). I also added a 7th color (gray) for when I'm searching for moves that permute certain pieces but that do not care what happens to certain other pieces.
The next task will be to program in the permutations obtained from the 18 basic movements. I thought about just programming in the 6 clockwise rotations and then having the others generated by repeating these, but I suspect that I'll be checking millions of positions, so that would just make things inefficient. When it comes time to writing the search algorithm, I may need to also write in a "don't be dumb" check that doesn't let me do two moves on the same face in a row. But I'll get to that one probably in the next few days.
I've set myself up to have two windows. One to show the unfolded cube and the other to show a 3D cube. I actually want to use the second window to display move sequences with a visual aid to help me get it right. It's not necessary, but it just seemed like a fun thing to try. That will be done towards the end of the project.
Here's the existing code:
import pygame
# Global Variables
sGap = 5
bGap = 10
boxSize = 30
# Functions
def posCalc(bS, sG, bG):
return bS*boxSize + sG*sGap + bG*bGap
def drawIt1(window, sqPos, sqColor, drawColor):
for i in range(6):
for ii in range(9):
pygame.draw.rect(window,
drawColor[sqColor[i][ii]],
( sqPos[i][ii][0], sqPos[i][ii][1], boxSize, boxSize ),
0)
pygame.display.update()
return
# Define drawing data
sqPos = [ [ [posCalc(3,3,1), posCalc(0,1,0)],
[posCalc(4,4,1), posCalc(0,1,0)],
[posCalc(5,5,1), posCalc(0,1,0)],
[posCalc(3,3,1), posCalc(1,2,0)],
[posCalc(4,4,1), posCalc(1,2,0)],
[posCalc(5,5,1), posCalc(1,2,0)],
[posCalc(3,3,1), posCalc(2,3,0)],
[posCalc(4,4,1), posCalc(2,3,0)],
[posCalc(5,5,1), posCalc(2,3,0)] ],
[ [posCalc(0,1,0), posCalc(3,3,1)],
[posCalc(1,2,0), posCalc(3,3,1)],
[posCalc(2,3,0), posCalc(3,3,1)],
[posCalc(0,1,0), posCalc(4,4,1)],
[posCalc(1,2,0), posCalc(4,4,1)],
[posCalc(2,3,0), posCalc(4,4,1)],
[posCalc(0,1,0), posCalc(5,5,1)],
[posCalc(1,2,0), posCalc(5,5,1)],
[posCalc(2,3,0), posCalc(5,5,1)] ],
[ [posCalc(3,3,1), posCalc(3,3,1)],
[posCalc(4,4,1), posCalc(3,3,1)],
[posCalc(5,5,1), posCalc(3,3,1)],
[posCalc(3,3,1), posCalc(4,4,1)],
[posCalc(4,4,1), posCalc(4,4,1)],
[posCalc(5,5,1), posCalc(4,4,1)],
[posCalc(3,3,1), posCalc(5,5,1)],
[posCalc(4,4,1), posCalc(5,5,1)],
[posCalc(5,5,1), posCalc(5,5,1)] ],
[ [posCalc(6,5,2), posCalc(3,3,1)],
[posCalc(7,6,2), posCalc(3,3,1)],
[posCalc(8,7,2), posCalc(3,3,1)],
[posCalc(6,5,2), posCalc(4,4,1)],
[posCalc(7,6,2), posCalc(4,4,1)],
[posCalc(8,7,2), posCalc(4,4,1)],
[posCalc(6,5,2), posCalc(5,5,1)],
[posCalc(7,6,2), posCalc(5,5,1)],
[posCalc(8,7,2), posCalc(5,5,1)] ],
[ [posCalc(9,7,3), posCalc(3,3,1)],
[posCalc(10,8,3), posCalc(3,3,1)],
[posCalc(11,9,3), posCalc(3,3,1)],
[posCalc(9,7,3), posCalc(4,4,1)],
[posCalc(10,8,3), posCalc(4,4,1)],
[posCalc(11,9,3), posCalc(4,4,1)],
[posCalc(9,7,3), posCalc(5,5,1)],
[posCalc(10,8,3), posCalc(5,5,1)],
[posCalc(11,9,3), posCalc(5,5,1)] ],
[ [posCalc(3,3,1), posCalc(6,5,2)],
[posCalc(4,4,1), posCalc(6,5,2)],
[posCalc(5,5,1), posCalc(6,5,2)],
[posCalc(3,3,1), posCalc(7,6,2)],
[posCalc(4,4,1), posCalc(7,6,2)],
[posCalc(5,5,1), posCalc(7,6,2)],
[posCalc(3,3,1), posCalc(8,7,2)],
[posCalc(4,4,1), posCalc(8,7,2)],
[posCalc(5,5,1), posCalc(8,7,2)] ]
]
sqColor = [ [ i for ii in range(9) ] for i in range(6) ]
drawColor = [ pygame.Color(0,0,255),
pygame.Color(255,0,0),
pygame.Color(255,255,0),
pygame.Color(255,140,0),
pygame.Color(255,255,255),
pygame.Color(0,255,0),
pygame.Color(100,100,100) ]
### Main program
# Initialize
pygame.init()
window1Width = posCalc(12,10,3)
window1Height = posCalc(9,8,2)
window1 = pygame.display.set_mode((window1Width,window1Height))
drawIt1(window1, sqPos, sqColor, drawColor)
No comments:
Post a Comment