-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTicTacDumbBot.java
29 lines (26 loc) · 947 Bytes
/
TicTacDumbBot.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
/* the dumb bot just guesses moves */
public class TicTacDumbBot implements TicTacToeBot{
int next_move_xcor, next_move_ycor, team;
TicTacBoard gameBoard;
/* makes a new ai with access to the gameboard*/
public TicTacDumbBot(TicTacBoard newboard, int n){
gameBoard = newboard;
team = n;
}
/* continues to guess a move until it gets a valid spot*/
public void getNextMove(){
next_move_xcor = (int)(Math.random() * 3);
next_move_ycor = (int) (Math.random() * 3);
while (!gameBoard.canMove(next_move_xcor, next_move_ycor)){
next_move_xcor = (int)(Math.random() * 3);
next_move_ycor = (int) (Math.random() * 3);
}
}
/* calls getNextMove then makes the move*/
public void makeNextMove(){
if (!gameBoard.isFilled()){
getNextMove();
gameBoard.makeMove(next_move_xcor, next_move_ycor);
}
}
}