pglass / cube

Python Rubik's cube solver
MIT License
155 stars 52 forks source link

Solver Moves #6

Closed Nico-Mayer closed 1 year ago

Nico-Mayer commented 1 year ago

First and foremost, great job! I have a question about the solver. I might be missing something here, or I could be using it incorrectly. In the example below, I input an already solved cube. My confusion is why the solver is generating a solving sequence for a cube that's already solved. Shouldn't the solver's "moves" array be empty in such a case?

Code:

c = Cube("OOOOOOOOOYYYWWWGGGBBBYYYWWWGGGBBBYYYWWWGGGBBBRRRRRRRRR")
print(c)
print(c.is_solved())
solver = Solver(c)
solver.solve()
print(solver.moves)

Output:

    OOO
    OOO
    OOO
YYY WWW GGG BBB
YYY WWW GGG BBB
YYY WWW GGG BBB
    RRR
    RRR
    RRR

True

['Z', 'Zi', 'D', 'B', 'Di', 'B', 'B', 'B', 'B', 'D', 'Bi', 'Di', 'Z', 'D', 'B', 'Di', 'B', 'B', 'B', 'B', 'D', 'Bi', 'Di', 'Z', 'D', 'B', 'Di', 'B', 'B', 'B', 'B', 'D', 'Bi', 'Di', 'Z', 'D', 'B', 'Di', 'B', 'B', 'B', 'B', 'D', 'Bi', 'Di', 'Z', 'B', 'L', 'Bi', 'Li', 'Bi', 'Di', 'B', 'D', 'B', 'Bi', 'Di', 'B', 'D', 'B', 'L', 'Bi', 'Li', 'Z', 'B', 'L', 'Bi', 'Li', 'Bi', 'Di', 'B', 'D', 'B', 'Bi', 'Di', 'B', 'D', 'B', 'L', 'Bi', 'Li', 'Z', 'B', 'L', 'Bi', 'Li', 'Bi', 'Di', 'B', 'D', 'B', 'Bi', 'Di', 'B', 'D', 'B', 'L', 'Bi', 'Li', 'Z', 'B', 'L', 'Bi', 'Li', 'Bi', 'Di', 'B', 'D', 'B', 'Bi', 'Di', 'B', 'D', 'B', 'L', 'Bi', 'Li', 'Z', 'X', 'X', 'D', 'F', 'R', 'Fi', 'Ri', 'Di', 'Xi', 'Xi', 'X', 'X', 'Zi', 'Li', 'Fi', 'L', 'D', 'F', 'Di', 'Li', 'F', 'L', 'F', 'F', 'Z', 'F', 'Li', 'Fi', 'L', 'D', 'F', 'Di', 'Li', 'F', 'L', 'F', 'Li', 'Fi', 'L', 'D', 'F', 'Di', 'Li', 'F', 'L', 'F', 'F', 'F', 'Li', 'Fi', 'L', 'D', 'F', 'Di', 'Li', 'F', 'L', 'F', 'Xi', 'Xi', 'X', 'X', 'F', 'F', 'R', 'F', 'Ri', 'F', 'R', 'F', 'F', 'Ri', 'F', 'F', 'Ri', 'Fi', 'R', 'Fi', 'Ri', 'F', 'F', 'R', 'F', 'F', 'F', 'F', 'Xi', 'Xi', 'X', 'X', 'Z', 'Z', 'Z', 'Z', 'Z', 'Z', 'R', 'R', 'F', 'D', 'Ui', 'R', 'R', 'Di', 'U', 'F', 'R', 'R', 'Z', 'Z', 'Z', 'Z', 'R', 'R', 'F', 'D', 'Ui', 'R', 'R', 'Di', 'U', 'F', 'R', 'R', 'Z', 'Di', 'Li', 'Ri', 'S', 'Ri', 'Ri', 'S', 'S', 'Ri', 'Fi', 'Fi', 'R', 'Si', 'Si', 'Ri', 'Ri', 'Si', 'R', 'Fi', 'Fi', 'L', 'D']
pglass commented 1 year ago

You are using it correctly!

It still outputs a list of moves for an already-solved cube because the solver is not that smart. It simply follows an algorithm that produces a solved cube, regardless of the initial state. It also doesn't attempt to produce a minimal/optimal solution. This means its solution sequences are quite long. While I originally planned to implement a better solver, I never got around to it and there are other libraries which produce much shorter and/or optimal solutions anyway.