forked from dntf0llow/openHalma
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.java
105 lines (88 loc) · 3.13 KB
/
Player.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import java.util.*;
import java.awt.Color;
public abstract class Player
{
protected final Color p_color;
protected final FIELD_VALUE fieldValue;
public static Player emptyPlayer = new LocalPlayer(FIELD_VALUE.EMPTY, Color.white, "");
protected final String name;
protected LinkedList<Position> targetPositions;
protected Position tip;
protected Position direction; //this is a position because it needs to hold x and y value
public Player() {
this(FIELD_VALUE.EMPTY, Color.white, ""); // by default this creates the empty player
}
public Player(FIELD_VALUE fieldValue, Color color, String s) {
fieldValue.setPlayer(this);
this.fieldValue = fieldValue;
this.p_color = (color == null) ? Color.black : color;
this.name = (s.equals("")) ? "Player" + fieldValue.getVal() : s;
}
public void initPositions(StarBoard board, LinkedList<Position> posis) {
for (Position p : posis) {
board.setPosition(p, this.fieldValue);
}
double distance = 0, pdistance;
Position center = new Position(board.dimension / 2, board.dimension / 2);
for (Position p: targetPositions) {
pdistance = board.pointDistance(p, center);
if (pdistance > distance) {
distance = pdistance;
tip = p;
}
}
Logger.log(LOGGER_LEVEL.DEBUG, this.toString() + " target (tip) is: " + tip.toString());
}
public void setTargetPositions(LinkedList<Position> p) {
this.targetPositions=p;
}
public void setDirection(Position p) {
this.direction = p;
}
public Color getColor() {
return p_color;
}
public FIELD_VALUE getFieldValue() {
return fieldValue;
}
public String getName() {
return name;
}
//request the player to make a move
public abstract Move requestMove(StarBoard board, LinkedList<Player> pl, Player p);
public boolean equals (Object p) {
if (!(p instanceof Player)) return false;
//TODO: check more?
return ((Player)p).fieldValue == this.fieldValue;
}
public Position getDirection() {
return direction;
}
public Position getTip() {
return tip;
}
public LinkedList<Position> getTargetPositions() {
return targetPositions;
}
public boolean isFinished(StarBoard b) {
for (Position p : targetPositions) ;// Logger.log(LOGGER_LEVEL.TEMP_DEBUG, this.toString() + " target: " + p);
for (Position p : b.getPositionByPlayer(this)) { //TODO: find out why this sometimes doesnt find all positions
//Logger.log(LOGGER_LEVEL.TEMP_DEBUG, this.toString() + " current: " + p);
if (!(targetPositions.contains(p))) {
return false;
}
}
return true;
}
public String toString() {
final String suffix;
if (this instanceof LocalPlayer) {
suffix = "H";
} else if (this instanceof ComputerPlayer) {
suffix = "C";
} else {
suffix = "N";
}
return this.name + "[" + suffix + "]";
}
}