1 | package com.takenoko.engine; | |
2 | ||
3 | import com.takenoko.actions.Action; | |
4 | import com.takenoko.actions.ActionResult; | |
5 | import com.takenoko.inventory.Inventory; | |
6 | import com.takenoko.objective.Objective; | |
7 | import java.util.List; | |
8 | import java.util.Objects; | |
9 | ||
10 | /** This class is used to store the state of a bot. */ | |
11 | public class BotState { | |
12 | public static final int MAX_OBJECTIVES = 5; | |
13 | private final ObjectiveManager objectiveManager; | |
14 | private final ActionManager actionManager; | |
15 | private final Inventory inventory; | |
16 | ||
17 | public BotState( | |
18 | Inventory inventory, ObjectiveManager objectiveManager, ActionManager actionManager) { | |
19 | this.inventory = inventory; | |
20 | this.objectiveManager = objectiveManager; | |
21 | this.actionManager = actionManager; | |
22 | } | |
23 | ||
24 | public BotState() { | |
25 | this(new Inventory(), new ObjectiveManager(), new ActionManager()); | |
26 | } | |
27 | ||
28 | /** | |
29 | * Copy constructor | |
30 | * | |
31 | * @param botState the state to copy | |
32 | */ | |
33 | public BotState(BotState botState) { | |
34 | this.inventory = botState.getInventory().copy(); | |
35 | this.actionManager = new ActionManager(botState.actionManager); | |
36 | this.objectiveManager = new ObjectiveManager(botState.objectiveManager); | |
37 | } | |
38 | ||
39 | // ------------------------------------------------------ // | |
40 | // ------------------- OBJECT METHODS ------------------- // | |
41 | // ------------------------------------------------------ // | |
42 | ||
43 | /** reset everything to the default values */ | |
44 | public void reset() { | |
45 |
1
1. reset : removed call to com/takenoko/engine/ObjectiveManager::reset → TIMED_OUT |
this.objectiveManager.reset(); |
46 |
1
1. reset : removed call to com/takenoko/engine/ActionManager::reset → TIMED_OUT |
this.actionManager.reset(); |
47 |
1
1. reset : removed call to com/takenoko/inventory/Inventory::clear → TIMED_OUT |
this.inventory.clear(); |
48 | } | |
49 | ||
50 | /** | |
51 | * make a copy of the current state | |
52 | * | |
53 | * @return the copy | |
54 | */ | |
55 | public BotState copy() { | |
56 |
1
1. copy : replaced return value with null for com/takenoko/engine/BotState::copy → KILLED |
return new BotState(this); |
57 | } | |
58 | ||
59 | @Override | |
60 | public boolean equals(Object o) { | |
61 |
2
1. equals : negated conditional → KILLED 2. equals : replaced boolean return with false for com/takenoko/engine/BotState::equals → KILLED |
if (this == o) return true; |
62 |
3
1. equals : negated conditional → KILLED 2. equals : negated conditional → KILLED 3. equals : replaced boolean return with true for com/takenoko/engine/BotState::equals → KILLED |
if (o == null || getClass() != o.getClass()) return false; |
63 | BotState botState = (BotState) o; | |
64 |
2
1. equals : negated conditional → KILLED 2. equals : replaced boolean return with true for com/takenoko/engine/BotState::equals → KILLED |
return getInventory().equals(botState.getInventory()) |
65 |
1
1. equals : negated conditional → KILLED |
&& objectiveManager.equals(botState.objectiveManager) |
66 |
1
1. equals : negated conditional → KILLED |
&& actionManager.equals(botState.actionManager); |
67 | } | |
68 | ||
69 | @Override | |
70 | public int hashCode() { | |
71 |
1
1. hashCode : replaced int return with 0 for com/takenoko/engine/BotState::hashCode → KILLED |
return Objects.hash(getInventory(), objectiveManager, actionManager); |
72 | } | |
73 | ||
74 | /** | |
75 | * update the objectives | |
76 | * | |
77 | * @param board the board | |
78 | */ | |
79 | public void update(Board board) { | |
80 |
1
1. update : removed call to com/takenoko/engine/ObjectiveManager::updateObjectives → TIMED_OUT |
this.objectiveManager.updateObjectives(board, this); |
81 |
1
1. update : removed call to com/takenoko/engine/ActionManager::updateDefaultActions → KILLED |
this.actionManager.updateDefaultActions(board, this); |
82 | } | |
83 | ||
84 | // ------------------------------------------------------ // | |
85 | // ----------------- INVENTORY METHODS ------------------ // | |
86 | // ------------------------------------------------------ // | |
87 | ||
88 | /** | |
89 | * @return the number of bamboo eaten by the bot | |
90 | */ | |
91 | public int getEatenBambooCounter() { | |
92 |
1
1. getEatenBambooCounter : replaced int return with 0 for com/takenoko/engine/BotState::getEatenBambooCounter → NO_COVERAGE |
return inventory.getBambooCount(); |
93 | } | |
94 | ||
95 | /** | |
96 | * Return the bot inventory | |
97 | * | |
98 | * @return the bot inventory | |
99 | */ | |
100 | public Inventory getInventory() { | |
101 |
1
1. getInventory : replaced return value with null for com/takenoko/engine/BotState::getInventory → KILLED |
return inventory; |
102 | } | |
103 | ||
104 | // ------------------------------------------------------ // | |
105 | // -------------- METHOD RELATED TO ACTIONS ------------- // | |
106 | // ------------------------------------------------------ // | |
107 | ||
108 | public void setNumberOfActions(int numberOfActions) { | |
109 |
1
1. setNumberOfActions : removed call to com/takenoko/engine/ActionManager::setNumberOfActions → KILLED |
this.actionManager.setNumberOfActions(numberOfActions); |
110 | } | |
111 | ||
112 | /** | |
113 | * @return number of actions the bot can do in a turn | |
114 | */ | |
115 | protected int getNumberOfActions() { | |
116 |
1
1. getNumberOfActions : replaced int return with 0 for com/takenoko/engine/BotState::getNumberOfActions → KILLED |
return this.actionManager.getNumberOfActions(); |
117 | } | |
118 | ||
119 | /** | |
120 | * Return the list of available actions. If actions of FORCED type are available, only these | |
121 | * actions are returned else all available actions are returned. | |
122 | * | |
123 | * @return the list of available actions | |
124 | */ | |
125 | public List<Class<? extends Action>> getAvailableActions() { | |
126 |
1
1. getAvailableActions : replaced return value with Collections.emptyList for com/takenoko/engine/BotState::getAvailableActions → KILLED |
return this.actionManager.getAvailableActions(); |
127 | } | |
128 | ||
129 | /** | |
130 | * add an action to the list of available actions | |
131 | * | |
132 | * @param action the action to add | |
133 | */ | |
134 | public void addAvailableAction(Class<? extends Action> action) { | |
135 |
1
1. addAvailableAction : removed call to com/takenoko/engine/ActionManager::addAvailableAction → KILLED |
this.actionManager.addAvailableAction(action); |
136 | } | |
137 | ||
138 | /** add an action to the number of actions to plau this turn */ | |
139 | public void addAction() { | |
140 |
1
1. addAction : removed call to com/takenoko/engine/ActionManager::addAction → TIMED_OUT |
this.actionManager.addAction(); |
141 | } | |
142 | ||
143 | /** | |
144 | * update an action in available actions | |
145 | * | |
146 | * @param action the action to update | |
147 | * @param actionResult the result of the action | |
148 | */ | |
149 | public void updateAvailableActions(Action action, ActionResult actionResult) { | |
150 |
1
1. updateAvailableActions : removed call to com/takenoko/engine/ActionManager::updateAvailableActions → KILLED |
this.actionManager.updateAvailableActions(action, actionResult); |
151 | } | |
152 | ||
153 | /** | |
154 | * reset the available actions | |
155 | * | |
156 | * @param board the board | |
157 | */ | |
158 | public void resetAvailableActions(Board board) { | |
159 |
1
1. resetAvailableActions : removed call to com/takenoko/engine/ActionManager::resetAvailableActions → TIMED_OUT |
this.actionManager.resetAvailableActions(board, this); |
160 | } | |
161 | ||
162 | /** | |
163 | * get the list of already done actions | |
164 | * | |
165 | * @return the list of already done actions | |
166 | */ | |
167 | public List<Class<? extends Action>> getAlreadyDoneActions() { | |
168 |
1
1. getAlreadyDoneActions : replaced return value with Collections.emptyList for com/takenoko/engine/BotState::getAlreadyDoneActions → TIMED_OUT |
return this.actionManager.getAlreadyDoneActions(); |
169 | } | |
170 | ||
171 | // ------------------------------------------------------ // | |
172 | // ------------ METHOD RELATED TO OBJECTIVES ------------ // | |
173 | // ------------------------------------------------------ // | |
174 | ||
175 | /** | |
176 | * Get the current Objectives of the bot | |
177 | * | |
178 | * @return Objectives | |
179 | */ | |
180 | public List<Objective> getObjectives() { | |
181 |
1
1. getObjectives : replaced return value with Collections.emptyList for com/takenoko/engine/BotState::getObjectives → KILLED |
return objectiveManager.getObjectives(); |
182 | } | |
183 | ||
184 | /** | |
185 | * Set the current Objective of the bot | |
186 | * | |
187 | * @param objective the objectives | |
188 | */ | |
189 | public void addObjective(Objective objective) { | |
190 |
1
1. addObjective : removed call to com/takenoko/engine/ObjectiveManager::addObjective → KILLED |
this.objectiveManager.addObjective(objective); |
191 | } | |
192 | ||
193 | /** | |
194 | * get the score of the achieved objectives | |
195 | * | |
196 | * @return the score of the achieved objectives | |
197 | */ | |
198 | public int getObjectiveScore() { | |
199 |
1
1. getObjectiveScore : replaced int return with 0 for com/takenoko/engine/BotState::getObjectiveScore → KILLED |
return objectiveManager.getObjectiveScore(); |
200 | } | |
201 | ||
202 | /** | |
203 | * Get the list of the redeemed objectives | |
204 | * | |
205 | * @return the list of the redeemed objectives | |
206 | */ | |
207 | public List<Objective> getRedeemedObjectives() { | |
208 |
1
1. getRedeemedObjectives : replaced return value with Collections.emptyList for com/takenoko/engine/BotState::getRedeemedObjectives → TIMED_OUT |
return objectiveManager.getRedeemedObjectives(); |
209 | } | |
210 | ||
211 | /** | |
212 | * get the list of achieved objectives | |
213 | * | |
214 | * @return the list of achieved objectives | |
215 | */ | |
216 | public List<Objective> getAchievedObjectives() { | |
217 |
1
1. getAchievedObjectives : replaced return value with Collections.emptyList for com/takenoko/engine/BotState::getAchievedObjectives → TIMED_OUT |
return objectiveManager.getAchievedObjectives(); |
218 | } | |
219 | ||
220 | /** | |
221 | * for each objective, check if it is achieved | |
222 | * | |
223 | * @param board the board | |
224 | */ | |
225 | public void verifyObjectives(Board board) { | |
226 |
1
1. verifyObjectives : removed call to com/takenoko/engine/ObjectiveManager::verifyObjectives → NO_COVERAGE |
objectiveManager.verifyObjectives(board, this); |
227 | } | |
228 | ||
229 | /** | |
230 | * set an objective as not achieved | |
231 | * | |
232 | * @param objective the objective | |
233 | */ | |
234 | public void setObjectiveNotAchieved(Objective objective) { | |
235 |
1
1. setObjectiveNotAchieved : removed call to com/takenoko/engine/ObjectiveManager::setObjectiveNotAchieved → NO_COVERAGE |
this.objectiveManager.setObjectiveNotAchieved(objective); |
236 | } | |
237 | ||
238 | /** | |
239 | * set an objective as achieved | |
240 | * | |
241 | * @param objective the objective | |
242 | */ | |
243 | public void setObjectiveAchieved(Objective objective) { | |
244 |
1
1. setObjectiveAchieved : removed call to com/takenoko/engine/ObjectiveManager::setObjectiveAchieved → TIMED_OUT |
this.objectiveManager.setObjectiveAchieved(objective); |
245 | } | |
246 | ||
247 | /** | |
248 | * redeem an objective | |
249 | * | |
250 | * @param objective the objective | |
251 | */ | |
252 | public void redeemObjective(Objective objective) { | |
253 |
1
1. redeemObjective : removed call to com/takenoko/engine/ObjectiveManager::redeemObjective → KILLED |
this.objectiveManager.redeemObjective(objective, this); |
254 | } | |
255 | ||
256 | /** | |
257 | * Returns the sum of the points of all the panda objectives | |
258 | * | |
259 | * @return the sum of the points of all the panda objectives | |
260 | */ | |
261 | public int getPandaObjectiveScore() { | |
262 |
1
1. getPandaObjectiveScore : replaced int return with 0 for com/takenoko/engine/BotState::getPandaObjectiveScore → KILLED |
return this.objectiveManager.getPandaObjectiveScore(); |
263 | } | |
264 | ||
265 | /** | |
266 | * Set the starting deck | |
267 | * | |
268 | * @param objectives list of objectives | |
269 | */ | |
270 | public void setStartingDeck(List<Objective> objectives) { | |
271 |
1
1. setStartingDeck : removed call to com/takenoko/engine/ObjectiveManager::setStartingDeck → TIMED_OUT |
this.objectiveManager.setStartingDeck(objectives); |
272 | } | |
273 | ||
274 | public List<Objective> getNotAchievedObjectives() { | |
275 |
1
1. getNotAchievedObjectives : replaced return value with Collections.emptyList for com/takenoko/engine/BotState::getNotAchievedObjectives → TIMED_OUT |
return this.objectiveManager.getNotAchievedObjectives(); |
276 | } | |
277 | } | |
Mutations | ||
45 |
1.1 |
|
46 |
1.1 |
|
47 |
1.1 |
|
56 |
1.1 |
|
61 |
1.1 2.2 |
|
62 |
1.1 2.2 3.3 |
|
64 |
1.1 2.2 |
|
65 |
1.1 |
|
66 |
1.1 |
|
71 |
1.1 |
|
80 |
1.1 |
|
81 |
1.1 |
|
92 |
1.1 |
|
101 |
1.1 |
|
109 |
1.1 |
|
116 |
1.1 |
|
126 |
1.1 |
|
135 |
1.1 |
|
140 |
1.1 |
|
150 |
1.1 |
|
159 |
1.1 |
|
168 |
1.1 |
|
181 |
1.1 |
|
190 |
1.1 |
|
199 |
1.1 |
|
208 |
1.1 |
|
217 |
1.1 |
|
226 |
1.1 |
|
235 |
1.1 |
|
244 |
1.1 |
|
253 |
1.1 |
|
262 |
1.1 |
|
271 |
1.1 |
|
275 |
1.1 |