-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTestConnectFour.java
More file actions
69 lines (58 loc) · 2.02 KB
/
Copy pathTestConnectFour.java
File metadata and controls
69 lines (58 loc) · 2.02 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
public class TestConnectFour {
public static void main(String[] args) throws Throwable {
java.util.Scanner kb = new java.util.Scanner(System.in);
System.out.print("Enter a valid position string: ");
String position = kb.nextLine();
char[][] board = setUp(position);
for (char[] row : board) {
for (char c : row)
System.out.print(c + " ");
System.out.println();
}
boolean turn = (position.length() % 2 == 0);
long k = System.nanoTime();
<<<<<<< HEAD
=======
// String[] soln = SolveConnectFour.solve(board, turn, position.length(), lastX(position, board), lastY(position, board));
// System.out.println("\n" + soln[0] + "\t" + soln[1] + "\n");
>>>>>>> origin/master
int[] result = SolveConnectFour.solve(board, turn, position.length(), lastX(position, board), lastY(position, board));
System.out.println("\n" + result[0] + " " + result[1] + "\n");
System.out.println((double)(System.nanoTime() - k) / 1E9 + " seconds to run");
}
public static char[][] setUp(String s) {
char[][] board = new char[6][7];
for (int i = 0; i < board.length; i++)
for (int j = 0; j < board[i].length; j++)
board[i][j] = ' ';
<<<<<<< HEAD
int[] gravRow = new int[board[0].length];
for (int i = 0; i < gravRow.length; i++) {
gravRow[i] = board.length - 1;
}
=======
int[] gravRow = new int[board[0].length];
for (int i = 0; i < gravRow.length; i++)
gravRow[i] = 5;
>>>>>>> origin/master
boolean turn = true;
for (int i = 0; i < s.length(); i++) {
int n = Integer.parseInt(s.substring(i, i + 1));
if (turn) board[gravRow[n - 1]][n - 1] = 'R';
else board[gravRow[n - 1]][n - 1] = 'Y';
gravRow[n - 1]--;
turn = !turn;
}
return board;
}
public static int lastX(String s, char[][] board) {
int n = Integer.parseInt(s.substring(s.length() - 1, s.length())) - 1;
for (int i = board.length - 1; i >= 0; i--)
if (board[i][n] == ' ')
return i + 1;
return 0;
}
public static int lastY(String s, char[][] board) {
return Integer.parseInt(s.substring(s.length() - 1, s.length())) - 1;
}
}