1 | package com.takenoko.stats; | |
2 | ||
3 | import com.takenoko.layers.tile.TileColor; | |
4 | import com.takenoko.objective.Objective; | |
5 | import com.takenoko.objective.ObjectiveType; | |
6 | import java.util.*; | |
7 | import org.apache.commons.lang3.tuple.MutablePair; | |
8 | ||
9 | /** This class represents an extended list of statistics for a specific BotManager */ | |
10 | public class SingleBotStatistics { | |
11 | public static final String WINS = "\t -Wins : "; | |
12 | public static final String LOSSES = "\t -Losses : "; | |
13 | public static final String IRRIGATIONS_PLACED = "\t -Irrigations Placed : "; | |
14 | public static final String FINAL_SCORE = "\t -Final Score : "; | |
15 | private int totalNbOfAction; | |
16 | private final Map<String, Integer> numericStats; | |
17 | private final Map<ObjectiveType, Integer> objectivesRedeemed; | |
18 | private final Map<TileColor, MutablePair<Integer, Integer>> | |
19 | bambooCounter; // Left eaten, right grown | |
20 | private final Map<TileColor, Integer> tilesPlaced; | |
21 | private final Map<String, MutablePair<Integer, Integer>> weathers; // Left applied, right rolled | |
22 | private final Map<String, Integer> actions; | |
23 | ||
24 | public SingleBotStatistics( | |
25 | Map<String, Integer> numericStats, | |
26 | Map<ObjectiveType, Integer> objectivesRedeemed, | |
27 | Map<TileColor, MutablePair<Integer, Integer>> bambooCounter, | |
28 | Map<TileColor, Integer> tilesPlaced, | |
29 | Map<String, MutablePair<Integer, Integer>> weathers, | |
30 | Map<String, Integer> actions, | |
31 | int totalNbOfAction) { | |
32 | this.numericStats = numericStats; | |
33 | this.objectivesRedeemed = objectivesRedeemed; | |
34 | this.bambooCounter = bambooCounter; | |
35 | this.tilesPlaced = tilesPlaced; | |
36 | this.weathers = weathers; | |
37 | this.actions = actions; | |
38 | this.totalNbOfAction = totalNbOfAction; | |
39 | numericStats.put(WINS, 0); | |
40 | numericStats.put(LOSSES, 0); | |
41 | numericStats.put(FINAL_SCORE, 0); | |
42 | numericStats.put(IRRIGATIONS_PLACED, 0); | |
43 | } | |
44 | ||
45 | public SingleBotStatistics(SingleBotStatistics singleBotStatistics) { | |
46 | this( | |
47 | singleBotStatistics.numericStats, | |
48 | singleBotStatistics.objectivesRedeemed, | |
49 | singleBotStatistics.bambooCounter, | |
50 | singleBotStatistics.tilesPlaced, | |
51 | singleBotStatistics.weathers, | |
52 | singleBotStatistics.actions, | |
53 | singleBotStatistics.totalNbOfAction); | |
54 | } | |
55 | ||
56 | public SingleBotStatistics(int wins, int losses, int finalScore) { | |
57 | this(); | |
58 | numericStats.replace(WINS, wins); | |
59 | numericStats.replace(LOSSES, losses); | |
60 | numericStats.replace(FINAL_SCORE, finalScore); | |
61 | } | |
62 | ||
63 | public SingleBotStatistics() { | |
64 | this( | |
65 | new HashMap<>(), | |
66 | new HashMap<>(), | |
67 | new HashMap<>(), | |
68 | new HashMap<>(), | |
69 | new HashMap<>(), | |
70 | new HashMap<>(), | |
71 | 0); | |
72 | } | |
73 | ||
74 | public void incrementWins() { | |
75 |
1
1. incrementWins : Replaced integer addition with subtraction → KILLED |
numericStats.replace(WINS, numericStats.get(WINS) + 1); |
76 | } | |
77 | ||
78 | public void incrementLosses() { | |
79 |
1
1. incrementLosses : Replaced integer addition with subtraction → KILLED |
numericStats.replace(LOSSES, numericStats.get(LOSSES) + 1); |
80 | } | |
81 | ||
82 | public void incrementIrrigationsPlaced() { | |
83 |
1
1. incrementIrrigationsPlaced : Replaced integer addition with subtraction → KILLED |
numericStats.replace(IRRIGATIONS_PLACED, numericStats.get(IRRIGATIONS_PLACED) + 1); |
84 | } | |
85 | ||
86 | public void updateScore(int toAdd) { | |
87 |
1
1. updateScore : Replaced integer addition with subtraction → KILLED |
numericStats.replace(FINAL_SCORE, numericStats.get(FINAL_SCORE) + toAdd); |
88 | } | |
89 | ||
90 | public void updateObjectivesRedeemed(Objective objective) { | |
91 |
1
1. updateObjectivesRedeemed : negated conditional → KILLED |
if (objective == null) { |
92 | throw new IllegalArgumentException(); | |
93 | } | |
94 | ObjectiveType objectiveType = objective.getType(); | |
95 |
1
1. updateObjectivesRedeemed : negated conditional → KILLED |
if (objectivesRedeemed.containsKey(objectiveType)) { |
96 |
1
1. updateObjectivesRedeemed : Replaced integer addition with subtraction → KILLED |
objectivesRedeemed.replace(objectiveType, objectivesRedeemed.get(objectiveType) + 1); |
97 | } else { | |
98 | objectivesRedeemed.put(objectiveType, 1); | |
99 | } | |
100 | } | |
101 | ||
102 | public void updateEatenBambooCounter(TileColor tileColor) { | |
103 |
1
1. updateEatenBambooCounter : negated conditional → KILLED |
if (tileColor == null) { |
104 | throw new IllegalArgumentException(); | |
105 | } | |
106 |
1
1. updateEatenBambooCounter : negated conditional → KILLED |
if (bambooCounter.containsKey(tileColor)) { |
107 | bambooCounter.put( | |
108 | tileColor, | |
109 | MutablePair.of( | |
110 |
1
1. updateEatenBambooCounter : Replaced integer addition with subtraction → KILLED |
bambooCounter.get(tileColor).getLeft() + 1, |
111 | bambooCounter.get(tileColor).getRight())); | |
112 | } else { | |
113 | bambooCounter.put(tileColor, MutablePair.of(1, 0)); | |
114 | } | |
115 | } | |
116 | ||
117 | public void updatePlantedBambooCounter(TileColor tileColor, int count) { | |
118 |
1
1. updatePlantedBambooCounter : negated conditional → KILLED |
if (tileColor == null) { |
119 | throw new IllegalArgumentException(); | |
120 | } | |
121 |
1
1. updatePlantedBambooCounter : negated conditional → TIMED_OUT |
if (count == 0) { |
122 | count = 1; | |
123 | } | |
124 |
1
1. updatePlantedBambooCounter : negated conditional → KILLED |
if (bambooCounter.containsKey(tileColor)) { |
125 | bambooCounter.put( | |
126 | tileColor, | |
127 | MutablePair.of( | |
128 | bambooCounter.get(tileColor).getLeft(), | |
129 |
1
1. updatePlantedBambooCounter : Replaced integer addition with subtraction → KILLED |
bambooCounter.get(tileColor).getRight() + count)); |
130 | } else { | |
131 | bambooCounter.put(tileColor, MutablePair.of(0, count)); | |
132 | } | |
133 | } | |
134 | ||
135 | public void updateTilesPlacedCounter(TileColor tileColor) { | |
136 |
1
1. updateTilesPlacedCounter : negated conditional → KILLED |
if (tileColor == null) { |
137 | throw new IllegalArgumentException(); | |
138 | } | |
139 |
1
1. updateTilesPlacedCounter : negated conditional → KILLED |
if (tilesPlaced.containsKey(tileColor)) { |
140 |
1
1. updateTilesPlacedCounter : Replaced integer addition with subtraction → KILLED |
tilesPlaced.put(tileColor, tilesPlaced.get(tileColor) + 1); |
141 | } else { | |
142 | tilesPlaced.put(tileColor, 1); | |
143 | } | |
144 | } | |
145 | ||
146 | public void updateWeathersRolled(String weather) { | |
147 |
1
1. updateWeathersRolled : negated conditional → KILLED |
if (weather == null) { |
148 | throw new IllegalArgumentException(); | |
149 | } | |
150 |
1
1. updateWeathersRolled : negated conditional → KILLED |
if (weathers.containsKey(weather)) { |
151 | weathers.replace( | |
152 | weather, | |
153 | MutablePair.of( | |
154 |
1
1. updateWeathersRolled : Replaced integer addition with subtraction → KILLED |
weathers.get(weather).getLeft(), weathers.get(weather).getRight() + 1)); |
155 | } else { | |
156 | weathers.put(weather, MutablePair.of(0, 1)); | |
157 | } | |
158 | } | |
159 | ||
160 | public void updateWeathersApplied(String weather) { | |
161 |
1
1. updateWeathersApplied : negated conditional → KILLED |
if (weather == null) { |
162 | throw new IllegalArgumentException(); | |
163 | } | |
164 |
1
1. updateWeathersApplied : negated conditional → KILLED |
if (weathers.containsKey(weather)) |
165 | weathers.replace( | |
166 | weather, | |
167 | MutablePair.of( | |
168 |
1
1. updateWeathersApplied : Replaced integer addition with subtraction → KILLED |
weathers.get(weather).getLeft() + 1, weathers.get(weather).getRight())); |
169 | else { | |
170 | weathers.put(weather, MutablePair.of(1, 0)); | |
171 | } | |
172 | } | |
173 | ||
174 | public void updateActions(String action) { | |
175 |
1
1. updateActions : negated conditional → KILLED |
if (action == null) { |
176 | throw new IllegalArgumentException(); | |
177 | } | |
178 |
1
1. updateActions : Replaced integer addition with subtraction → KILLED |
totalNbOfAction++; |
179 |
1
1. updateActions : negated conditional → KILLED |
if (actions.containsKey(action)) { |
180 |
1
1. updateActions : Replaced integer addition with subtraction → KILLED |
actions.replace(action, actions.get(action) + 1); |
181 | } else { | |
182 | actions.put(action, 1); | |
183 | } | |
184 | } | |
185 | ||
186 | public SingleBotStatistics copy() { | |
187 |
1
1. copy : replaced return value with null for com/takenoko/stats/SingleBotStatistics::copy → NO_COVERAGE |
return new SingleBotStatistics(this); |
188 | } | |
189 | ||
190 | public void reset() { | |
191 |
1
1. reset : removed call to java/util/Map::clear → TIMED_OUT |
this.objectivesRedeemed.clear(); |
192 |
1
1. reset : removed call to java/util/Map::clear → TIMED_OUT |
this.bambooCounter.clear(); |
193 | } | |
194 | ||
195 | @Override | |
196 | public String toString() { | |
197 | StringBuilder singleBotStat = new StringBuilder(); | |
198 | String lineJump = "\n \t \t \t"; | |
199 | String indentation = "\t\t* "; | |
200 | TreeMap<ObjectiveType, Integer> sortedObjectives = new TreeMap<>(objectivesRedeemed); | |
201 | TreeMap<TileColor, MutablePair<Integer, Integer>> sortedBambooCounter = | |
202 | new TreeMap<>(bambooCounter); | |
203 | TreeMap<TileColor, Integer> sortedTilesPlaced = new TreeMap<>(tilesPlaced); | |
204 | TreeMap<String, Integer> sortedActions = new TreeMap<>(actions); | |
205 | singleBotStat | |
206 | .append(WINS) | |
207 | .append(numericStats.get(WINS)) | |
208 | .append(lineJump) | |
209 | .append(LOSSES) | |
210 | .append(numericStats.get(LOSSES)) | |
211 | .append(lineJump) | |
212 | .append(IRRIGATIONS_PLACED) | |
213 | .append(numericStats.get(IRRIGATIONS_PLACED)) | |
214 | .append(lineJump) | |
215 | .append(FINAL_SCORE) | |
216 | .append(numericStats.get(FINAL_SCORE)) | |
217 | .append(lineJump) | |
218 | .append("\t -Redeemed objectives : "); | |
219 | for (ObjectiveType objectiveType : sortedObjectives.keySet()) { | |
220 | singleBotStat | |
221 | .append(lineJump) | |
222 | .append(indentation) | |
223 | .append(objectiveType) | |
224 | .append(" : ") | |
225 | .append(objectivesRedeemed.get(objectiveType)); | |
226 | } | |
227 | singleBotStat.append(lineJump).append("\t -Bamboos eaten :"); | |
228 | for (TileColor tileColor : sortedBambooCounter.keySet()) { | |
229 | singleBotStat | |
230 | .append(lineJump) | |
231 | .append(indentation) | |
232 | .append(tileColor) | |
233 | .append(" : ") | |
234 | .append(bambooCounter.get(tileColor).getLeft()); | |
235 | } | |
236 | singleBotStat.append(lineJump).append("\t -Bamboos grown :"); | |
237 | for (TileColor tileColor : sortedBambooCounter.keySet()) { | |
238 | singleBotStat | |
239 | .append(lineJump) | |
240 | .append(indentation) | |
241 | .append(tileColor) | |
242 | .append(" : ") | |
243 | .append(bambooCounter.get(tileColor).getRight()); | |
244 | } | |
245 | singleBotStat.append(lineJump).append("\t -Tiles placed :"); | |
246 | for (TileColor tileColor : sortedTilesPlaced.keySet()) { | |
247 | singleBotStat | |
248 | .append(lineJump) | |
249 | .append(indentation) | |
250 | .append(tileColor) | |
251 | .append(" : ") | |
252 | .append(tilesPlaced.get(tileColor)); | |
253 | } | |
254 | singleBotStat.append(lineJump).append("\t -Rolled Weathers :"); | |
255 | for (Map.Entry<String, MutablePair<Integer, Integer>> entry : weathers.entrySet()) { | |
256 | singleBotStat | |
257 | .append(lineJump) | |
258 | .append(indentation) | |
259 | .append(entry.getKey()) | |
260 | .append(" : ") | |
261 | .append(entry.getValue().getRight()); | |
262 | } | |
263 | singleBotStat.append(lineJump).append("\t -Applied Weathers :"); | |
264 | for (Map.Entry<String, MutablePair<Integer, Integer>> entry : weathers.entrySet()) { | |
265 | singleBotStat | |
266 | .append(lineJump) | |
267 | .append(indentation) | |
268 | .append(entry.getKey()) | |
269 | .append(" : ") | |
270 | .append(entry.getValue().getLeft()); | |
271 | } | |
272 | singleBotStat.append(lineJump).append("\t -Average choice of action :"); | |
273 | for (Map.Entry<String, Integer> entry : sortedActions.entrySet()) { | |
274 | singleBotStat | |
275 | .append(lineJump) | |
276 | .append(indentation) | |
277 | .append(entry.getKey()) | |
278 | .append(" : ") | |
279 |
2
1. toString : Replaced float division with multiplication → TIMED_OUT 2. toString : Replaced float multiplication with division → TIMED_OUT |
.append((Float.valueOf(entry.getValue()) / totalNbOfAction) * 100) |
280 | .append("%"); | |
281 | } | |
282 |
1
1. toString : replaced return value with "" for com/takenoko/stats/SingleBotStatistics::toString → TIMED_OUT |
return singleBotStat.toString(); |
283 | } | |
284 | ||
285 | @Override | |
286 | public boolean equals(Object o) { | |
287 |
2
1. equals : negated conditional → SURVIVED 2. equals : replaced boolean return with false for com/takenoko/stats/SingleBotStatistics::equals → NO_COVERAGE |
if (this == o) return true; |
288 |
3
1. equals : replaced boolean return with true for com/takenoko/stats/SingleBotStatistics::equals → NO_COVERAGE 2. equals : negated conditional → KILLED 3. equals : negated conditional → KILLED |
if (o == null || getClass() != o.getClass()) return false; |
289 | SingleBotStatistics that = (SingleBotStatistics) o; | |
290 |
2
1. equals : replaced boolean return with true for com/takenoko/stats/SingleBotStatistics::equals → SURVIVED 2. equals : negated conditional → KILLED |
return totalNbOfAction == that.totalNbOfAction |
291 |
1
1. equals : negated conditional → KILLED |
&& numericStats.equals(that.numericStats) |
292 |
1
1. equals : negated conditional → KILLED |
&& objectivesRedeemed.equals(that.objectivesRedeemed) |
293 |
1
1. equals : negated conditional → KILLED |
&& bambooCounter.equals(that.bambooCounter) |
294 |
1
1. equals : negated conditional → KILLED |
&& tilesPlaced.equals(that.tilesPlaced) |
295 |
1
1. equals : negated conditional → KILLED |
&& weathers.equals(that.weathers) |
296 |
1
1. equals : negated conditional → KILLED |
&& actions.equals(that.actions); |
297 | } | |
298 | ||
299 | @Override | |
300 | public int hashCode() { | |
301 |
1
1. hashCode : replaced int return with 0 for com/takenoko/stats/SingleBotStatistics::hashCode → NO_COVERAGE |
return Objects.hash( |
302 | totalNbOfAction, | |
303 | numericStats, | |
304 | objectivesRedeemed, | |
305 | bambooCounter, | |
306 | tilesPlaced, | |
307 | weathers, | |
308 | actions); | |
309 | } | |
310 | ||
311 | public Map<String, Integer> getNumericStats() { | |
312 |
1
1. getNumericStats : replaced return value with Collections.emptyMap for com/takenoko/stats/SingleBotStatistics::getNumericStats → KILLED |
return numericStats; |
313 | } | |
314 | ||
315 | public int getTotalNbOfAction() { | |
316 |
1
1. getTotalNbOfAction : replaced int return with 0 for com/takenoko/stats/SingleBotStatistics::getTotalNbOfAction → KILLED |
return totalNbOfAction; |
317 | } | |
318 | ||
319 | public Map<ObjectiveType, Integer> getObjectivesRedeemed() { | |
320 |
1
1. getObjectivesRedeemed : replaced return value with Collections.emptyMap for com/takenoko/stats/SingleBotStatistics::getObjectivesRedeemed → KILLED |
return objectivesRedeemed; |
321 | } | |
322 | ||
323 | public Map<TileColor, MutablePair<Integer, Integer>> getBambooCounter() { | |
324 |
1
1. getBambooCounter : replaced return value with Collections.emptyMap for com/takenoko/stats/SingleBotStatistics::getBambooCounter → KILLED |
return bambooCounter; |
325 | } | |
326 | ||
327 | public Map<TileColor, Integer> getTilesPlaced() { | |
328 |
1
1. getTilesPlaced : replaced return value with Collections.emptyMap for com/takenoko/stats/SingleBotStatistics::getTilesPlaced → KILLED |
return tilesPlaced; |
329 | } | |
330 | ||
331 | public Map<String, MutablePair<Integer, Integer>> getWeathers() { | |
332 |
1
1. getWeathers : replaced return value with Collections.emptyMap for com/takenoko/stats/SingleBotStatistics::getWeathers → KILLED |
return weathers; |
333 | } | |
334 | ||
335 | public Map<String, Integer> getActions() { | |
336 |
1
1. getActions : replaced return value with Collections.emptyMap for com/takenoko/stats/SingleBotStatistics::getActions → KILLED |
return actions; |
337 | } | |
338 | ||
339 | public void addStatistics(SingleBotStatistics value) { | |
340 | for (Map.Entry<String, Integer> entry : value.getNumericStats().entrySet()) { | |
341 |
1
1. addStatistics : Replaced integer addition with subtraction → NO_COVERAGE |
numericStats.put(entry.getKey(), numericStats.get(entry.getKey()) + entry.getValue()); |
342 | } | |
343 |
1
1. addStatistics : Replaced integer addition with subtraction → NO_COVERAGE |
totalNbOfAction += value.getTotalNbOfAction(); |
344 | } | |
345 | ||
346 | public int getWins() { | |
347 |
1
1. getWins : replaced int return with 0 for com/takenoko/stats/SingleBotStatistics::getWins → SURVIVED |
return numericStats.get(WINS); |
348 | } | |
349 | ||
350 | public int getLosses() { | |
351 |
1
1. getLosses : replaced int return with 0 for com/takenoko/stats/SingleBotStatistics::getLosses → SURVIVED |
return numericStats.get(LOSSES); |
352 | } | |
353 | ||
354 | public int getFinalScore() { | |
355 |
1
1. getFinalScore : replaced int return with 0 for com/takenoko/stats/SingleBotStatistics::getFinalScore → SURVIVED |
return numericStats.get(FINAL_SCORE); |
356 | } | |
357 | } | |
Mutations | ||
75 |
1.1 |
|
79 |
1.1 |
|
83 |
1.1 |
|
87 |
1.1 |
|
91 |
1.1 |
|
95 |
1.1 |
|
96 |
1.1 |
|
103 |
1.1 |
|
106 |
1.1 |
|
110 |
1.1 |
|
118 |
1.1 |
|
121 |
1.1 |
|
124 |
1.1 |
|
129 |
1.1 |
|
136 |
1.1 |
|
139 |
1.1 |
|
140 |
1.1 |
|
147 |
1.1 |
|
150 |
1.1 |
|
154 |
1.1 |
|
161 |
1.1 |
|
164 |
1.1 |
|
168 |
1.1 |
|
175 |
1.1 |
|
178 |
1.1 |
|
179 |
1.1 |
|
180 |
1.1 |
|
187 |
1.1 |
|
191 |
1.1 |
|
192 |
1.1 |
|
279 |
1.1 2.2 |
|
282 |
1.1 |
|
287 |
1.1 2.2 |
|
288 |
1.1 2.2 3.3 |
|
290 |
1.1 2.2 |
|
291 |
1.1 |
|
292 |
1.1 |
|
293 |
1.1 |
|
294 |
1.1 |
|
295 |
1.1 |
|
296 |
1.1 |
|
301 |
1.1 |
|
312 |
1.1 |
|
316 |
1.1 |
|
320 |
1.1 |
|
324 |
1.1 |
|
328 |
1.1 |
|
332 |
1.1 |
|
336 |
1.1 |
|
341 |
1.1 |
|
343 |
1.1 |
|
347 |
1.1 |
|
351 |
1.1 |
|
355 |
1.1 |