public Cube(Cube other) { corners = other.corners.Select(x => new Cubie(x.pos, x.orient)).ToArray(); edges = other.edges.Select(x => new Cubie(x.pos, x.orient)).ToArray(); }
public static List <string> fullSolve(Cube cube, int maxDepth, int timeoutMS = 6000, bool printInfo = false) { if (!printInfo) { Tools.ColorPrint( string.Format("SOLVER START, MAX DEPTH {0}, TIME ALLOWED {1}MS\n\n", maxDepth, timeoutMS), ConsoleColor.Cyan ); } if (cube.isSolved()) { if (!printInfo) { Tools.ColorPrint("CUBE ALREADY SOLVED... MAKE IT HARDER NEXT TIME\n", ConsoleColor.Cyan); } return(new List <string>()); } ax[0] = 0; po[0] = 0; flip[0] = cube.edgeOrientCoord(); twist[0] = cube.cornOrientCoord(); udslice[0] = cube.UDSliceCoord(); cornperm[0] = cube.cornPermCoord(); udsliceS[0] = cube.UDSliceCoordS(); usliceS[0] = cube.USliceCoordS(); dsliceS[0] = cube.DSliceCoordS(); minDistPhase1[1] = 1; int mv = 0, n = 0, depthPhase1 = 1; bool busy = false; Stopwatch watch = new Stopwatch(); watch.Start(); if (!printInfo) { Tools.ColorPrint(string.Format( "CUBE COORDINATES\n" + "\n" + " ORIENTATIONS\n" + " Corner : {0}\n" + " Edge : {1}\n" + "\n" + " PERMUTATIONS\n" + " Corner : {2}\n" + " Edge : {3}\n" + "\n" + " SORTED COMBINATIONS\n" + " U-Slice : {4}\n" + " D-Slice : {5}\n" + " UD-Slice : {6}\n" + "\n", twist[0], flip[0], cornperm[0], cube.edgePermCoord(), usliceS[0], dsliceS[0], udsliceS[0] ), ConsoleColor.DarkCyan); } while (true) { do { if (depthPhase1 - n > minDistPhase1[n + 1] && !busy) { if (ax[n] == 0 || ax[n] == 3) { ax[++n] = 1; } else { ax[++n] = 0; } po[n] = 1; } else if (++po[n] > 3) { do { if (++ax[n] > 5) { if (watch.ElapsedMilliseconds > timeoutMS) { //throw new TimeoutException("Not enough time"); List <string> empty = new List <string>(); empty.Add(""); empty.Add(""); empty.Add("0"); return(empty); } if (n == 0) { if (depthPhase1 > maxDepth) { throw new Exception("Max depth exceeded"); } else { depthPhase1++; ax[n] = 0; po[n] = 1; busy = false; if (!printInfo) { Tools.ColorPrint(string.Format("Depth {0} reached\n", depthPhase1), ConsoleColor.DarkCyan); } break; } } else { n--; busy = true; break; } } else { po[n] = 1; busy = false; } } while (n != 0 && (ax[n - 1] == ax[n] || ax[n - 1] == ax[n] + 3)); } else { busy = false; } } while (busy); mv = ax[n] * 3 + po[n] - 1; flip[n + 1] = MoveTables.moveEO[flip[n], mv]; twist[n + 1] = MoveTables.moveCO[twist[n], mv]; udslice[n + 1] = MoveTables.moveUD[udslice[n], mv]; minDistPhase1[n + 1] = Math.Max( PruneTable.pruneEO[Constants.N_UD * flip[n + 1] + udslice[n + 1]], PruneTable.pruneCO[Constants.N_UD * twist[n + 1] + udslice[n + 1]] ); if (minDistPhase1[n + 1] == 0 && n >= depthPhase1 - 1) { minDistPhase1[n + 1] = 10; int s = phaseTwo(depthPhase1, maxDepth); if (n == depthPhase1 - 1 && s >= 0) { if (s == depthPhase1 || (ax[depthPhase1 - 1] != ax[depthPhase1] && ax[depthPhase1 - 1] != ax[depthPhase1] + 3)) { if (!printInfo) { Tools.ColorPrint(string.Format("\nSolution found, length {0}\n\n", s), ConsoleColor.Cyan); } return(axPoToMove(s, (printInfo) ? depthPhase1 : -1)); } } } } }