Example #1
0
        private static void BuildCornerSymGroup()
        {
            cornerSymGroup  = new int[40320];
            symGroupMembers = new int[10368][];
            for (int i = 0; i < cornerSymGroup.Length; i++)
            {
                cornerSymGroup[i] = -1;
            }
            int numGroups = 0;

            Cube c = new Cube();

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

                    int g = numGroups++;

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

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

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

//                        Console.Write(g + ": " + s0 + " " + ud + " " + lr + " " + ud_lr + "  ");
//                        Console.WriteLine();
                }
            }
        }
Example #2
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)));
        }
Example #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);
        }
Example #4
0
        private static void BuildCornerSymGroup()
        {
            cornerSymGroup = new int[40320];
            symGroupMembers = new int[10368][];
            for (int i = 0; i < cornerSymGroup.Length; i++)
            {
                cornerSymGroup[i] = -1;
            }
            int numGroups = 0;

            Cube c = new Cube();

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

                    int g = numGroups++;

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

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

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

            //                        Console.Write(g + ": " + s0 + " " + ud + " " + lr + " " + ud_lr + "  ");
            //                        Console.WriteLine();
                }
            }
        }
Example #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;
        }
Example #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));
        }