muodov / kociemba

A pure Python and pure C ports of Kociemba's algorithm for solving Rubik's cube
GNU General Public License v2.0
561 stars 126 forks source link

Solve cube leads to wrong answer #40

Closed ooooJayoooo closed 3 years ago

ooooJayoooo commented 3 years ago

Hello

I'm amazed by this algorithm and I'm trying to wrap my head around it.

I gave it, this as an input: UUUUUUUUURRRRRRRRRFFFFFFFFFDDDDDDDDDLLLLLLLLLBBBBBBBBB

It is supposed to be the solved state and it leads to this answer: D2 R' D' F2 B D R2 D2 R' F2 D' F2 U' B2 L2 U2 D R2 U

So how come a solved state leads to moves?

I installed the package via pip and just doing a simple script :

import kociemba cube = 'UUUUUUUUURRRRRRRRRFFFFFFFFFDDDDDDDDDLLLLLLLLLBBBBBBBBB' solve = kociemba.solve(cube) print(cube) print(solve)

i run with Python3.9.2

muodov commented 3 years ago

This is an expected behaviour. The two-phase algorithm does not guarantee an optimal solution. The resulting move sequence will still resolve to a solved cube, so technically it is correct :) In my cube solver machine this case is handled separately - just hardcode a no-op for this specific cubestring.

This is actually mentioned in the README:

NB please note that two-phase algorithm does not guarantee that the produced solution is the shortest possible. Instead, it gives you a "good enough" solution in a very short time. You can implement additional checks on top of this library, for example, to not produce any moves if the cube is already solved.
ooooJayoooo commented 3 years ago

actually i understood this, but the sequence of moves replied is not leading to a solved state. not at least from a solved state.

i applied the moves and all i got was a very scrambled cube. :)

muodov commented 3 years ago

That is strange indeed. I get the following result (Python 3.7.9):

▶ kociemba UUUUUUUUURRRRRRRRRFFFFFFFFFDDDDDDDDDLLLLLLLLLBBBBBBBBB
R L U2 R L' B2 U2 R2 F2 L2 D2 L2 F2

The tests are passing on Travis, so I assume it's something to do with your installation. Could you try to do a full reinstall of the package?

ooooJayoooo commented 3 years ago

i reinstalled and now running the version kociemba-1.2.1 and it works now. i still have an error when i put my own string but at least it works with the solved string.

ooooJayoooo commented 3 years ago

thank you