Esempio n. 1
0
        public static void CreateTables()
        {
            int totalcombinations = 594 * 2048 * 495;

            // create files to write table to
            byte[] zeroes = new byte[594 * 495];
            FileStream moves = new FileStream("c:/temp/phase1.bin", FileMode.Create, FileAccess.ReadWrite);
            for (int i = 0; i < 2048; i++)
            {
                moves.Write(zeroes, 0, zeroes.Length);
            }

            Cube c = new Cube();

            // initialize to not reached
            byte[] steps = new byte[totalcombinations];
            for (int index=0; index<steps.Length; index++)
            {
                steps[index] = 255;
            }

            // create the root situation for this phase
            int dummym;
            steps[getindex(c, out dummym)] = 0;

            // iteratively add newly reachable situations
            for (int distance=0; distance<250; distance++)
            {
                int currentsituations = 0;
                int foundnew = 0;
                int foundfaster = 0;

                long start = DateTime.Now.Ticks / 10000;  // ms

                for (int index = 0; index < totalcombinations; index++)
                {
                    // consider only situations with current distance to get next situations
                    if (steps[index] == distance)
                    {
                        currentsituations++;    // count situtaions with this distance

                        setcube(c, index);
                        for (int a= 1; a <= Cube.B3D3; a++)
                        {
                            c.DoIncrementalAction(a);

                            int mir;
                            int ni = getindex(c, out mir);

                            int newdistance = distance+Cube.time_actions[a];
                            if (newdistance < steps[ni])       // found a faster route
                            {
                                if (steps[ni]==255)
                                {   foundnew++;
                                }
                                else
                                {   foundfaster++;
                                }
                                // memorize shorter distance
                                steps[ni] = (byte) newdistance;

                                // write to file
                                moves.Seek(ni, SeekOrigin.Begin);
                                moves.WriteByte((byte) (Cube.sym_actions[mir][a]));
                            }
                        }
                    }
                }

                long end = DateTime.Now.Ticks / 10000;  // ms
                Console.WriteLine(distance+": Situations: "+currentsituations+" New: " + foundnew+" Improved: "+foundfaster+"  ("+(end-start)+" ms)");
            }

            // finish writing
            moves.Close();
        }
Esempio n. 2
0
        public static void CreateTables()
        {
            int totalcombinations = 594 * 2048 * 495;

            // create files to write table to
            byte[]     zeroes = new byte[594 * 495];
            FileStream moves  = new FileStream("c:/temp/phase1.bin", FileMode.Create, FileAccess.ReadWrite);

            for (int i = 0; i < 2048; i++)
            {
                moves.Write(zeroes, 0, zeroes.Length);
            }

            Cube c = new Cube();

            // initialize to not reached
            byte[] steps = new byte[totalcombinations];
            for (int index = 0; index < steps.Length; index++)
            {
                steps[index] = 255;
            }

            // create the root situation for this phase
            int dummym;

            steps[getindex(c, out dummym)] = 0;

            // iteratively add newly reachable situations
            for (int distance = 0; distance < 250; distance++)
            {
                int currentsituations = 0;
                int foundnew          = 0;
                int foundfaster       = 0;

                long start = DateTime.Now.Ticks / 10000;  // ms

                for (int index = 0; index < totalcombinations; index++)
                {
                    // consider only situations with current distance to get next situations
                    if (steps[index] == distance)
                    {
                        currentsituations++;    // count situtaions with this distance

                        setcube(c, index);
                        for (int a = 1; a <= Cube.B3D3; a++)
                        {
                            c.DoIncrementalAction(a);

                            int mir;
                            int ni = getindex(c, out mir);

                            int newdistance = distance + Cube.time_actions[a];
                            if (newdistance < steps[ni])       // found a faster route
                            {
                                if (steps[ni] == 255)
                                {
                                    foundnew++;
                                }
                                else
                                {
                                    foundfaster++;
                                }
                                // memorize shorter distance
                                steps[ni] = (byte)newdistance;

                                // write to file
                                moves.Seek(ni, SeekOrigin.Begin);
                                moves.WriteByte((byte)(Cube.sym_actions[mir][a]));
                            }
                        }
                    }
                }

                long end = DateTime.Now.Ticks / 10000;  // ms
                Console.WriteLine(distance + ": Situations: " + currentsituations + " New: " + foundnew + " Improved: " + foundfaster + "  (" + (end - start) + " ms)");
            }

            // finish writing
            moves.Close();
        }
Esempio n. 3
0
        public static void CreateTables()
        {
            long totalcombinations = 10368L * 40320 * 12;

            // create files to write table parts to
            FileStream moves = new FileStream("c:/temp/phase2.log", FileMode.Create, FileAccess.Write);

            byte[] fbuffer = new byte[6];

            // initialize to not reached
            HugeByteArray steps = new HugeByteArray(totalcombinations);

            for (long index = 0; index < totalcombinations; index++)
            {
                steps[index] = 255;
            }

            // create the root situation for this phase
            Cube c = new Cube();

            int dummym;

            steps[getindex(c, out dummym)] = 0;

            Console.WriteLine("Start computing reachable positions...");

            // iteratively add newly reachable situations
            for (int distance = 0; distance < 250; distance++)
            {
                int currentsituations = 0;
                int foundnew          = 0;
                int foundfaster       = 0;

                long start = DateTime.Now.Ticks / 10000;  // ms

                for (long index = 0; index < totalcombinations; index++)
                {
                    // consider only situations with current distance to get next situations
                    if (steps[index] == distance)
                    {
                        currentsituations++;    // count situations with this distance

                        setcube(c, index);
                        for (int a = 1; a <= Cube.B3D3; a++)
                        {
                            c.DoIncrementalAction(a);

                            // disallow moves that would bring cube out of S1
                            if (!Cube.s1_actions[a])
                            {
                                continue;
                            }

                            int  mir;
                            long ni = getindex(c, out mir);

                            int newdistance = distance + Cube.time_actions[a];
                            if (newdistance < steps[ni])       // found a faster route
                            {
                                if (steps[ni] == 255)
                                {
                                    foundnew++;
                                }
                                else
                                {
                                    foundfaster++;
                                }
                                // memorize shorter distance
                                steps[ni] = (byte)newdistance;

                                // write to spool file (position: 5 byte, move: 1 byte)
                                fbuffer[0] = (byte)(ni & 0xff);
                                fbuffer[1] = (byte)((ni >> 8) & 0xff);
                                fbuffer[2] = (byte)((ni >> 16) & 0xff);
                                fbuffer[3] = (byte)((ni >> 24) & 0xff);
                                fbuffer[4] = (byte)((ni >> 32) & 0xff);
                                fbuffer[5] = (byte)(Cube.sym_actions[mir][a]);
                                moves.Write(fbuffer, 0, 6);
                            }
                        }
                    }
                }

                long end = DateTime.Now.Ticks / 10000;  // ms
                Console.WriteLine(distance + ": Situations: " + currentsituations + " New: " + foundnew + " Improved: " + foundfaster + "  (" + (end - start) + " ms)");
            }

            // finish writing
            moves.Close();
        }
Esempio n. 4
0
        public static void CreateTables()
        {
            long totalcombinations = 10368L * 40320 * 12;

            // create files to write table parts to
            FileStream moves = new FileStream("c:/temp/phase2.log", FileMode.Create, FileAccess.Write);
            byte[] fbuffer = new byte[6];

            // initialize to not reached
            HugeByteArray steps = new HugeByteArray(totalcombinations);
            for (long index = 0; index < totalcombinations; index++)
            {
                steps[index] = 255;
            }

            // create the root situation for this phase
            Cube c = new Cube();

            int dummym;
            steps[getindex(c, out dummym)] = 0;

            Console.WriteLine("Start computing reachable positions...");

            // iteratively add newly reachable situations
            for (int distance = 0; distance < 250; distance++)
            {
                int currentsituations = 0;
                int foundnew = 0;
                int foundfaster = 0;

                long start = DateTime.Now.Ticks / 10000;  // ms

                for (long index = 0; index < totalcombinations; index++)
                {
                    // consider only situations with current distance to get next situations
                    if (steps[index] == distance)
                    {
                        currentsituations++;    // count situations with this distance

                        setcube(c, index);
                        for (int a = 1; a <= Cube.B3D3; a++)
                        {
                            c.DoIncrementalAction(a);

                            // disallow moves that would bring cube out of S1
                            if (!Cube.s1_actions[a])
                            {
                                continue;
                            }

                            int mir;
                            long ni = getindex(c, out mir);

                            int newdistance = distance + Cube.time_actions[a];
                            if (newdistance < steps[ni])       // found a faster route
                            {
                                if (steps[ni] == 255)
                                {
                                    foundnew++;
                                }
                                else
                                {
                                    foundfaster++;
                                }
                                // memorize shorter distance
                                steps[ni] = (byte)newdistance;

                                // write to spool file (position: 5 byte, move: 1 byte)
                                fbuffer[0] = (byte)(ni & 0xff);
                                fbuffer[1] = (byte)((ni >> 8) & 0xff);
                                fbuffer[2] = (byte)((ni >> 16) & 0xff);
                                fbuffer[3] = (byte)((ni >> 24) & 0xff);
                                fbuffer[4] = (byte)((ni >> 32) & 0xff);
                                fbuffer[5] = (byte)(Cube.sym_actions[mir][a]);
                                moves.Write(fbuffer, 0, 6);
                            }
                        }
                    }
                }

                long end = DateTime.Now.Ticks / 10000;  // ms
                Console.WriteLine(distance + ": Situations: " + currentsituations + " New: " + foundnew + " Improved: " + foundfaster + "  (" + (end - start) + " ms)");
            }

            // finish writing
            moves.Close();
        }