Esempio n. 1
0
        private static void BuildTwistSymGroup()
        {
            twistSymGroup   = new int[2187];
            symGroupMembers = new int[594][];
            for (int i = 0; i < twistSymGroup.Length; i++)
            {
                twistSymGroup[i] = -1;
            }
            int numGroups = 0;

            Cube c = new Cube();

            for (int i = 0; i < twistSymGroup.Length; i++)
            {
                if (twistSymGroup[i] < 0)
                {
                    c.SetCornerTwistFromIndex(i);
                    int s0 = c.GetCornerTwistIndex();
                    c.MirrorUD();
                    int ud = c.GetCornerTwistIndex();
                    c.MirrorLR();
                    int ud_lr = c.GetCornerTwistIndex();
                    c.MirrorUD();
                    int lr = c.GetCornerTwistIndex();
                    c.MirrorLR();
                    if (s0 != c.GetCornerTwistIndex() || i != s0)
                    {
                        Console.WriteLine("ERROR: symmetry action do not match original situation!");
                    }

                    int g = numGroups++;

                    if (twistSymGroup[s0] >= 0 || twistSymGroup[ud] >= 0 || twistSymGroup[lr] >= 0 || twistSymGroup[ud_lr] >= 0)
                    {
                        Console.WriteLine("ERROR: Overwriting symmetry group member");
                    }

                    twistSymGroup[s0]    = g;
                    twistSymGroup[ud]    = g;
                    twistSymGroup[lr]    = g;
                    twistSymGroup[ud_lr] = g;

                    symGroupMembers[g] = new int[] { s0, ud, lr, ud_lr };

//                    Console.Write(g + ": " + s0 + " " + ud+ " " + lr+ " " + ud_lr + "  ");
//                    if ((numGroups % 2) == 0) Console.WriteLine();
                }
            }
        }
Esempio n. 2
0
        public static int getindex(Cube c, out int symtype)
        {
            int t  = c.GetCornerTwistIndex();
            int tg = twistSymGroup[t];
            int e  = c.GetEdgeFlipIndex();
            int d  = c.GetMiddleEdgeDistributionIndex();

            int es = int.MaxValue;
            int ds = int.MaxValue;

            symtype = -1;

            for (int s = 0; s < 4; s++)
            {
                if (symGroupMembers[tg][s] == t)
                {
                    int etmp = symEdgeFlipIndex[e][s];
                    int dtmp = symMiddleEdgeDistributionIndex[d][s];
                    if ((etmp < es) || (etmp == es && dtmp < ds))
                    {
                        es      = etmp;
                        ds      = dtmp;
                        symtype = s;
                    }
                }
            }

            return(tg + 594 * (es + 2048 * ds));
        }
Esempio n. 3
0
        public static int Solve(Cube c, int[] histogram)
        {
            FileStream file = new FileStream("c:/temp/phase1.bin", FileMode.Open, FileAccess.Read);

            int m;
            int i = getindex(c, out m);

            Console.Write(i + ":" + m + " ");

            int turns = 0;
            int time  = 0;

            for (;;)
            {
                i = getindex(c, out m);
//                Console.Write("("+m+")");

                file.Seek(i, SeekOrigin.Begin);
                int b = file.ReadByte();
                if (b <= 0)
                {
                    if (c.GetCornerTwistIndex() != 0 || c.GetEdgeFlipIndex() != 0 || c.GetMiddleEdgeDistributionIndex() != 0)
                    {
                        Console.WriteLine("Phase 1 leads to unfinished cube");
                        return(-1);
                    }
                    break;  // no more moves - finish operation
                }
                int a = Cube.sym_actions[m].IndexOf((char)b);

                turns++;
                time += Cube.time_actions[a];

                histogram[a]++;

                Console.Write(Cube.sym_actions[0][a]);
                c.DoReverseAction(a);

                if (turns == 35)
                {
                    Console.WriteLine("Not finding solution...");
                }
            }
//            Console.Write("  ("+turns + "/"+time+")");
            file.Close();

            return(time);
        }
Esempio n. 4
0
        private static void BuildTwistSymGroup()
        {
            twistSymGroup = new int[2187];
            symGroupMembers = new int[594][];
            for (int i = 0; i < twistSymGroup.Length; i++)
            {
                twistSymGroup[i] = -1;
            }
            int numGroups = 0;

            Cube c = new Cube();

            for (int i=0; i<twistSymGroup.Length; i++)
            {
                if (twistSymGroup[i]<0)
                {
                    c.SetCornerTwistFromIndex(i);
                    int s0 = c.GetCornerTwistIndex();
                    c.MirrorUD();
                    int ud = c.GetCornerTwistIndex();
                    c.MirrorLR();
                    int ud_lr = c.GetCornerTwistIndex();
                    c.MirrorUD();
                    int lr = c.GetCornerTwistIndex();
                    c.MirrorLR();
                    if (s0!=c.GetCornerTwistIndex() || i!=s0)
                    {
                        Console.WriteLine("ERROR: symmetry action do not match original situation!");
                    }

                    int g = numGroups++;

                    if (twistSymGroup[s0] >= 0 || twistSymGroup[ud]>=0 || twistSymGroup[lr]>=0 || twistSymGroup[ud_lr]>= 0)
                    {
                        Console.WriteLine("ERROR: Overwriting symmetry group member");
                    }

                    twistSymGroup[s0] = g;
                    twistSymGroup[ud] = g;
                    twistSymGroup[lr] = g;
                    twistSymGroup[ud_lr] = g;

                    symGroupMembers[g] = new int[] { s0, ud, lr, ud_lr };

            //                    Console.Write(g + ": " + s0 + " " + ud+ " " + lr+ " " + ud_lr + "  ");
            //                    if ((numGroups % 2) == 0) Console.WriteLine();
                }
            }
        }
Esempio n. 5
0
        public static int Solve(Cube c, int[] histogram)
        {
            FileStream file = new FileStream("c:/temp/phase1.bin", FileMode.Open, FileAccess.Read);

            int m;
            int i = getindex(c, out m);
            Console.Write(i + ":" + m + " ");

            int turns = 0;
            int time = 0;
            for (;;)
            {
                i = getindex(c, out m);
            //                Console.Write("("+m+")");

                file.Seek(i, SeekOrigin.Begin);
                int b = file.ReadByte();
                if (b <= 0)
                {
                    if (c.GetCornerTwistIndex() != 0 || c.GetEdgeFlipIndex() != 0 || c.GetMiddleEdgeDistributionIndex()!=0)
                    {
                        Console.WriteLine("Phase 1 leads to unfinished cube");
                        return -1;
                    }
                    break;  // no more moves - finish operation
                }
                int a = Cube.sym_actions[m].IndexOf((char)b);

                turns++;
                time += Cube.time_actions[a];

                histogram[a]++;

                Console.Write(Cube.sym_actions[0][a]);
                c.DoReverseAction(a);

                if (turns==35)
                {
                    Console.WriteLine("Not finding solution...");
                }
            }
            //            Console.Write("  ("+turns + "/"+time+")");
            file.Close();

            return time;
        }
Esempio n. 6
0
        public static int getindex(Cube c, out int symtype)
        {
            int t = c.GetCornerTwistIndex();
            int tg = twistSymGroup[t];
            int e = c.GetEdgeFlipIndex();
            int d = c.GetMiddleEdgeDistributionIndex();

            int es = int.MaxValue;
            int ds = int.MaxValue;
            symtype = -1;

            for (int s=0; s<4; s++)
            {
                if (symGroupMembers[tg][s]==t)
                {
                    int etmp = symEdgeFlipIndex[e][s];
                    int dtmp = symMiddleEdgeDistributionIndex[d][s];
                    if ( (etmp < es) || (etmp==es && dtmp<ds) )
                    {
                        es = etmp;
                        ds = dtmp;
                        symtype = s;
                    }
                }
            }

            return tg + 594 * (es + 2048 * ds);
        }