-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.java
More file actions
61 lines (54 loc) · 1.59 KB
/
Player.java
File metadata and controls
61 lines (54 loc) · 1.59 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
/****************************************************************
* Player.java
* Mancala plater
*/
public abstract class Player {
protected int move; //stores the current best move for the player
private String screenName;
private int whichPlayer;
Player() {
move = 0;
screenName = new String("");
whichPlayer = 1;
}
/**
* Callback method to tell the player that it is its turn to move.
* It can always assume that the player will have at least one valid move.
*
* @param context the current position in the game
*
* @return the index of the bin to move from.
*/
public abstract void move(GameState context);
/**
* Initializes the internal state of the player.
*
* @param screenName the name of the player that will appear on the game display
* @param whichPlayer either 1 or 2 to indicate if the player is the one who goes first.
* If other than 1 or 2 it defaults to 1
*/
public void initialize(String screenName, int whichPlayer) {
this.screenName = screenName;
if (whichPlayer > 2 || whichPlayer < 1) {
this.whichPlayer = 1;
}
else {
this.whichPlayer = whichPlayer;
}
}
/**
* Retrieves a display name for the player.
*
* @return a readable name for this player
*/
public String getDisplayName() {
return screenName;
}
/**
* @returns the latest move chosen by the player after the latest search.
* The move must be a valid one according to the latest GameContext sent to the player.
*/
public int getMove() {
return move;
}
}