-
Notifications
You must be signed in to change notification settings - Fork 0
/
ComputerPlayer
55 lines (47 loc) · 1.25 KB
/
ComputerPlayer
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
/* ************************************************************************* *\
* Programmierung 1 HS 2018 - Serie 5-1
* Raphaela Seeger 16-113-441
* Anastasija Novikova 16-825-390
\* ************************************************************************* */
/** A not as stupid computer player */
public class ComputerPlayer implements IPlayer
{
private Token token;
/**
* Strategy is to chose a random column and select
* the next valid column to the right (the chosen included)
*/
public int getNextColumn( Token[][] board )
{
java.util.Random generator = new java.util.Random();
int col = generator.nextInt( board.length );
int step = 0;
while ( isColFull( col, board ) ) {
col = ( col + 1 ) % board.length;
}
return col;
}
/**
* @return true if the column col is already full and false otherwise.
*/
private boolean isColFull( int col, Token[][] board )
{
int topRow = board[ col ].length - 1;
if( board[ col ][ topRow ] != Token.empty )
{return true;}
else
{return false;}
}
public void setToken( Token token )
{
this.token = token;
}
public Token getToken()
{
return this.token;
}
public String getPlayersName()
{
return "Random Player";
}
}