/** * Written by Nathan: Step one in solving the rubiks cube. * This will solve the white cross on top of the cube. * NOTE: This is the version I had before cloning Luke's repo. */ public void SolveWhiteCross() { while (!WhiteCrossSolved()) { List <Block> yellow_slice = cube.GetSlice(Color.Yellow); Orientor front_face; Edge edge_piece; Boolean block_with_white_on_bottom = false, block_with_white_in_center, block_on_top_not_oriented_correctly; //will take any edge piece with the white on the bottom and place it where it needs to be. foreach (Block block_in_yellow_slice in yellow_slice) { //if the blocks in the yellow slice that have a white color also have a green color //is an edge piece if (cube.GetBlock(Color.Green, true, cube.GetBlock(Color.White, true, yellow_slice)).Count == 1) { block_with_white_on_bottom = true; edge_piece = (Edge)cube.GetBlock(Color.Green, true, cube.GetBlock(Color.White, true, yellow_slice))[0]; //while the edgepeice isn't directly under the side it needs to be, //cube.Rotate it until it is. while (!edge_piece.Equals(cube.GetBlock(1, 0, 0))) { cube.Rotate(Color.Yellow, Direction.Clockwise); } //get the block that will give you the orientation to use as the front face front_face = Cube.GetOrientation(Color.Green); PlaceBottomEdgePieceInCross(edge_piece, front_face); //yellow_slice = cube.GetSlice(Color.Yellow); break; } else if (cube.GetBlock(Color.Orange, true, cube.GetBlock(Color.White, true, yellow_slice)).Count == 1) { block_with_white_on_bottom = true; edge_piece = (Edge)cube.GetBlock(Color.Orange, true, cube.GetBlock(Color.White, true, yellow_slice))[0]; while (!edge_piece.Equals(cube.GetBlock(0, 0, 1))) { cube.Rotate(Color.Yellow, Direction.Clockwise); } front_face = Cube.GetOrientation(Color.Orange); PlaceBottomEdgePieceInCross(edge_piece, front_face); //yellow_slice = cube.GetSlice(Color.Yellow); break; } else if (cube.GetBlock(Color.Red, true, cube.GetBlock(Color.White, true, yellow_slice)).Count == 1) { block_with_white_on_bottom = true; edge_piece = (Edge)cube.GetBlock(Color.Red, true, cube.GetBlock(Color.White, true, yellow_slice))[0]; while (!edge_piece.Equals(cube.GetBlock(2, 0, 1))) { cube.Rotate(Color.Yellow, Direction.Clockwise); } front_face = Cube.GetOrientation(Color.Red); PlaceBottomEdgePieceInCross(edge_piece, front_face); //yellow_slice = cube.GetSlice(Color.Yellow); break; } else if (cube.GetBlock(Color.Blue, true, cube.GetBlock(Color.White, true, yellow_slice)).Count == 1) { block_with_white_on_bottom = true; edge_piece = (Edge)cube.GetBlock(Color.Blue, true, cube.GetBlock(Color.White, true, yellow_slice))[0]; //Block temp = cube.GetBlock(1, 0, 2); while (!edge_piece.Equals(cube.GetBlock(1, 0, 2))) { cube.Rotate(Color.Yellow, Direction.Clockwise); } front_face = Cube.GetOrientation(Color.Blue); PlaceBottomEdgePieceInCross(edge_piece, front_face); break; } else { block_with_white_on_bottom = false; } } /***************************************************** * if edge piece is in the center, then put it in the bottom layer, * and the above will put it in the correct position. */ if (block_with_white_in_center = cube.GetBlock(0, 1, 0).HasColor(Color.White)) { cube.Rotate(Color.Green, Direction.CounterClockwise); } else if (block_with_white_in_center = cube.GetBlock(0, 1, 2).HasColor(Color.White)) { cube.Rotate(Color.Orange, Direction.CounterClockwise); } else if (block_with_white_in_center = cube.GetBlock(2, 1, 2).HasColor(Color.White)) { cube.Rotate(Color.Blue, Direction.CounterClockwise); } else if (block_with_white_in_center = cube.GetBlock(2, 1, 0).HasColor(Color.White)) { cube.Rotate(Color.Red, Direction.CounterClockwise); } else { block_with_white_in_center = false; } if (block_with_white_in_center) { continue; } /******************************************************/ /***************************************************** * if edge piece is in the correct position, but the incorrect * orientation, then put it in the bottom layer, and let the * placeBottomEdgePieceInCross(...) function handle puting it * in the correct position */ if (block_on_top_not_oriented_correctly = cube.GetBlock(1, 2, 0).front == Color.White) { front_face = Cube.GetOrientation(Color.Green); } else if (block_on_top_not_oriented_correctly = cube.GetBlock(0, 2, 1).left == Color.White) { front_face = Cube.GetOrientation(Color.Orange); } else if (block_on_top_not_oriented_correctly = cube.GetBlock(1, 2, 2).back == Color.White) { front_face = Cube.GetOrientation(Color.Blue); } else if (block_on_top_not_oriented_correctly = cube.GetBlock(2, 2, 1).right == Color.White) { front_face = Cube.GetOrientation(Color.Red); } else { front_face = null; block_on_top_not_oriented_correctly = false; } if (block_on_top_not_oriented_correctly) { cube.Rotate(front_face.front, Direction.Clockwise); cube.Rotate(front_face.front, Direction.Clockwise); } /*****************************************************/ /* * if the cross is solved, but incorreclty oriented */ if (!block_with_white_on_bottom && !block_with_white_in_center && !block_on_top_not_oriented_correctly) { CheckWhiteCross(); } } }
public Solver(Cube cube) { this.cube = cube; }