-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainProg.java
More file actions
72 lines (63 loc) · 1.98 KB
/
mainProg.java
File metadata and controls
72 lines (63 loc) · 1.98 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
70
71
72
//This is the main program to execute the model & run the game.
import java.util.Scanner;
public class mainProg {
public static void main(String[] args) {
// Turn order logic. Any arg makes player second
int turn = 1;
int color = 2;
if (args.length >= 1) {
turn = 2;
color = 1;
}
// Sets board
board curBoard = new board();
curBoard.setBoard();
// Set up scanner for input
Scanner scan = new Scanner(System.in);
// Main game loop
while (true) {
curBoard.printBoard();
int whiteScore = 0;
int blackScore = 0;
for (int i = 0; i < 8; i++)
{
for (int j = 0; j < 8; j++)
{
if (curBoard.curBoard[i][j] == 1)
{
whiteScore++;
}
else if (curBoard.curBoard[i][j] == 2)
{
blackScore++;
}
}
}
System.out.println("Score - WHITE: " + whiteScore + " | BLACK: " + blackScore);
System.out.println();
if (turn == 1) {
System.out.print("Enter player move: ");
boolean moveAccepted = false;
while (!moveAccepted) {
moveAccepted = curBoard.makeMove(curBoard.moveReader(scan.next()), color);
if (!moveAccepted) {
System.out.print("Move rejected. Please enter a valid move in the format B3 or e7:");
}
}
turn = 2;
} else {
board.CoordPair aiMove = model.findBestMove(curBoard, 3 - color);
if (aiMove == null)
{
System.out.println("AI has no legal moves. Passing turn.");
}
else
{
curBoard.makeMove(aiMove, 3 - color);
System.out.println("AI plays: " + model.moveToString(aiMove));
}
turn = 1;
}
}
}
}