-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeadWood.java
More file actions
223 lines (199 loc) · 5.76 KB
/
Copy pathDeadWood.java
File metadata and controls
223 lines (199 loc) · 5.76 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
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
import java.util.ArrayList;
public class DeadWood implements Bot {
// The public API of YourTeamName must not change
// You cannot change any other classes
// YourTeamName may not alter the state of the board or the player objects
// It may only inspect the state of the board and the player objects
private boolean rollDone = false;
private boolean wasInJail = false;
private int turnsInJail = 0;
private ArrayList<Property> ownedProperty;
BoardAPI boardBot;
PlayerAPI playerBot;
DiceAPI diceBot;
DeadWood (BoardAPI board, PlayerAPI player, DiceAPI dice) {
boardBot=board;
playerBot=player;
diceBot=dice;
return;
}
public String getName() {
return "DeadWood";
}
public String getCommand() {
String command = "done";
if(!wasInJail) isReroll();
if(command=="done") command = checkForJail();
if(command=="done") command = tryToBuyProperty();
if(command=="done") command = buildUp();
if(command=="done") command = checkBalance();
if(command=="done") command = tryToRoll();
if(command=="done") {
rollDone = false;
wasInJail=false;
}
return command;
}
public String getDecision() {
if(playerBot.getBalance() > 50) return "pay";
else return "chance";
}
private void isReroll() {
if(diceBot.isDouble()) {
rollDone = false;
if(playerBot.isInJail()) rollDone=true;
}
}
private String tryToBuyProperty() {
Property prop = null;
//square = board.getSquare(player.getPosition());
if(boardBot.isProperty(playerBot.getPosition())) {
prop = boardBot.getProperty(playerBot.getPosition());
}
if(prop!=null && prop.getOwner()==null && prop!=boardBot.getProperty(12) && prop!=boardBot.getProperty(28) ) {
if(playerBot.getBalance() < prop.getPrice()) {
return mortgageCheapestProperty();
}
return "buy";
}
return "done";
}
private String buildUp(){
if(ownedProperty==null){
return "done";
} else {
for (Property currProp : ownedProperty) {
if (currProp instanceof Site) {
if (playerBot.isGroupOwner((Site) currProp)) {
if(currProp.isMortgaged()){
if(playerBot.getBalance()>currProp.getMortgageRemptionPrice()){
return "redeem " + currProp.getShortName();
}
} else {
for (int i = 5; i > 0; i--) {
if (((Site) currProp).canBuild(i) && playerBot.getBalance() > ((Site) currProp).getBuildingPrice() * i) {
return "build " + currProp.getShortName() + " " + i;
}
}
}
}
}
}
}
return "done";
}
private String checkForJail() {
if(playerBot.isInJail()) {
int ownedProp = 0;
if(turnsInJail > 0) {
for(int checkProperties = 0; checkProperties<40; checkProperties++)
{
if(boardBot.isProperty(checkProperties))
{
if(boardBot.getProperty(checkProperties).getOwner() != null)
{
ownedProp += 1;
}
}
}
if(ownedProp>=24 && !rollDone)
{
wasInJail = true;
if(playerBot.hasGetOutOfJailCard () && turnsInJail==3) return "card";
else {
rollDone = true;
return "roll";
}
} else if(ownedProp<24 && playerBot.hasGetOutOfJailCard ()) {
wasInJail = true;
return "card";
}else{
if(playerBot.getBalance() > 50) {
wasInJail = true;
return "pay";
}
else return mortgageCheapestProperty();
}
}
else rollDone = true;
turnsInJail += 1;
}
else {
turnsInJail=0;
}
return "done";
}
private String tryToRoll() {
if(!rollDone) {
rollDone = true;
return "roll";
}
return "done";
}
private String checkBalance() {
ownedProperty = playerBot.getProperties();
String command;
if(playerBot.getBalance() < 0) {
command = mortgageCheapestProperty();
if(command=="done") command = "bankrupt";
return command;
}
else if(playerBot.getBalance() > 600) {
command = buildUp();
if(command=="done") command = redeemMostExpensiveProperty();
return command;
}
return "done";
}
private String mortgageCheapestProperty() {
ownedProperty = playerBot.getProperties();
if(ownedProperty != null) {
Property cheapestProp = null;
int i=0;
while(cheapestProp==null && i<ownedProperty.size()) {
if(!ownedProperty.get(i).isMortgaged()) {
cheapestProp = ownedProperty.get(i);
}
i++;
}
if(cheapestProp!=null) {
for(Property currProp : ownedProperty) {
if(cheapestProp.getRent() > currProp.getRent() && !currProp.isMortgaged()) {
cheapestProp = currProp;
}
}
if(cheapestProp instanceof Site) {
if(((Site) cheapestProp).hasBuildings()) {
return "demolish " + cheapestProp.getShortName() + " 1";//TODO check building is ready
}
else return "mortgage " + cheapestProp.getShortName();
} else {
return "mortgage " + cheapestProp.getShortName();
}
}
}
return "done";
}
private String redeemMostExpensiveProperty() {
ownedProperty = playerBot.getProperties();
if(ownedProperty != null) {
Property expensiveProp = null;
int i=0;
while(expensiveProp==null && i<ownedProperty.size()) {
if(ownedProperty.get(i).isMortgaged()) {
expensiveProp = ownedProperty.get(i);
}
i++;
}
if(expensiveProp!=null) {
for(Property currProp : ownedProperty) {
if(expensiveProp.getPrice() < currProp.getPrice() && currProp.isMortgaged()) {
expensiveProp = currProp;
}
}
return "redeem " + expensiveProp.getShortName();
}
}
return "done";
}
}