-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.py
74 lines (57 loc) · 1.65 KB
/
helper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import cv2
import kociemba
import numpy as np
from constants import CELL_LEN, COLORS, FACE_LEN, INPUT_MAP
def classify_color(img, face_num, idx):
h, s, v = img
# print(h, s, v)
if idx == 4:
items = list(COLORS.items())
return items[face_num][0]
else:
if s < 100:
return "WHITE"
elif h < 15:
return "ORANGE"
elif h < 45:
return "YELLOW"
elif h < 72:
return "GREEN"
elif h < 120:
return "BLUE"
elif h > 150:
return "RED"
else:
return "BLACK"
def draw_cube_face(color_dict):
arr = np.zeros((FACE_LEN, FACE_LEN, 3), dtype=int)
for i in range(3):
row = np.zeros((CELL_LEN, FACE_LEN, 3), dtype=int)
x = CELL_LEN * i
for j in range(3):
y = CELL_LEN * j
color = color_dict[3 * i + j]
row[:, y:y+CELL_LEN, :] = COLORS[color]
arr[x:x+CELL_LEN, :, :] = row
# drawing borders
arr[0] = COLORS['BLACK']
arr[-1] = COLORS['BLACK']
arr[:, 0, :] = COLORS['BLACK']
arr[:, -1, :] = COLORS['BLACK']
arr[CELL_LEN, :, :] = COLORS['BLACK']
arr[2*CELL_LEN, :, :] = COLORS['BLACK']
arr[:, CELL_LEN, :] = COLORS['BLACK']
arr[:, 2*CELL_LEN, :] = COLORS['BLACK']
return arr[:, :, ::-1]
def prepare_cube_state(face_dict):
order = [4, 1, 0, 5, 3, 2]
state = ''
for f in order:
face = face_dict[f]
for i in range(9):
state += INPUT_MAP[face[i]]
# print(state)
return state
def get_solution(state):
soln = kociemba.solve(state)
return soln