public static void DoPLL(Cube cube, List <Move> moves) { List <Move> pllMoves = new List <Move>(); int doubleColorFaceTop = -1; int doubleColorFaceBottom = -1; for (int i = 0; i < 4; i++) { if (cube.Faces[i].Tiles[0] == cube.Faces[i].Tiles[1]) { doubleColorFaceTop = doubleColorFaceTop == -1 ? i : -2; Console.WriteLine("TopFace: " + doubleColorFaceTop); } if (cube.Faces[i].Tiles[2] == cube.Faces[i].Tiles[3]) { doubleColorFaceBottom = doubleColorFaceBottom == -1 ? i : -2; Console.WriteLine("BotFace: " + doubleColorFaceBottom); } } if (-1 < doubleColorFaceTop && 1 != doubleColorFaceTop) { pllMoves.Add(doubleColorFaceTop == 0 ? Move.UP : (doubleColorFaceTop == 2 ? Move.U : Move.U2)); } if (-1 < doubleColorFaceBottom && 1 != doubleColorFaceBottom) { pllMoves.Add(doubleColorFaceBottom == 0 ? Move.D : (doubleColorFaceBottom == 2 ? Move.DP : Move.D2)); } if (-1 < doubleColorFaceTop && -1 < doubleColorFaceBottom) { pllMoves.AddRange(new Move[] { Move.R2, Move.UP, Move.B2, Move.U2, Move.R2, Move.UP, Move.R2 }); } if (-1 < doubleColorFaceTop && -1 == doubleColorFaceBottom) { pllMoves.AddRange(new Move[] { Move.R, Move.UP, Move.R, Move.F2, Move.RP, Move.U, Move.RP }); } if (-1 < doubleColorFaceTop && -2 == doubleColorFaceBottom) { pllMoves.AddRange(new Move[] { Move.RP, Move.U, Move.RP, Move.F2, Move.R, Move.FP, Move.RP, Move.F2, Move.R2 }); } if (-1 == doubleColorFaceTop && -1 < doubleColorFaceBottom) { pllMoves.AddRange(new Move[] { Move.L, Move.DP, Move.L, Move.F2, Move.LP, Move.D, Move.LP }); } if (-1 == doubleColorFaceTop && -1 == doubleColorFaceBottom) { pllMoves.AddRange(new Move[] { Move.R2, Move.F2, Move.R2 }); } if (-1 == doubleColorFaceTop && -2 == doubleColorFaceBottom) { pllMoves.AddRange(new Move[] { Move.R, Move.UP, Move.RP, Move.UP, Move.F2, Move.UP, Move.R, Move.U, Move.RP, Move.D, Move.R2 }); } if (-2 == doubleColorFaceTop && -1 < doubleColorFaceBottom) { pllMoves.AddRange(new Move[] { Move.LP, Move.D, Move.LP, Move.F2, Move.L, Move.FP, Move.LP, Move.F2, Move.L2 }); } if (-2 == doubleColorFaceTop && -1 == doubleColorFaceBottom) { pllMoves.AddRange(new Move[] { Move.L, Move.DP, Move.LP, Move.DP, Move.F2, Move.DP, Move.L, Move.D, Move.LP, Move.U, Move.L2 }); } if (0 < pllMoves.Count) { Console.WriteLine("PLL done\n"); } moves.AddRange(pllMoves); ApplyMoves(cube, pllMoves.ToArray()); }
public static Cube ApplyMove(Cube cube, Move move) { switch (move) { // TODO: expaaannddd case Move.B: cube.RotateBClock(); break; case Move.BP: cube.RotateBCounterClock(); break; case Move.B2: cube.RotateBHalf(); break; case Move.L: cube.RotateLClock(); break; case Move.LP: cube.RotateLCounterClock(); break; case Move.L2: cube.RotateLHalf(); break; case Move.D: cube.RotateDClock(); break; case Move.DP: cube.RotateDCounterClock(); break; case Move.D2: cube.RotateDHalf(); break; case Move.F: cube.RotateFClock(); break; case Move.FP: cube.RotateFCounterClock(); break; case Move.F2: cube.RotateFHalf(); break; case Move.R: cube.RotateRClock(); break; case Move.RP: cube.RotateRCounterClock(); break; case Move.R2: cube.RotateRHalf(); break; case Move.U: cube.RotateUClock(); break; case Move.UP: cube.RotateUCounterClock(); break; case Move.U2: cube.RotateUHalf(); break; default: break; } return(cube); }
public static Move[] OptimalSolve(Cube cube, bool onlyBottomFace = false, bool feedBack = true) { Move maxMoveIndex; if (onlyBottomFace) { maxMoveIndex = Enum.GetValues(typeof(Move)).Cast <Move>().Max(); } else { maxMoveIndex = (Move)Enum.GetValues(typeof(MoveOptimalSolve)).Cast <MoveOptimalSolve>().Max(); } //maxMoveIndex = (Move)Enum.GetValues(typeof(MoveOptimalSolve)).Cast<MoveOptimalSolve>().Max(); // TEST List <Move> moves = new List <Move>(); int amountChecked = 0; List <List <Move> > movesChecked = new List <List <Move> >(); //Console.WriteLine("Solved: " + cube.IsSolved()); if ((!onlyBottomFace && cube.IsSolved()) || (onlyBottomFace && cube.Faces[5].IsOneColor() != -1)) { return(moves.ToArray()); } for (int i = 0; i <= 11; i++) { moves.Add((Move)0); int j = 0; do { Cube testCube = new Cube(cube); Cube.ApplyMoves(testCube, moves.ToArray()); if ((!onlyBottomFace && testCube.IsSolved()) || (onlyBottomFace && testCube.Faces[5].IsOneColor() != -1)) { return(moves.ToArray()); } amountChecked++; //Console.WriteLine(testCube); //Console.WriteLine(ToFriendlyString(moves.ToArray()) + " " + testCube.IsSolved()); //Console.Write(ToFriendlyString(moves.ToArray()) + "\t\t"); bool isDecentMove; j = -1; do { isDecentMove = true; j++; if (0 < j) { moves[j - 1] = (Move)0; } moves[j]++; // Console.Write(j.ToString() + i.ToString() + " "); if (j < i) { isDecentMove = IsDecentNextMove(moves[j], moves[j + 1]); } while (j < i && moves[j] < maxMoveIndex && !isDecentMove) { moves[j]++; isDecentMove = IsDecentNextMove(moves[j], moves[j + 1]); } if (!isDecentMove) { //Console.WriteLine("Not decent: " + moves[j]); moves[j]++; } //Console.Write(":" + moves[j] + " " + (j < i ? moves[j + 1].ToString() : "") + " " + isDecentMove + "\n"); } while (j < i && maxMoveIndex < moves[j]); // Console.WriteLine("DAMN"); } while (moves[j] <= maxMoveIndex); moves[j] = (Move)0; if (feedBack) { Console.WriteLine("Amount Checked: " + amountChecked); //Console.ReadKey(); } } return(null); }