-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplay.java
76 lines (72 loc) · 2.84 KB
/
play.java
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
70
71
72
73
74
75
76
import java.util.*;
import java.io.*;
public class play {
public static void main(String args[]){
engine thisGame = new engine();
playGame(thisGame);
}
public static String[][][] formatBoard(int[][][] thisBoard){
String[][][] formattedBoard = new String[4][4][4];
for(int i = 0; i < 4; i++){
for(int j = 0; j < 4; j++){
for(int k = 0; k < 4; k++){
if(thisBoard[i][j][k] == 0){
formattedBoard[i][j][k] = "-";
}
else if(thisBoard[i][j][k] == 1){
formattedBoard[i][j][k] = "●";
}
else{
formattedBoard[i][j][k] = "○";
}
}
}
}
return formattedBoard;
}
public static void playGame(engine game){
Scanner kb = new Scanner(System.in);
boolean playersMove = true;
boolean gameEnded = false;
int[] lastMoveBot = new int[2];
int[] lastMove = new int[2];
outerloop:
while(!gameEnded){
if(playersMove){
System.out.println("Enter your move");
String[] move = kb.nextLine().split(" ");
if(move[0].equalsIgnoreCase("UNDO")){
game.undo(lastMove[0], lastMove[1]);
game.undo(lastMoveBot[0], lastMoveBot[1]);
continue outerloop;
}
lastMove[0] = Integer.parseInt(move[0]);
lastMove[1] = Integer.parseInt(move[1]);
game.playMove(Integer.parseInt(move[0]), Integer.parseInt(move[1]));
System.out.println(game.scoreBoard());
playersMove = false;
}
else{
System.out.println("Processing...");
double[] currentMove = game.bestMove(true, 0, game.depth);
lastMoveBot[0] = (int)currentMove[1];
lastMoveBot[1] = (int)currentMove[2];
game.playMove((int)currentMove[1], (int)currentMove[2]);
System.out.println((int)currentMove[1] + " " + (int)currentMove[2]);
System.out.println(currentMove[0]);
System.out.println(game.scoreBoard());
playersMove = true;
}
for(int i = 0; i < 4; i++){
for(int j = 0; j < 4; j++){
for(int k = 0; k < 4; k++){
System.out.print(formatBoard(game.board)[i][j][k] + " ");
}
System.out.println();
}
System.out.println();
}
System.out.println("_____________________________ ");
}
}
}