-
Notifications
You must be signed in to change notification settings - Fork 0
/
WhitePlayer.java
108 lines (91 loc) · 2.3 KB
/
WhitePlayer.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
106
107
108
public class WhitePlayer implements Player {
public static int STARTING_POINT = 24;
public static int ENDING_POINT = 1;
public static int MIDPOINT = 7;
@Override
public int moveChecker(int startingPosition, int n) {
int finalPosition = 0;
/* Daca piesa este pe bara */
if (startingPosition == Board.BAR){
finalPosition = STARTING_POINT - n + 1;
}
/* Altfel piesa este pe tabla, in joc */
else {
finalPosition = startingPosition - n;
/* Mutarea ne-a dus piesa la capatul jocului */
if (finalPosition < getEndingPoint()){
finalPosition = Board.OUT;
}
}
return finalPosition;
}
@Override
public boolean isInEndPhase(int[] checkersLocation){
/* Cazul in care avem o piesa pe bara */
if (checkersLocation[Board.BAR] != 0) {
return false;
}
int i = getStartingPoint();
for( ; i >= MIDPOINT; i--){
if (checkersLocation[i] > 0){
return false;
}
}
return true;
}
@Override
public int getFarest(int[] checkersLocation, int[] opponentLocations, int dice) {
int result = -1;
int newLocation = 0;
for (int i = MIDPOINT-1; i >= ENDING_POINT; i--) {
if (checkersLocation[i] > 0) {
newLocation = i-dice;
if ((newLocation >= ENDING_POINT && opponentLocations[newLocation] <= 1) ||
(newLocation < ENDING_POINT)){
result = i;
return result;
}
else if (newLocation >= ENDING_POINT && opponentLocations[newLocation] > 1){
return -1;
}
}
}
return result;
}
public int getFarest (int[] checkersLocation, int dice){
int result = ENDING_POINT + dice - 1;
if (checkersLocation[result] > 0){
return result;
}
return -1;
}
@Override
public int closerToHouse(int[] checkersLocation) {
int free = 0;
for (int i = STARTING_POINT; i >= ENDING_POINT; i--){
if (checkersLocation[i] > 0)
break;
free++;
}
return free;
}
@Override
public int[] getOpponentHouseInterval() {
int[] result = new int[2];
result[0] = 19;
result[1] = 24;
return result;
}
@Override
public int getStartingPoint() {
return STARTING_POINT;
}
@Override
public int getEndingPoint() {
return ENDING_POINT;
}
@Override
public boolean equals(Object o){
return (o instanceof WhitePlayer);
}
}