예제 #1
0
 def __init__(self, color, pos):
     self.color = color
     self.head = Cube(pos)
     self.body.append(self.head)
     self.dir_x = 0
     self.dir_y = 0
     rows = settings.rows
예제 #2
0
def main():
    #global vars
    global s, snack
    st.init()
    s = Snake(st.snake_color, (st.snake_x, st.snake_y))
    snack = Cube(randomSnack(st.rows, s), color=st.snack_color)

    #create window
    window = pygame.display.set_mode((st.width, st.width))

    #Display elements
    flag = True
    clock = pygame.time.Clock()
    delay_time = 50
    tick_time = 10

    while flag:
        pygame.time.delay(delay_time)
        clock.tick(tick_time)
        s.move()
        snack_check()
        # snake_check()
        for x in range(len(s.body)):
            if s.body[x].pos in list(map(lambda z: z.pos, s.body[x + 1:])):
                print('Score: ', len(s.body))
                # message_box('You Lost!', 'Play again...')
                s.reset((10, 10))
                break
        redrawWindow(window)
    pass
예제 #3
0
 def reset(self, pos):
     self.head = Cube(pos)
     self.body = []
     self.body.append(self.head)
     self.turns = {}
     self.dir_x = 0
     self.dir_y = 1
예제 #4
0
    def addCube(self):
        tail = self.body[-1]
        dx, dy = tail.dir_x, tail.dir_y

        if dx == 1 and dy == 0:  # moving right
            new_pos = (tail.pos[0] - 1, tail.pos[1])
            self.body.append(Cube(new_pos))
        elif dx == -1 and dy == 0:  # left
            new_pos = (tail.pos[0] + 1, tail.pos[1])
            self.body.append(Cube(new_pos))
        elif dx == 0 and dy == -1:  # up
            new_pos = (tail.pos[0], tail.pos[1] + 1)
            self.body.append(Cube(new_pos))
        elif dx == 0 and dy == 1:  # down
            new_pos = (tail.pos[0], tail.pos[1] - 1)
            self.body.append(Cube(new_pos))

        self.body[-1].dir_x = dx
        self.body[-1].dir_y = dy
예제 #5
0
class Facade:

    def __init__(self):
        self.sphere_obj = Sphere(3)
        self.cube_obj = Cube(3)
        self.cylinder_obj = Cylinder(3, 7)
        self.cone_obj = Cone(3, 5)

    def get_volume(self):

        return self.sphere_obj.get_volume() + self.cube_obj.get_volume() + \
               self.cylinder_obj.get_volume() + self.cone_obj.get_volume()
예제 #6
0
파일: test.py 프로젝트: Nyanyan/Solvour
def scramble_to_state(scramble):
    cube = Cube()
    for i in scramble:
        cube = cube.move(i)
    res = [-1 for _ in range(96)]
    corners = [[32, 80, 28], [35, 31, 67], [44, 48, 83], [47, 64, 51], [0, 95, 60], [3, 63, 76], [12, 16, 92], [15, 79, 19]]
    corner_colors = [[0, 4, 3], [0, 3, 2], [0, 1, 4], [0, 2, 1], [5, 4, 1], [5, 1, 2], [5, 3, 4], [5, 2, 3]]
    for i in range(8):
        cp = cube.Cp[i]
        co = cube.Co[i]
        for j, idx in enumerate(corners[i]):
            res[idx] = corner_colors[cp][(j - co) % 3]
    edges = [[33, 29], [30, 34], [39, 66], [65, 43], [46, 50], [49, 45], [40, 82], [81, 36], [87, 52], [56, 91], [72, 59], [55, 68], [71, 27], [23, 75], [88, 20], [24, 84], [1, 61], [62, 2], [7, 77], [78, 11], [14, 18], [17, 13], [8, 93], [94, 4]]
    edge_colors = [[0, 3], [3, 0], [0, 2], [2, 0], [0, 1], [1, 0], [0, 4], [4, 0], [4, 1], [1, 4], [2, 1], [1, 2], [2, 3], [3, 2], [4, 3], [3, 4], [5, 1], [1, 5], [5, 2], [2, 5], [5, 3], [3, 5], [5, 4], [4, 5]]
    for i in range(24):
        ep = cube.Ep[i]
        for j, idx in enumerate(edges[i]):
            res[idx] = edge_colors[ep][j]
    centers = [37, 38, 42, 41, 53, 54, 58, 57, 69, 70, 74, 73, 26, 25, 21, 22, 85, 86, 90, 89, 5, 6, 10, 9]
    for i in range(24):
        res[centers[i]] = cube.Ce[i]
    return res
예제 #7
0
'''
4x4x4 Solver Move Table Part Written by Nyanyan
Copyright 2020 Nyanyan
'''

from cube_class import Cube, face, axis, wide, move_cp, move_co, move_ep, move_ce, move_candidate, twist_to_idx, successor, idx_ep_phase1, ep_switch_parity, cmb
from collections import deque
import csv

move_arr = [
    0, 1, 2, 3, 4, 5, 6, 7, 8, 12, 13, 14, 15, 16, 17, 18, 19, 20, 24, 25, 26,
    27, 28, 29, 30, 31, 32
]

solved = Cube()
ce_move_phase0 = [[-1 for _ in range(len(move_arr))] for _ in range(735471)]
que = deque([solved])
cnt = 0
print('CE move index phase0')
while que:
    cnt += 1
    if cnt % 10000 == 0:
        print(cnt, len(que))
    puzzle = que.popleft()
    idx = puzzle.idx_ce_phase0()
    #print(idx)
    if ce_move_phase0[idx][0] == -1:
        for twist in move_arr:
            n_puzzle = puzzle.move(twist)
            n_idx = n_puzzle.idx_ce_phase0()
            ce_move_phase0[idx][twist_to_idx[twist]] = n_idx
예제 #8
0
def init_grid():
    grid = []
    for i in range(ST.ROWS):
        grid.append([Cube(i, j) for j in range(ST.COLS)])
    return grid
예제 #9
0
 def __init__(self):
     self.sphere_obj = Sphere(3)
     self.cube_obj = Cube(3)
     self.cylinder_obj = Cylinder(3, 7)
     self.cone_obj = Cone(3, 5)
예제 #10
0
'''


def generate(depth, l_twist, cube):
    if depth == 0:
        return cube
    twist = randint(0, 17)
    while twist // 3 == l_twist // 3:
        twist = randint(0, 17)
    cube = cube.move(twist)
    return generate(depth - 1, twist, cube)


res = []
few_move = []
cube = Cube()
tmp = cube.idx()
tmp.append(0)
few_move.append(tmp)
print(cube.idx())
#label = list(range(324))
#label.append('num')
#res.append(label)
#generate(cube, 0, -10)
for depth in range(1, 21):
    for _ in range(100):
        tmp = generate(depth, -10, Cube()).idx()
        tmp.append(depth)
        res.append(tmp)

with open('data.csv', mode='w') as f:
예제 #11
0
def snack_check():
    global s, snack
    if s.body[0].pos == snack.pos:
        s.addCube()
        snack = Cube(randomSnack(st.rows, s), color=st.snack_color)
예제 #12
0
from cube_class import Cube, face, axis
from collections import deque
import csv

#                  0    1     2     3    4     5     6     7    8     9    10    11    12   13    14    15   16    17
move_candidate = [
    "R", "R2", "R'", "L", "L2", "L'", "U", "U2", "U'", "D", "D2", "D'", "F",
    "F2", "F'", "B", "B2", "B'"
]

successor = [[0, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15, 17],
             [1, 4, 6, 7, 8, 9, 10, 11, 13, 16]]

solved = Cube()
'''
cp_move = [[-1 for _ in range(18)] for _ in range(40320)]
que = deque([solved])
cnt = 0
print('CP move index')
while que:
    cnt += 1
    if cnt % 10000 == 0:
        print(cnt, len(que))
    puzzle = que.popleft()
    idx = puzzle.idx_cp()
    if cp_move[idx][0] == -1:
        for twist in range(18):
            n_puzzle = puzzle.move(twist)
            n_idx = n_puzzle.idx_cp()
            cp_move[idx][twist] = n_idx
            que.append(n_puzzle)
예제 #13
0
prun_len = [5, 4]
prunning = [[[] for _ in range(prun_len[i])] for i in range(2)]
for phase in range(2):
    with open('prunning_phase' + str(phase) + '.csv', mode='r') as f:
        for j in range(prun_len[phase]):
            prunning[phase][j] = [
                int(i) for i in f.readline().replace('\n', '').split(',')
            ]

successor = [[0, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15, 17],
             [1, 4, 6, 7, 8, 9, 10, 11, 13, 16]]
move_candidate = [
    "R", "R2", "R'", "L", "L2", "L'", "U", "U2", "U'", "D", "D2", "D'", "F",
    "F2", "F'", "B", "B2", "B'"
]
solution = []
path = []
scarmble = [move_candidate.index(i) for i in input('scramble: ').split()]
puzzle = Cube()
for i in scarmble:
    puzzle = puzzle.move(i)
strt = time()
solver(puzzle)
print('solution:', end=' ')
for i in solution:
    print(move_candidate[i], end=' ')
print('')
print(len(solution), 'moves')
print('time:', time() - strt, 'sec')
예제 #14
0
        ]
move_ep_phase5_ud = [[] for _ in range(40320)]
with open('move/ep_phase5_ud.csv', mode='r') as f:
    for idx in range(40320):
        move_ep_phase5_ud[idx] = [
            int(i) for i in f.readline().replace('\n', '').split(',')
        ]
move_ep_phase5_fbrl = [[] for _ in range(24)]
with open('move/ep_phase5_fbrl.csv', mode='r') as f:
    for idx in range(24):
        move_ep_phase5_fbrl[idx] = [
            int(i) for i in f.readline().replace('\n', '').split(',')
        ]

# phase 0
solved = Cube()
print('phase 0 1/1')
prunning = [99 for _ in range(735471)]
solved_idx = solved.idx_ce_phase0()
prunning[solved_idx] = 0
que = deque([[solved_idx, 0, -10, -10, -10]])
cnt = 0
while que:
    cnt += 1
    if cnt % 10000 == 0:
        #tmp = prunning.count(100)
        print(cnt, len(que))
        #print(prunning[0])
    puzzle, num, l1_twist, l2_twist, l3_twist = que.popleft()
    for twist in successor[0]:
        if face(twist) == face(l1_twist) or axis(twist) == axis(