private void RotateZ(Rotation rotation, int layer) { if (rotation == Rotation.Clockwise) { Cubelet tmpTopRight = cubelets[2, 0, layer]; Cubelet tmpTop = cubelets[1, 0, layer]; // move cubelets to correct position cubelets[2, 0, layer] = cubelets[0, 0, layer]; cubelets[1, 0, layer] = cubelets[0, 1, layer]; cubelets[0, 0, layer] = cubelets[0, 2, layer]; cubelets[0, 1, layer] = cubelets[1, 2, layer]; cubelets[0, 2, layer] = cubelets[2, 2, layer]; cubelets[1, 2, layer] = cubelets[2, 1, layer]; cubelets[2, 2, layer] = tmpTopRight; cubelets[2, 1, layer] = tmpTop; } else { Cubelet tmpTopLeft = cubelets[0, 0, layer]; Cubelet tmpTop = cubelets[1, 0, layer]; // move cubelets to correct position cubelets[0, 0, layer] = cubelets[2, 0, layer]; cubelets[1, 0, layer] = cubelets[2, 1, layer]; cubelets[2, 0, layer] = cubelets[2, 2, layer]; cubelets[2, 1, layer] = cubelets[1, 2, layer]; cubelets[2, 2, layer] = cubelets[0, 2, layer]; cubelets[1, 2, layer] = cubelets[0, 1, layer]; cubelets[0, 2, layer] = tmpTopLeft; cubelets[0, 1, layer] = tmpTop; } // correct cubelet rotation cubelets[2, 0, layer].RotateZ(rotation); cubelets[1, 0, layer].RotateZ(rotation); cubelets[0, 0, layer].RotateZ(rotation); cubelets[0, 1, layer].RotateZ(rotation); cubelets[0, 2, layer].RotateZ(rotation); cubelets[1, 2, layer].RotateZ(rotation); cubelets[2, 2, layer].RotateZ(rotation); cubelets[2, 1, layer].RotateZ(rotation); }
private void RotateX(Rotation rotation, int layer) { if (rotation == Rotation.Clockwise) { Cubelet tmpTopFront = cubelets[layer, 0, 0]; Cubelet tmpTop = cubelets[layer, 0, 1]; // move cubelets to correct position cubelets[layer, 0, 0] = cubelets[layer, 0, 2]; cubelets[layer, 0, 1] = cubelets[layer, 1, 2]; cubelets[layer, 0, 2] = cubelets[layer, 2, 2]; cubelets[layer, 1, 2] = cubelets[layer, 2, 1]; cubelets[layer, 2, 2] = cubelets[layer, 2, 0]; cubelets[layer, 2, 1] = cubelets[layer, 1, 0]; cubelets[layer, 2, 0] = tmpTopFront; cubelets[layer, 1, 0] = tmpTop; } else { Cubelet tmpTopBack = cubelets[layer, 0, 2]; Cubelet tmpTop = cubelets[layer, 0, 1]; // move cubelets to correct position cubelets[layer, 0, 2] = cubelets[layer, 0, 0]; cubelets[layer, 0, 1] = cubelets[layer, 1, 0]; cubelets[layer, 0, 0] = cubelets[layer, 2, 0]; cubelets[layer, 1, 0] = cubelets[layer, 2, 1]; cubelets[layer, 2, 0] = cubelets[layer, 2, 2]; cubelets[layer, 2, 1] = cubelets[layer, 1, 2]; cubelets[layer, 2, 2] = tmpTopBack; cubelets[layer, 1, 2] = tmpTop; } // correct cubelet rotation cubelets[layer, 0, 2].RotateX(rotation); cubelets[layer, 0, 1].RotateX(rotation); cubelets[layer, 0, 0].RotateX(rotation); cubelets[layer, 1, 0].RotateX(rotation); cubelets[layer, 2, 0].RotateX(rotation); cubelets[layer, 2, 1].RotateX(rotation); cubelets[layer, 2, 2].RotateX(rotation); cubelets[layer, 1, 2].RotateX(rotation); }
private void RotateY(Rotation rotation, int layer) { if (rotation == Rotation.Clockwise) { Cubelet tmpFrontLeft = cubelets[0, layer, 0]; Cubelet tmpFront = cubelets[1, layer, 0]; // move cubelets to correct position cubelets[0, layer, 0] = cubelets[2, layer, 0]; cubelets[1, layer, 0] = cubelets[2, layer, 1]; cubelets[2, layer, 0] = cubelets[2, layer, 2]; cubelets[2, layer, 1] = cubelets[1, layer, 2]; cubelets[2, layer, 2] = cubelets[0, layer, 2]; cubelets[1, layer, 2] = cubelets[0, layer, 1]; cubelets[0, layer, 2] = tmpFrontLeft; cubelets[0, layer, 1] = tmpFront; } else { Cubelet tmpFrontRight = cubelets[2, layer, 0]; Cubelet tmpFront = cubelets[1, layer, 0]; // move cubelets to correct position cubelets[2, layer, 0] = cubelets[0, layer, 0]; cubelets[1, layer, 0] = cubelets[0, layer, 1]; cubelets[0, layer, 0] = cubelets[0, layer, 2]; cubelets[0, layer, 1] = cubelets[1, layer, 2]; cubelets[0, layer, 2] = cubelets[2, layer, 2]; cubelets[1, layer, 2] = cubelets[2, layer, 1]; cubelets[2, layer, 2] = tmpFrontRight; cubelets[2, layer, 1] = tmpFront; } // correct cubelet rotation cubelets[0, layer, 2].RotateY(rotation); cubelets[0, layer, 1].RotateY(rotation); cubelets[0, layer, 0].RotateY(rotation); cubelets[1, layer, 0].RotateY(rotation); cubelets[2, layer, 0].RotateY(rotation); cubelets[2, layer, 1].RotateY(rotation); cubelets[2, layer, 2].RotateY(rotation); cubelets[1, layer, 2].RotateY(rotation); }
/** * Reset the cube to it's solved state */ public void Reset() { for (int row = 0; row < 3; row++) { for (int col = 0; col < 3; col++) { for (int depth = 0; depth < 3; depth++) { CubeletColor front = (depth == 0 ? CubeletColor.Red : CubeletColor.Empty); CubeletColor back = (depth == 2 ? CubeletColor.Orange : CubeletColor.Empty); CubeletColor left = (col == 0 ? CubeletColor.Blue : CubeletColor.Empty); CubeletColor right = (col == 2 ? CubeletColor.Green : CubeletColor.Empty); CubeletColor top = (row == 0 ? CubeletColor.Yellow : CubeletColor.Empty); CubeletColor bottom = (row == 2 ? CubeletColor.White : CubeletColor.Empty); cubelets[col, row, depth] = new Cubelet(front, back, left, right, top, bottom); } } } }