public static void JoinTableLogFile() { long totalcombinations = 10368L * 40320 * 12; // create the move table (non-used elements are 0) HugeByteArray b = new HugeByteArray(totalcombinations); // read files where the table parts were written to Console.WriteLine("Reading phase2 parts file..."); FileStream moves = new FileStream("c:/temp/phase2.log", FileMode.Open, FileAccess.Read); // read all move parts (newer overwriting older ones) byte[] fbuffer = new byte[6]; for (; ;) { int len = moves.Read(fbuffer, 0, 6); if (len == 0) { break; } if (len != 6) { throw new IOException("Could not read exactly 6 bytes!"); } long index = ((long)fbuffer[0]) + (((long)fbuffer[1]) << 8) + (((long)fbuffer[2]) << 16) + (((long)fbuffer[3]) << 24) + (((long)fbuffer[4]) << 32); b[index] = fbuffer[5]; } moves.Close(); // write in new order to algorithm files Console.WriteLine("Start writing phase2 files..."); FileStream o = new FileStream("c:/temp/phase2_0.bin", FileMode.Create, FileAccess.Write); for (long index = 0; index < totalcombinations / 2; index++) { o.WriteByte(b[index]); } o.Close(); o = new FileStream("c:/temp/phase2_1.bin", FileMode.Create, FileAccess.Write); for (long index = totalcombinations / 2; index < totalcombinations; index++) { o.WriteByte(b[index]); } o.Close(); }
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(); }
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(); }
public static void JoinTableLogFile() { long totalcombinations = 10368L * 40320 * 12; // create the move table (non-used elements are 0) HugeByteArray b = new HugeByteArray(totalcombinations); // read files where the table parts were written to Console.WriteLine("Reading phase2 parts file..."); FileStream moves = new FileStream("c:/temp/phase2.log", FileMode.Open, FileAccess.Read); // read all move parts (newer overwriting older ones) byte[] fbuffer = new byte[6]; for (; ; ) { int len = moves.Read(fbuffer, 0, 6); if (len == 0) { break; } if (len != 6) { throw new IOException("Could not read exactly 6 bytes!"); } long index = ((long)fbuffer[0]) + (((long)fbuffer[1]) << 8) + (((long)fbuffer[2]) << 16) + (((long)fbuffer[3]) << 24) + (((long)fbuffer[4]) << 32); b[index] = fbuffer[5]; } moves.Close(); // write in new order to algorithm files Console.WriteLine("Start writing phase2 files..."); FileStream o = new FileStream("c:/temp/phase2_0.bin", FileMode.Create, FileAccess.Write); for (long index = 0; index < totalcombinations / 2; index++) { o.WriteByte(b[index]); } o.Close(); o = new FileStream("c:/temp/phase2_1.bin", FileMode.Create, FileAccess.Write); for (long index = totalcombinations / 2; index < totalcombinations; index++) { o.WriteByte(b[index]); } o.Close(); }