-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoardUtils.java
More file actions
37 lines (34 loc) · 1.19 KB
/
BoardUtils.java
File metadata and controls
37 lines (34 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
public class BoardUtils {
public static void printBoard(int[][] board) {
System.out.println(" 0 1 2 3 4 5 6 7 8");
for (int i = 0; i < 9; i++) {
if (i % 3 == 0)
System.out.println(" +-------+-------+-------+");
System.out.print(i + " | ");
for (int j = 0; j < 9; j++) {
if (board[i][j] == 0)
System.out.print(". ");
else
System.out.print(board[i][j] + " ");
if ((j + 1) % 3 == 0)
System.out.print("| ");
}
System.out.println();
}
System.out.println(" +-------+-------+-------+");
}
public static boolean isBoardFull(int[][] board) {
for (int[] row : board)
for (int cell : row)
if (cell == 0)
return false;
return true;
}
public static int[][] deepCopy(int[][] original) {
int[][] copy = new int[original.length][original[0].length];
for (int i = 0; i < original.length; i++) {
System.arraycopy(original[i], 0, copy[i], 0, original[0].length);
}
return copy;
}
}