UM CSCI 152- Java
This program simulates a 3×3 Rubik's Cube using a 3-dimensional char array in Java. It supports single and multiple face rotations, tracks all moves made during the session, and can output a solution sequence to undo all previous moves.
public static void rotateFaceClockwise(char[][] face) {
char[][] temp = new char[3][3];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
temp[j][2 - i] = face[i][j];
}
}
for (int i = 0; i < 3; i++) {
System.arraycopy(temp[i], 0, face[i], 0, 3);
}
}
ArrayList<String> stack = new ArrayList<>();
public static void solve(ArrayList<String> stack) {
System.out.print("Solution: ");
for (int i = stack.size() - 1; i >= 0; i--) {
System.out.print(stack.get(i) + " ");
}
System.out.println();
}
This project challenged my understanding of 3D spatial reasoning and array indexing. It also provided valuable practice handling real-time input and state management in an object-based simulation. Possible improvements include adding scrambling, move optimizations, and full cube solving algorithms.