Exemplo n.º 1
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));
        }
Exemplo n.º 2
0
        private static void BuildSymmetricalIndizes()
        {
            Cube c = new Cube();

            symEdgeFlipIndex = new int[2048][];
            for (int i = 0; i < symEdgeFlipIndex.Length; i++)
            {
                c.SetEdgeFlipFromIndex(i);
                int s0 = c.GetEdgeFlipIndex();
                c.MirrorUD();
                int ud = c.GetEdgeFlipIndex();
                c.MirrorLR();
                int ud_lr = c.GetEdgeFlipIndex();
                c.MirrorUD();
                int lr = c.GetEdgeFlipIndex();
                c.MirrorLR();
                if (i != s0 || i != c.GetEdgeFlipIndex())
                {
                    Console.WriteLine("Edge flip mirror calcuation error");
                }
                symEdgeFlipIndex[i] = new int[] { s0, ud, lr, ud_lr };
            }

            symMiddleEdgeDistributionIndex = new int[495][];
            for (int i = 0; i < symMiddleEdgeDistributionIndex.Length; i++)
            {
                c.SetMiddleEdgeDistributionFromIndex(i);
                int s0 = c.GetMiddleEdgeDistributionIndex();
                c.MirrorUD();
                int ud = c.GetMiddleEdgeDistributionIndex();
                c.MirrorLR();
                int ud_lr = c.GetMiddleEdgeDistributionIndex();
                c.MirrorUD();
                int lr = c.GetMiddleEdgeDistributionIndex();
                c.MirrorLR();
                if (i != s0 || i != c.GetMiddleEdgeDistributionIndex())
                {
                    Console.WriteLine("Middle Edge Distribution mirror calcuation error: " + i + "!=" + s0);
                }
                symMiddleEdgeDistributionIndex[i] = new int[] { s0, ud, lr, ud_lr };
            }
        }
Exemplo 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);
        }
Exemplo n.º 4
0
        private static void BuildSymmetricalIndizes()
        {
            Cube c = new Cube();

            symEdgeFlipIndex = new int[2048][];
            for (int i = 0; i < symEdgeFlipIndex.Length; i++)
            {
                c.SetEdgeFlipFromIndex(i);
                int s0 = c.GetEdgeFlipIndex();
                c.MirrorUD();
                int ud = c.GetEdgeFlipIndex();
                c.MirrorLR();
                int ud_lr = c.GetEdgeFlipIndex();
                c.MirrorUD();
                int lr = c.GetEdgeFlipIndex();
                c.MirrorLR();
                if (i != s0 || i!=c.GetEdgeFlipIndex())
                {
                    Console.WriteLine("Edge flip mirror calcuation error");
                }
                symEdgeFlipIndex[i] = new int[] { s0, ud, lr, ud_lr };
            }

            symMiddleEdgeDistributionIndex = new int[495][];
            for (int i = 0; i < symMiddleEdgeDistributionIndex.Length; i++)
            {
                c.SetMiddleEdgeDistributionFromIndex(i);
                int s0 = c.GetMiddleEdgeDistributionIndex();
                c.MirrorUD();
                int ud = c.GetMiddleEdgeDistributionIndex();
                c.MirrorLR();
                int ud_lr = c.GetMiddleEdgeDistributionIndex();
                c.MirrorUD();
                int lr = c.GetMiddleEdgeDistributionIndex();
                c.MirrorLR();
                if (i != s0 || i != c.GetMiddleEdgeDistributionIndex())
                {
                    Console.WriteLine("Middle Edge Distribution mirror calcuation error: "+i+"!="+s0);
                }
                symMiddleEdgeDistributionIndex[i] = new int[] { s0, ud, lr, ud_lr };
            }
        }
Exemplo 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;
        }
Exemplo 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);
        }