-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFoolAI.java
More file actions
61 lines (58 loc) · 1.49 KB
/
Copy pathFoolAI.java
File metadata and controls
61 lines (58 loc) · 1.49 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
import java.lang.Math;
//This is a fool AI that inserts coin at random position
//@Param = Board for changing data inside
public class FoolAI extends Player implements playerInterface{
/**
* Initializes FoolAI object with given color
* @param color
*/
public FoolAI(String color)
{
super(color);
}
@Override
public Board act(Board b)
{
//hasValue = check if the position ai choose randomly has coin inside already
//rechoose number if so
boolean noValue = true;
//check what board the game is playing
boolean checkC4 = b.get_connect_four();
boolean checkC5 = b.get_connect_five();
//create a new coin which represent AI coin
Coin c = new Coin(color);
Coin[][]bCoin = b.getBoard();
//int for taking value of the position where the AI is going to put the coin at
//default at [0,0], but will change later
int row = 0;
int col = 0;
//generate random number for both row and column
//6*7 board for connect-four
do
{
if(checkC4)
{
row = (int)(Math.random() * 8-1+1) + 1;
col = (int)(Math.random() * 8-1+1) + 1;
}
//6*9 board for connect-five
if(checkC5)
{
row = (int)(Math.random() * 8-1+1) + 1;
col = (int)(Math.random() * 8-1+1) + 1;
}
//choose new number of row and col if there is coin in position the ai firstly choose
if(!(bCoin[row][col] == null))
{
noValue = false;
}
else
{
noValue = true;
}
}while(!noValue);
//insert the coin to the board and return it
b.insert(c,row,col);
return b;
}
}