Implement Rubik's Cube Thistlethwaite algorithm phase 3

28 Views Asked by At

I'm trying to implement a C++ Rubik's Cube solver using Thistlethwaite's algorithm and a pattern database. I want to store all possible cube configurations for each group described by the algorithm, along with the moves that brought the solved cube to that state.

I have already implemented phase 1, 2 and 4. For each phase, I create a file containing a unique id representing each cube configuration and its moves.

Now, I am stuck at phase 3. I need to implement a function that creates a unique id to describe each cube state of phase 3. I understand there are (8C42 ·2·3) = 29,400 unique ids that can be generated. However, in my case, 175,420 unique ids are generated with my BFS.

I think my function is taking into account some aspects of phase 3, but not exactly what is required. Here is what I am using to generate the unique id so far:

int64_t Solver::idPhase3(Cube c){
    string faces = "FRUBLD";

    int64_t id = 0; 
    for (int i = 0; i < 7; i++){
        for (int j = 0; j < 3; j++){
            id <<= 1;
            char t = c.cornerNames[c.cPos[i]][(c.cOri[i] + j) % 3];
            if (!(t == c.cornerNames[i][j] ||
                t == faces[(faces.find(c.cornerNames[i][j]) + 3) % 6])){
                id++;
            }
        }           
    }
    for (int i = 0; i < 11; i++){
        for (int j = 0; j < 2; j++){
            id <<= 1;
            char t = c.edgeNames[c.ePos[i]][(c.eOri[i] + j) % 2];
            if (!(t == c.edgeNames[i][j] ||
                t == faces[(faces.find(c.edgeNames[i][j]) + 3) % 6])){
                id++;
            }
        }           
    }
    for (int i = 0; i < 8; i++)
    {
        id <<= 1;
        if (c.cPos[i] % 4 != i % 4)
            id++;
    }
    id <<= 1;
    for (int i = 0; i < 8; i++ )
        for( int j = i + 1; j < 8; j++ )
    id ^= c.cPos[i] > c.cPos[j];
    return id;
}

Here is what I try to represent with this function:

  • Whether the orientation of the corners is good.
  • Whether the middle layer edges are into their slice.
  • Whether the parity of the edge permutation (and hence the corners too) is made even.
  • Whether the total twist of each tetrad is fixed.

However, it doesn't seem to work and reach group 3. This is a real problem because when I solve the cube using my pattern database, phase 4 sometimes generate an id that is not found in the phase 4 pattern database file.

I think this is due to the fact that phase 3 gives moves that do not allow access to group G3=<L2,R2,F2,B2,U2,D2>, which is required for phase 4.

Here is the whole project. I actually work with a copied version of it for testing purpose.

0

There are 0 best solutions below