def keyboard(key, x, y): if key == 'q': print "Quitting..." sys.exit(0) elif key == 's': solver.loadCube(cube) if not solver.isSolved(): globals()['actions'] = solver.solveCube() print "Solving %d steps" % len(globals()['actions']) solve(0) elif key == 'a': globals()['actions'] = [] elif key == 'r': cube.scramble() drawGLScene() elif key == 'n': rot = globals()['cube'].rot globals()['cube'] = Cube(globals()['size']) globals()['actions'] = [] globals()['cube'].rot = rot drawGLScene() elif key == '+': cube.zoomIn() drawGLScene() elif key == '-': cube.zoomOut() drawGLScene() elif key == 'h': print help
def registerSideRotation(self, solving=False): while len(self.rotateList) != 0: last = 0 boxId = self.rotateList[0] while not last: self.rotateList.remove(boxId) prevBoxId = self.prevId(boxId) if prevBoxId in self.rotateList: self.boxes[prevBoxId].rotateBox(self.sideRot) relPos = self.findRelativePos(boxId) self.boxes[prevBoxId].pos = self.relativeToAbsolutePos( relPos) box = self.boxes[boxId] self.boxes[boxId] = self.boxes[prevBoxId] self.boxes[prevBoxId] = box else: self.boxes[boxId].rotateBox(self.sideRot) relPos = self.findRelativePos(boxId) self.boxes[boxId].pos = self.relativeToAbsolutePos(relPos) last = 1 boxId = prevBoxId #self.sideRot = Quaternion() self.sideRot = [0., 0., 0.] # if we're in auto-solve mode, we don't # need to check for correct solution if not solving: # check if cube is solved solver.loadCube(self) # sorry to say we "only" support solving # of 3x3x3 cubes at this time if self.n == 3: if solver.isSolved() and self.n == 3: print "Solved" else: left = len(solver.solveCube()) if (left == 1): print "One move left!" elif (left <= 10): print "%d moves left" % left
def registerSideRotation(self, solving=False): while len(self.rotateList) != 0: last = 0 boxId = self.rotateList[0] while not last: self.rotateList.remove(boxId) prevBoxId = self.prevId(boxId) if prevBoxId in self.rotateList: self.boxes[prevBoxId].rotateBox(self.sideRot) relPos = self.findRelativePos(boxId) self.boxes[prevBoxId].pos = self.relativeToAbsolutePos(relPos) box = self.boxes[boxId] self.boxes[boxId] = self.boxes[prevBoxId] self.boxes[prevBoxId] = box else: self.boxes[boxId].rotateBox(self.sideRot) relPos = self.findRelativePos(boxId) self.boxes[boxId].pos = self.relativeToAbsolutePos(relPos) last = 1 boxId = prevBoxId #self.sideRot = Quaternion() self.sideRot = [ 0., 0., 0. ] # if we're in auto-solve mode, we don't # need to check for correct solution if not solving: # check if cube is solved solver.loadCube(self) # sorry to say we "only" support solving # of 3x3x3 cubes at this time if self.n == 3: if solver.isSolved() and self.n == 3: print "Solved" else: left = len(solver.solveCube()) if (left == 1): print "One move left!" elif (left <= 10): print "%d moves left" % left