Esempio n. 1
0
        public static long getindex(Cube c, out int symtype)
        {
            int t  = c.GetCornerPermutationIndex();
            int tg = cornerSymGroup[t];
            int o  = c.GetOuterEdgePermutationIndex();
            int m  = c.GetMiddleEdgePermutationIndex();
//       Console.WriteLine("get: corner:" + t+ " outer:"+o+" middle:"+m);

            int os = int.MaxValue;
            int ms = int.MaxValue;

            symtype = -1;

            for (int s = 0; s < 4; s++)
            {
                if (symGroupMembers[tg][s] == t)
                {
                    int otmp = symOuterEdgePermutationIndex[o][s];
                    int mtmp = symMiddleEdgePermutationIndex[m][s];
                    if ((otmp < os) || (otmp == os && mtmp < ms))
                    {
                        os      = otmp;
                        ms      = mtmp;
                        symtype = s;
                    }
                }
            }

            return(tg + 10368L * (os + 40320 * (ms / 2)));
        }
Esempio n. 2
0
        private static void BuildSymmetricalIndizes()
        {
            Cube c = new Cube();

            symOuterEdgePermutationIndex = new int[40320][];
            for (int i = 0; i < symOuterEdgePermutationIndex.Length; i++)
            {
                c.SetOuterEdgePermutationFromIndex(i);
                int s0 = c.GetOuterEdgePermutationIndex();
                c.MirrorUD();
                int ud = c.GetOuterEdgePermutationIndex();
                c.MirrorLR();
                int ud_lr = c.GetOuterEdgePermutationIndex();
                c.MirrorUD();
                int lr = c.GetOuterEdgePermutationIndex();
                c.MirrorLR();
                if (i != s0 || i != c.GetOuterEdgePermutationIndex())
                {
                    Console.WriteLine("outer edge permutation mirror calcuation error");
                }
                symOuterEdgePermutationIndex[i] = new int[] { s0, ud, lr, ud_lr };
            }

            symMiddleEdgePermutationIndex = new int[24][];
            for (int i = 0; i < symMiddleEdgePermutationIndex.Length; i++)
            {
                c.SetMiddleEdgePermutationFromIndex(i);
                int s0 = c.GetMiddleEdgePermutationIndex();
                c.MirrorUD();
                int ud = c.GetMiddleEdgePermutationIndex();
                c.MirrorLR();
                int ud_lr = c.GetMiddleEdgePermutationIndex();
                c.MirrorUD();
                int lr = c.GetMiddleEdgePermutationIndex();
                c.MirrorLR();
                if (i != s0 || i != c.GetMiddleEdgePermutationIndex())
                {
                    Console.WriteLine("Middle Edge Permutation mirror calcuation error: " + i + "!=" + s0);
                }
                symMiddleEdgePermutationIndex[i] = new int[] { s0, ud, lr, ud_lr };
            }
        }
Esempio n. 3
0
        public static int Solve(Cube c, int[] histogram)
        {
            long totalcombinations = 10368L * 40320 * 12;

            FileStream file0 = new FileStream("c:/temp/phase2_0.bin", FileMode.Open, FileAccess.Read);
            FileStream file1 = new FileStream("c:/temp/phase2_1.bin", FileMode.Open, FileAccess.Read);

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

            int turns = 0;
            int time  = 0;

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

                int b;
                if (i < totalcombinations / 2)
                {
                    file0.Seek(i, SeekOrigin.Begin);
                    b = file0.ReadByte();
                }
                else
                {
                    file1.Seek(i - (totalcombinations / 2), SeekOrigin.Begin);
                    b = file1.ReadByte();
                }

                if (b <= 0)
                {
                    if (c.GetCornerPermutationIndex() != 0 || c.GetOuterEdgePermutationIndex() != 0 || c.GetMiddleEdgePermutationIndex() != 0)
                    {
                        Console.WriteLine("Phase 2 leads to unfinished cube");
                    }
                    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 + ")");

            file0.Close();
            file1.Close();

            return(time);
        }
Esempio n. 4
0
        private static void BuildSymmetricalIndizes()
        {
            Cube c = new Cube();

            symOuterEdgePermutationIndex = new int[40320][];
            for (int i = 0; i < symOuterEdgePermutationIndex.Length; i++)
            {
                c.SetOuterEdgePermutationFromIndex(i);
                int s0 = c.GetOuterEdgePermutationIndex();
                c.MirrorUD();
                int ud = c.GetOuterEdgePermutationIndex();
                c.MirrorLR();
                int ud_lr = c.GetOuterEdgePermutationIndex();
                c.MirrorUD();
                int lr = c.GetOuterEdgePermutationIndex();
                c.MirrorLR();
                if (i != s0 || i != c.GetOuterEdgePermutationIndex())
                {
                    Console.WriteLine("outer edge permutation mirror calcuation error");
                }
                symOuterEdgePermutationIndex[i] = new int[] { s0, ud, lr, ud_lr  };
            }

            symMiddleEdgePermutationIndex = new int[24][];
            for (int i = 0; i < symMiddleEdgePermutationIndex.Length; i++)
            {
                c.SetMiddleEdgePermutationFromIndex(i);
                int s0 = c.GetMiddleEdgePermutationIndex();
                c.MirrorUD();
                int ud = c.GetMiddleEdgePermutationIndex();
                c.MirrorLR();
                int ud_lr = c.GetMiddleEdgePermutationIndex();
                c.MirrorUD();
                int lr = c.GetMiddleEdgePermutationIndex();
                c.MirrorLR();
                if (i != s0 || i != c.GetMiddleEdgePermutationIndex())
                {
                    Console.WriteLine("Middle Edge Permutation mirror calcuation error: " + i + "!=" + s0);
                }
                symMiddleEdgePermutationIndex[i] = new int[] { s0, ud, lr, ud_lr };
            }
        }
Esempio n. 5
0
        public static int Solve(Cube c, int[] histogram)
        {
            long totalcombinations = 10368L * 40320 * 12;

            FileStream file0 = new FileStream("c:/temp/phase2_0.bin", FileMode.Open, FileAccess.Read);
            FileStream file1 = new FileStream("c:/temp/phase2_1.bin", FileMode.Open, FileAccess.Read);

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

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

                int b;
                if (i < totalcombinations / 2)
                {
                    file0.Seek(i, SeekOrigin.Begin);
                    b = file0.ReadByte();
                }
                else
                {
                    file1.Seek(i - (totalcombinations/2), SeekOrigin.Begin);
                    b = file1.ReadByte();
                }

                if (b <= 0)
                {
                    if (c.GetCornerPermutationIndex() != 0 || c.GetOuterEdgePermutationIndex() != 0 || c.GetMiddleEdgePermutationIndex()!=0)
                    {
                        Console.WriteLine("Phase 2 leads to unfinished cube");
                    }
                    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 + ")");

            file0.Close();
            file1.Close();

            return time;
        }
Esempio n. 6
0
        public static long getindex(Cube c, out int symtype)
        {
            int t = c.GetCornerPermutationIndex();
            int tg = cornerSymGroup[t];
            int o = c.GetOuterEdgePermutationIndex();
            int m = c.GetMiddleEdgePermutationIndex();
            //       Console.WriteLine("get: corner:" + t+ " outer:"+o+" middle:"+m);

            int os = int.MaxValue;
            int ms = int.MaxValue;
            symtype = -1;

            for (int s = 0; s < 4; s++)
            {
                if (symGroupMembers[tg][s] == t)
                {
                    int otmp = symOuterEdgePermutationIndex[o][s];
                    int mtmp = symMiddleEdgePermutationIndex[m][s];
                    if ((otmp < os) || (otmp == os && mtmp < ms))
                    {
                        os = otmp;
                        ms = mtmp;
                        symtype = s;
                    }
                }
            }

            return tg + 10368L * (os + 40320 * (ms / 2));
        }