-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrossModule.py
147 lines (105 loc) · 3.39 KB
/
crossModule.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# Currently in progress
import cube_info
import cubeModule
import math
import copy
# definitions
cross_sol = []
# Checks to see if cross is solved
# note: color uses numeric value (0-5)
def findCrossEdges(color, cube_in):
pos = []
# identify location of edge pieces
for i in range(len(cube_info.edges)):
for each in cube_info.edges[i]:
if cube_in.cube[each] == color:
pos.append([each, cube_info.edges[i]])
return pos
def findSlice(position):
for i in range(4):
if edges[i].includes(position): # upper slice
return 0
for i in range(4,8):
if edges[i].includes(position): # middle slice
return 1
else:
return 2 #bottom slice
# find target location for each cross edge piece
def findCrossTargets(edg_loc, cube_in):
# locate the target of each cross edge piece in order
target = []
for each in edg_loc:
for index in cube_info.edges:
tmp_target = [cube_info.solved[index[0]], cube_info.solved[index[1]]]
tmp = [cube_in.cube[each[1][0]], cube_in.cube[each[1][1]]]
print("tmp_target", tmp_target, "tmp", tmp)
if tmp_target == tmp or tmp_target == tmp.reverse():
for both in index:
if cube_in.cube[each[0]] == cube_info.solved[both]:
target.append(both)
return target
def sameSide(position, target):
for i in range(len(cube_info.faces)):
if faces[i] in math.floor(position/9) and faces[i] in math.floor(target/9):
return true
return false
def solveEdge(position, target, cube_in):
# first, determine which slice position and target are in
pos_slice = findSlice(position)
# target slice should always be on the bottom
# first rotate target edge to front side
# case 1: edge is on same slice
if pos_Slice == 2:
print('same slice')
# see if on same side
if this.sameSide(position, target):
print('same side')
else:
# need to flip edge
print('flip edge')
elif pos_slice == 1:
# case 2: edge is on middle slice
print('middle slice')
else:
# case 3: edge is on opposite, upper slice
# first rotate upper slice until edge is above corresponding cross piece
if target == 3 or target == 5:
permutation = 'U'
while pos != target - 45:
cross_sol.append(permutation)
pos, target = updateCross(pos, target, permutation)
def updateCross(pos, target, permutation):
# create temporary cube to modify
tmp_cube = cubeModule.cube()
tmp_cube.cube[pos] = 'pos'
tmp_cube.cube[target] = 'tar'
# modify cube with given permutation
tmp_cube.perm(permutation)
# return updated pos and target
return tmp_cube.index('pos'), tmp_cube.index('tar')
def solveCross(color, cube_in_orig):
# While the cross is unsolved, check each cross edge position
# If a cross edge is in the incorrect location, solve it, then repeat
# make copy of original cube
cube_in = copy.deepcopy(cube_in_orig)
# find cross edges
edg_pos = findCrossEdges(color, cube_in)
# find corresponding targets
target = findCrossTargets(edg_pos, cube_in)
print("target",target)
edg = []
for i in range(len(edg_pos)):
edg.append(edg_pos[i][0])
print("edg", edg)
while (edg != target):
for i in range(len(edg_pos)):
if edg_pos[i][0] != target[i]:
# solve edge piece
print("solve edge")
# find new current cross edge locations
edg_pos = findCrossEdges(color, cube_in)
target = findCrossTargets(edg_pos, cube_in)
edg = []
for i in range(len(edg_pos)):
edg.append(edg_pos[i][0])
print("cross solved")