-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHumanPlayer.java
More file actions
38 lines (35 loc) · 773 Bytes
/
Copy pathHumanPlayer.java
File metadata and controls
38 lines (35 loc) · 773 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
/****************************************************************
* HumanPlayer.java
*
*/
import java.io.*;
public class HumanPlayer extends Player
{
public static final int SLEEP_TIME = 20;
public static int choice = -1;
public void move(GameState context)
{
//reset the choice from board
choice = -1;
//select the first legal move to be safe
for (int i=0; i<6; i++)
{
if (!context.illegalMove(i))
{
move = i;
break;
}
}
//try to get the choice from GUI
while (choice == -1)
{
Utility.tSleep(SLEEP_TIME);
}
//transform from the index of the bins to the choice
if (choice < 6)
move = choice;
else
move = choice - 6;
choice = -1;
}
}