Esempio n. 1
0
        internal static void InitPermSym2Raw()
        {
            CubieCube c = new CubieCube();
            CubieCube d = new CubieCube();

            int[] occ   = new int[40320 / 32];
            int   count = 0;

            for (int i = 0; i < 40320 / 32; occ[i++] = 0)
            {
                ;
            }
            EPermR2S = new char[40320];
            for (int i = 0; i < 40320; i++)
            {
                if ((occ[i >> 5] & (1 << (i & 0x1f))) == 0)
                {
                    c.SetEPerm(i);
                    for (int s = 0; s < 16; s++)
                    {
                        EdgeConjugate(c, s, d);
                        int idx = d.GetEPerm();
                        if (idx == i)
                        {
                            SymStatePerm[count] |= (char)(1 << s);
                        }
                        occ[idx >> 5] |= 1 << (idx & 0x1f);
                        int a = d.GetU4Comb();
                        int b = d.GetD4Comb() >> 9;
                        int m = 494 - (a & 0x1ff) + (a >> 9) * 70 + b * 1680;
                        MtoEPerm[m] = EPermR2S[idx] = (char)(count << 4 | s);
                    }
                    EPermS2R[count++] = (char)i;
                }
            }
        }
Esempio n. 2
0
        private string Solve(CubieCube c)
        {
            Tools.Init();
            int conjMask = 0;

            for (int i = 0; i < 6; i++)
            {
                twist[i] = c.GetTwistSym();
                flip[i]  = c.GetFlipSym();
                slice[i] = c.GetUDSlice();
                corn0[i] = c.GetCPermSym();
                ud8e0[i] = c.GetU4Comb() << 16 | c.GetD4Comb();

                for (int j = 0; j < i; j++)
                {   //If S_i^-1 * C * S_i == C, It's unnecessary to compute it again.
                    if (twist[i] == twist[j] && flip[i] == flip[j] && slice[i] == slice[j] &&
                        corn0[i] == corn0[j] && ud8e0[i] == ud8e0[j])
                    {
                        conjMask |= 1 << i;
                        break;
                    }
                }
                if ((conjMask & (1 << i)) == 0)
                {
                    prun[i] = Math.Max(Math.Max(
                                           CoordCube.GetPruning(CoordCube.UDSliceTwistPrun,
                                                                ((int)(twist[i] >> 3)) * 495 + CoordCube.UDSliceConj[slice[i] & 0x1ff][twist[i] & 7]),
                                           CoordCube.GetPruning(CoordCube.UDSliceFlipPrun,
                                                                ((int)((uint)flip[i] >> 3)) * 495 + CoordCube.UDSliceConj[slice[i] & 0x1ff][flip[i] & 7])),
                                       Tools.USE_TWIST_FLIP_PRUN ? CoordCube.GetPruning(CoordCube.TwistFlipPrun,
                                                                                        ((int)(twist[i] >> 3)) * 2688 + (flip[i] & 0xfff8 | CubieCube.Sym8MultInv[flip[i] & 7][twist[i] & 7])) : 0);
                }
                c.URFConjugate();
                if (i == 2)
                {
                    c.InvCubieCube();
                }
            }
            for (depth1 = 0; depth1 < sol; depth1++)
            {
                maxDep2 = Math.Min(12, sol - depth1);
                for (urfIdx = 0; urfIdx < 6; urfIdx++)
                {
                    if ((firstAxisRestriction != -1 || lastAxisRestriction != -1) && urfIdx >= 3)
                    {
                        // When urfIdx >= 3, we're solving the
                        // inverse cube. This doesn't work
                        // when we're also restricting the
                        // first turn, so we just skip inverse
                        // solutions when firstAxisRestriction has
                        // been set.
                        continue;
                    }
                    if ((conjMask & (1 << urfIdx)) != 0)
                    {
                        continue;
                    }
                    corn[0] = corn0[urfIdx];
                    mid4[0] = slice[urfIdx];
                    ud8e[0] = ud8e0[urfIdx];
                    valid1  = 0;
                    int lm = firstAxisRestriction == -1 ? -1 : CubieCube.URFMoveInv[urfIdx][firstAxisRestriction] / 3 * 3;
                    if ((prun[urfIdx] <= depth1) &&
                        Phase1((int)((uint)twist[urfIdx] >> 3), twist[urfIdx] & 7, (int)((uint)flip[urfIdx] >> 3), flip[urfIdx] & 7,
                               slice[urfIdx] & 0x1ff, depth1, lm) == 0)
                    {
                        return(solution == null ? "Error 8" : solution);
                    }
                }
            }
            return(solution == null ? "Error 7" : solution);
        }