コード例 #1
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);
        }
コード例 #2
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;
        }
コード例 #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);
        }
コード例 #4
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;
        }