Skip to content

Commit e5ab099

Browse files
Adding CFOP solver
1 parent 39ade36 commit e5ab099

File tree

3 files changed

+550
-1
lines changed

3 files changed

+550
-1
lines changed

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ Python 3 implementation of a (3x3x3) Rubik's Cube utility.
66

77
## TODO (Open to contributions)
88

9+
- [ ] CFOP is not Optimal, need to reimplement F2L and refactor PLL
910
- [ ] Refactor `Cube` class to be more easy to understand
1011
- [ ] Replace VisualCube with a custom implementation of a 3D cube visualization
11-
- [ ] Optimize the `Solver` classes
1212
- [ ] Add more solvers
1313
- [ ] Add support for other cube sizes (2x2x2, 4x4x4, 5x5x5, etc.)
1414
- [ ] Add support for other cube types (Pyraminx, Megaminx, etc.)
@@ -69,6 +69,17 @@ solver.solve()
6969
print(solver.moves)
7070
```
7171

72+
Or using the Fridrich(CFOP) method:
73+
74+
```python
75+
from solvers.CFOP import CfopSolver
76+
77+
solver = CfopSolver(cube)
78+
solver.solve()
79+
80+
print(solver.moves)
81+
```
82+
7283
Optimize the sequence of moves:
7384

7485
```python

cube.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
'B': 'G'
3333
}
3434

35+
FACES_COLORS_INV = {v: k for k, v in FACES_COLORS.items()}
36+
3537
FACES_CODES = {
3638
'U': 0,
3739
'R': 1,
@@ -201,6 +203,13 @@ def get_face_piece_color(self, face, piece, error=True):
201203

202204
return FACES_COLORS[CORNERS_CODES_INV[self.cube['corners'][piece]][piece_idx]]
203205

206+
def normalize_rotations(self):
207+
for piece in self.cube['corners_rotations']:
208+
self.cube['corners_rotations'][piece] = self.cube['corners_rotations'][piece] % 3
209+
210+
for piece in self.cube['edges_rotations']:
211+
self.cube['edges_rotations'][piece] = self.cube['edges_rotations'][piece] % 2
212+
204213
def get_relative_piece_color(self, face, piece):
205214
# piece = self.get_piece(piece)
206215

@@ -222,6 +231,21 @@ def search_piece(self, piece):
222231
if self.get_piece(corner) == piece:
223232
return corner
224233

234+
def search_piece_rotation(self, piece):
235+
piece = self.get_relative_piece_position(piece)
236+
237+
if len(piece) == 1:
238+
return 0
239+
elif len(piece) == 2:
240+
return self.cube['edges_rotations'][piece]
241+
elif len(piece) == 3:
242+
return self.cube['corners_rotations'][piece]
243+
244+
def get_face_of_color(self, color, piece):
245+
for face in piece:
246+
if self.get_face_piece_color(face, piece) == color:
247+
return face
248+
225249
def pprint(self):
226250
face = 'B'
227251
for piece_idx, piece in enumerate([

0 commit comments

Comments
 (0)