Пример #1
0
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
Пример #2
0
    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
Пример #3
0
    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
Пример #4
0
import py222
import solver
import numpy as np

# get solved state
s = py222.initState()

# apply some scramble
s = py222.doAlgStr(s, "F2")

# solve cube
solver.solveCube(s)
Пример #5
0
    # 接收用戶的輸入值並轉成小寫
    while True:
        choice = input('輸入"help"給予解魔方提示 輸入"e"退出本程式\n').lower()
        #5 白 4 綠 3 青 2 澄 1 藍 0 紅
        if choice == 'help':
            print('傳送解析指令')
            ser.write('os'.encode())
            while 1:
                if (ser.in_waiting):
                    mcu_feedback = ser.readline().decode()  # 接收回應訊息並解碼
                    s = mcu_feedback.split(' ')
                    s.remove('')
                    print(s)
                    arr = np.array([
                        s[18], s[17], s[19], s[16], s[13], s[12], s[14], s[15],
                        s[1], s[0], s[2], s[3], s[20], s[23], s[21], s[22],
                        s[5], s[4], s[6], s[7], s[9], s[8], s[10], s[11]
                    ])
                    arr = arr.astype(int)
                    solver.solveCube(arr)
                    break
        elif choice == 'e':
            ser.close()
            print('再見!')
            sys.exit()
        else:
            print('指令錯誤…')

except KeyboardInterrupt:
    ser.close()
    print('再見!')