-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.java
48 lines (41 loc) · 1.17 KB
/
Game.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
import java.io.IOException;
import java.util.Scanner;
public class Game {
private final String HUMAN = "human";
private final String COMPUTER = "computer";
private Board b;
private Scanner reader = new Scanner(System.in); // Reading from System.in
public Game() throws InterruptedException, IOException {
b = new Board();
while(!b.gameOver()) {
personMove(HUMAN);
if(b.gameOver()) {
break;
}
else {
computerMove();
}
}
reader.close();
}
private void personMove(String team) throws IOException, InterruptedException {
int move = 0;
while(!(move > 0 && move < 8)) { // read in the person's move
System.out.println("Human enter a number: ");
move = reader.nextInt(); // Scans the next token of the input as an int.
}
move--;
while(!b.putPiece(team, move)) {
System.out.println("Move unavailable");
}
b.drawBoard();
}
private void computerMove() throws IOException, InterruptedException {
Board tempBoard = b;
AI ai = new AI();
Move tempMove = new Move(0, 0);
Move bestMove = ai.minimax(tempBoard, 8, -1000000000, 1000000000, COMPUTER, tempMove);
b.putPiece(bestMove.yMove, bestMove.xMove);
b.drawBoard();
}
}