Пример #1
0
        public Algo(string s)
        {
            string[] ss;
            int i, m, n;

            s = s.Trim();
            s = s.ToUpper();
            if (!checkString(s,AllowedSymbols)) throw new Exception("Invalid algorithm string"); ;
            ss = s.Split(new char[1]{' '},StringSplitOptions.RemoveEmptyEntries);
            _moves = new Move[ss.Length];
            for (i=0;i<ss.Length;i++)
            {
                if (ss[i].Length > 2)
                    throw new Exception("Invalid algorithm string");
                if (!checkString(ss[i].Substring(0, 1), AllowedSymbols.Substring(0, 6)))
                    throw new Exception("Invalid algorithm string");
                if (ss[i].Length == 2)
                {
                    if (!checkString(ss[i].Substring(1, 1), AllowedSymbols.Substring(7, 2)))
                        throw new Exception("Invalid algorithm string");
                    n = (ss[i][1] == '2') ? 1 : 2;
                }
                else n = 0;

                m = AllowedSymbols.IndexOf(ss[i][0]);
                _moves[i] = new Move((FaceId) m, (TurnDir) n);
            }
        }
Пример #2
0
        /*public Algo SuperSolver ()
        {
            int i, j, k, startPrune;
            Move a = new Move();
            Algo solution = new Algo();

            k = 0;
            startPrune = table.TwistFlipPruneTable[c.Twist * CubeTable.FLIP + c.Flip];
            for (i=0;i<startPrune;i++)
            {
                for (j = 0; j < 6; j++)
                {
                    a = new Move((FaceId) j, 0);
                    for (k = 0; k < 4; k++)
                    {
                        c.Rotate(a);
                        if (startPrune-i > table.TwistFlipPruneTable[c.Twist*CubeTable.FLIP+c.Flip])
                            goto metka;
                    }
                }
                metka:
                a.Dir = (TurnDir) k;
                solution = solution + new Algo(a.ToString());
            }

            return solution;
        }*/
        public Algo SuperSolver()
        {
            int i, j, k, startPrune;
            Move a = new Move();
            Algo solution = new Algo();

            k = 0;
            startPrune = getPrune(c.Twist, c.Flip, c.Slice/24);
            for (i = 0; i < startPrune; i++)
            {
                for (j = 0; j < 6; j++)
                {
                    a = new Move((FaceId)j, 0);
                    if (solution.Length > 0 && (a.Face == solution[solution.Length - 1].Face || ((int)a.Face % 2 == 0 && a.Face + 1 == solution[solution.Length - 1].Face) || ((int)a.Face % 2 == 1 && a.Face - 1 == solution[solution.Length - 1].Face)))
                        continue;
                    for (k = 0; k < 3; k++)
                    {
                        c.Rotate(a);
                        if (startPrune - i > getPrune(c.Twist, c.Flip, c.Slice/24))
                            goto metka;
                    }
                    c.Rotate(a);
                }
                if (j == 6)
                {
                    i--;
                    startPrune++;
                    continue;
                }
                metka:
                a.Dir = (TurnDir)k;
                solution = solution + new Algo(a.ToString());
            }

            return solution;
        }
Пример #3
0
        public static Algo operator +(Algo a, Algo b)
        {
            Algo c;
            Move m = null;
            int i, j, k;

            for (i=a.Length-1,j=0;i>=0&&j<b.Length;)
            {
                if (a[i].Face != b[j].Face)
                    break;
                if ((int)(a[i].Dir) + (int)(b[j].Dir) == 2)
                {
                    i--;
                    j++;
                    continue;
                }
                if (a[i].Dir == b[j].Dir)
                    m = new Move(a[i].Face,TurnDir.DOUBLE);
                else if ((int)(a[i].Dir) + (int)(b[j].Dir) == 1)
                    m = new Move(a[i].Face, TurnDir.CCW);
                else m = new Move(a[i].Face, TurnDir.CW);
                i--;
                j++;
                break;
            }
            c = new Algo(i+1+b.Length-j+((m == null)?(0):(1)));
            for (k = 0; k <= i; k++)
                c[k] = new Move(a[k].Face, a[k].Dir);
            if (m != null)
            {
                c[k] = m;
                k++;
            }
            for (; j < b.Length; k++, j++)
                c[k] = new Move(b[j].Face, b[j].Dir);

            return c;
        }
Пример #4
0
        void fillRL(int n)
        {
            int i;

            for (i=n;i<Length;i++)
                _moves[i] = new Move((FaceId) ((i-n)%2), TurnDir.CW);
        }
Пример #5
0
 public void Rotate(Move a)
 {
     switch (a.Face)
     {
         case FaceId.R:
             R(a.Dir);break;
         case FaceId.L:
             L(a.Dir); break;
         case FaceId.U:
             U(a.Dir); break;
         case FaceId.D:
             D(a.Dir); break;
         case FaceId.F:
             F(a.Dir); break;
         case FaceId.B:
             B(a.Dir); break;
     }
 }