-
Notifications
You must be signed in to change notification settings - Fork 0
/
DumbPlayer.java
54 lines (47 loc) · 1.14 KB
/
DumbPlayer.java
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
/**
* A really dumb player. *Any* decent player should win ALL games against this
* player
*/
public class DumbPlayer implements Player {
private int horizontal, vertical,identifier;
public DumbPlayer(int ident) {
horizontal = 0;
vertical = 0;
this.identifier = ident;
}
@Override
/**
* Uses a 'straight-forward' way for placing tiles:
* starts in the top left, and sequentially tries every possibility until one works.
*/
public Location placeTile(boolean retry) {
MyLocation tile;
if(!retry)
tile = new MyLocation(horizontal, vertical);
else{
if(horizontal < Game.SIZE-1){
horizontal++;
tile = new MyLocation(horizontal, vertical);
}
else{
horizontal = 0;
vertical++;
tile = new MyLocation(horizontal, vertical);
}
}
return tile;
}
@Override
/**
* Doesn't use the state of the board at all - (again, not a good idea!)
* resets the placement sequence on every move, ie. it will restart trying
* to place tiles at the top left at every move.
*/
public void setResult(Location move) {
horizontal = 0;
vertical = 0;
}
public int getIdentifier(){
return this.identifier;
}
}