-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAiPlayer.java
More file actions
44 lines (28 loc) · 876 Bytes
/
AiPlayer.java
File metadata and controls
44 lines (28 loc) · 876 Bytes
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
import java.util.ArrayList;
import java.util.Random;
class AiPlayer extends Player {
public AiPlayer(String name, char symbol){
super(name, symbol);
}
public void play(XandOGame game){
// call the checkAvailableCells method to check for available methods
ArrayList<Integer> availableCells = game.getAvailableCells();
Random randomnumbers = new Random();
//choose a random cells and pass it to the modify game State method
int random = 0;
while(availableCells.size() > 0 ){
random = randomnumbers.nextInt(9-1+1) + 1;
while(!availableCells.contains(random)){
random = randomnumbers.nextInt(9-1+1) + 1;
break;
}
break;
}
int symbolValue = resolveSymbol();
if(random != 0){
game.modifyGameState(random, symbolValue);
};
System.out.println(getSymbol() + " just played...");
game.printGameBoard();
}
}