|
1 | | - |
| 1 | + |
2 | 2 |
|
3 | | -# Rubik's Cube Solver |
| 3 | +# Rubik Sim |
4 | 4 |
|
5 | | -This project displays a Rubik's cube solver created with genetic algorithms. |
| 5 | +This project allows to simulate a 3x3 Rubik's cube and perform operations over it. |
6 | 6 |
|
7 | | -## 📖 Documentation |
8 | | - |
9 | | -Documentation will be added once the project advances. |
10 | | -Feel free to look for the latest updates within the 'develop' branch. |
11 | | - |
12 | | -## 🐍 Python Setup |
| 7 | +## ⚙️ Setup |
13 | 8 |
|
14 | 9 | **Requirements** |
15 | 10 |
|
16 | | -- Python 3.8 or higher |
| 11 | +- Python 3.9 or higher |
17 | 12 |
|
18 | 13 | **Installation** |
19 | 14 |
|
20 | | -The package is not released in PyPI. Thus, there are multiple options to run the code: |
| 15 | +The package is installable via pip: |
21 | 16 |
|
22 | | -1. Install via pip + git |
23 | 17 | ````shell |
24 | | -pip install git+https://github.com/Jtachan/genetic_rubiks_solver.git |
| 18 | +pip install rubik-sim |
25 | 19 | ```` |
26 | 20 |
|
27 | | -2. Clone the repo, then install locally |
| 21 | +Alternatively, the 'develop' branch can be installed for the latest changes |
28 | 22 | ```shell |
29 | | -git clone https://github.com/Jtachan/genetic_rubiks_solver.git |
30 | | -pip install . |
| 23 | +pip install git+https://github.com/Jtachan/genetic_rubiks_solver.git@develop |
| 24 | +``` |
| 25 | + |
| 26 | +## 🏃 Usage |
| 27 | + |
| 28 | +#### Initializing the cube |
| 29 | + |
| 30 | +The package allows importing all the classes directly from the module. |
| 31 | + |
| 32 | +To initialize the cube, it is only needed the `RubiksCube` class. |
| 33 | +This generates a fully solved cube. To obtain a random state using `scramble()` |
| 34 | + |
| 35 | +````python |
| 36 | +from rubik_sim import RubiksCube |
| 37 | + |
| 38 | +my_cube = RubiksCube() # Solved cube |
| 39 | +my_cube.scramble() # Updates the cube by 25 random moves |
| 40 | +```` |
| 41 | + |
| 42 | +The number of moves to scramble the cube can also be specified as a parameter: |
| 43 | +<br/>`RubiksCube.scramble(nof_moves: int = 25)` |
| 44 | + |
| 45 | +It is also possible to initialize any cube from a string of characters defining the color of each tile. |
| 46 | + |
| 47 | +````python |
| 48 | +my_cube = RubiksCube.from_color_code( |
| 49 | + 'BBBBBBBBBGGGGGGGGGOOOOOOOOOYYYYYYYYYRRRRRRRRRWWWWWWWWW' |
| 50 | +) |
| 51 | +```` |
| 52 | + |
| 53 | +The only supported colors are green ('G'), orange ('O'), yellow ('Y'), red ('R'), white ('W') and blue ('B'). |
| 54 | + |
| 55 | +#### Representation |
| 56 | + |
| 57 | +The cube's state can be represented by calling `print()` |
| 58 | + |
| 59 | +```pycon |
| 60 | +>>> print(my_cube) |
| 61 | + ['B' 'B' 'B'] |
| 62 | + ['B' 'B' 'B'] |
| 63 | + ['B' 'B' 'B'] |
| 64 | +['G' 'G' 'G']['O' 'O' 'O']['Y' 'Y' 'Y']['R' 'R' 'R'] |
| 65 | +['G' 'G' 'G']['O' 'O' 'O']['Y' 'Y' 'Y']['R' 'R' 'R'] |
| 66 | +['G' 'G' 'G']['O' 'O' 'O']['Y' 'Y' 'Y']['R' 'R' 'R'] |
| 67 | + ['W' 'W' 'W'] |
| 68 | + ['W' 'W' 'W'] |
| 69 | + ['W' 'W' 'W'] |
31 | 70 | ``` |
| 71 | + |
| 72 | +From the representation, the faces are: |
| 73 | + |
| 74 | +- Blue = Top (up) face |
| 75 | +- Green = Left face |
| 76 | +- Orange = Front face |
| 77 | +- Yellow = Right face |
| 78 | +- Red = Back face |
| 79 | +- White = Bottom (down) face |
| 80 | + |
| 81 | +#### Rotating the cube |
| 82 | + |
| 83 | +`RubiksCube.perform_operations(operations: Sequence[NOTATION_MOVES])` |
| 84 | + |
| 85 | +This method updates the current state of the cube by performing operations over it. |
| 86 | +The supported operations are: |
| 87 | +> U, U', U2, D, D', D2, R, R', R2, L, L', L2, F, F', F2, B, B', B2, |
| 88 | +> M, M', M2, E, E', E2, S, S' and S2. |
| 89 | + |
| 90 | +These are the general notations for the possible moves on the cube. |
| 91 | +More about the Rubik's cube notation: https://ruwix.com/the-rubiks-cube/notation/ |
| 92 | + |
| 93 | +Any missing notation can be performed with the current notations. |
0 commit comments