1 | package com.takenoko.engine; | |
2 | ||
3 | import com.takenoko.objective.Objective; | |
4 | import com.takenoko.objective.PandaObjective; | |
5 | import java.util.ArrayList; | |
6 | import java.util.List; | |
7 | import java.util.Objects; | |
8 | ||
9 | /** This class is used to manage the objectives of the bot. */ | |
10 | public class ObjectiveManager { | |
11 | private final List<Objective> objectives; | |
12 | private final List<Objective> achievedObjectives; | |
13 | private final List<Objective> redeemedObjectives; | |
14 | ||
15 | public ObjectiveManager() { | |
16 | this.objectives = new ArrayList<>(); | |
17 | this.achievedObjectives = new ArrayList<>(); | |
18 | this.redeemedObjectives = new ArrayList<>(); | |
19 | } | |
20 | ||
21 | public ObjectiveManager(ObjectiveManager objectiveManager) { | |
22 | this.objectives = new ArrayList<>(objectiveManager.objectives); | |
23 | this.achievedObjectives = new ArrayList<>(objectiveManager.achievedObjectives); | |
24 | this.redeemedObjectives = new ArrayList<>(objectiveManager.redeemedObjectives); | |
25 | } | |
26 | ||
27 | /** | |
28 | * Get the current Objectives of the bot | |
29 | * | |
30 | * @return Objectives | |
31 | */ | |
32 | public List<Objective> getObjectives() { | |
33 |
1
1. getObjectives : replaced return value with Collections.emptyList for com/takenoko/engine/ObjectiveManager::getObjectives → KILLED |
return new ArrayList<>(objectives); |
34 | } | |
35 | ||
36 | /** | |
37 | * get the score of the achieved objectives | |
38 | * | |
39 | * @return the score of the achieved objectives | |
40 | */ | |
41 | public int getObjectiveScore() { | |
42 |
1
1. getObjectiveScore : replaced int return with 0 for com/takenoko/engine/ObjectiveManager::getObjectiveScore → KILLED |
return redeemedObjectives.stream().mapToInt(Objective::getPoints).sum(); |
43 | } | |
44 | ||
45 | /** | |
46 | * Get the list of the redeemed objectives | |
47 | * | |
48 | * @return the list of the redeemed objectives | |
49 | */ | |
50 | public List<Objective> getRedeemedObjectives() { | |
51 |
1
1. getRedeemedObjectives : replaced return value with Collections.emptyList for com/takenoko/engine/ObjectiveManager::getRedeemedObjectives → TIMED_OUT |
return new ArrayList<>(redeemedObjectives); |
52 | } | |
53 | ||
54 | /** | |
55 | * get the list of achieved objectives | |
56 | * | |
57 | * @return the list of achieved objectives | |
58 | */ | |
59 | public List<Objective> getAchievedObjectives() { | |
60 |
1
1. getAchievedObjectives : replaced return value with Collections.emptyList for com/takenoko/engine/ObjectiveManager::getAchievedObjectives → TIMED_OUT |
return new ArrayList<>(achievedObjectives); |
61 | } | |
62 | ||
63 | /** | |
64 | * for each objective, check if it is achieved | |
65 | * | |
66 | * @param board the board | |
67 | * @param botState the bot manager | |
68 | */ | |
69 | public void verifyObjectives(Board board, BotState botState) { | |
70 | for (Objective objective : objectives) { | |
71 |
1
1. verifyObjectives : removed call to com/takenoko/objective/Objective::verify → TIMED_OUT |
objective.verify(board, botState); |
72 | } | |
73 | for (Objective objective : achievedObjectives) { | |
74 |
1
1. verifyObjectives : removed call to com/takenoko/objective/Objective::verify → TIMED_OUT |
objective.verify(board, botState); |
75 | } | |
76 | } | |
77 | ||
78 | /** | |
79 | * Set the current Objective of the bot | |
80 | * | |
81 | * @param objective the objectives | |
82 | */ | |
83 | public void addObjective(Objective objective) { | |
84 | this.objectives.add(objective); | |
85 | } | |
86 | ||
87 | /** | |
88 | * update the objectives | |
89 | * | |
90 | * @param board the board | |
91 | * @param botState the bot manager | |
92 | */ | |
93 | public void updateObjectives(Board board, BotState botState) { | |
94 |
1
1. updateObjectives : removed call to com/takenoko/engine/ObjectiveManager::verifyObjectives → TIMED_OUT |
verifyObjectives(board, botState); |
95 | ||
96 | // If objective is achieved, add it to the list of achieved objectives | |
97 | List<Objective> toAchieve = new ArrayList<>(); | |
98 | for (Objective objective : objectives) { | |
99 |
1
1. updateObjectives : negated conditional → TIMED_OUT |
if (objective.isAchieved()) { |
100 | toAchieve.add(objective); | |
101 | } | |
102 | } | |
103 | for (Objective objective : toAchieve) { | |
104 |
1
1. updateObjectives : removed call to com/takenoko/engine/ObjectiveManager::setObjectiveAchieved → TIMED_OUT |
setObjectiveAchieved(objective); |
105 | } | |
106 | ||
107 | // If objective is no more achievable, remove it from the list of objectives | |
108 | List<Objective> toRemove = new ArrayList<>(); | |
109 | for (Objective objective : achievedObjectives) { | |
110 |
1
1. updateObjectives : negated conditional → TIMED_OUT |
if (!objective.isAchieved()) { |
111 | toRemove.add(objective); | |
112 | } | |
113 | } | |
114 | for (Objective objective : toRemove) { | |
115 |
1
1. updateObjectives : removed call to com/takenoko/engine/ObjectiveManager::setObjectiveNotAchieved → TIMED_OUT |
setObjectiveNotAchieved(objective); |
116 | } | |
117 | } | |
118 | ||
119 | /** | |
120 | * set an objective as not achieved | |
121 | * | |
122 | * @param objective the objective | |
123 | */ | |
124 | public void setObjectiveNotAchieved(Objective objective) { | |
125 | this.achievedObjectives.remove(objective); | |
126 | this.objectives.add(objective); | |
127 | } | |
128 | ||
129 | /** | |
130 | * set an objective as achieved | |
131 | * | |
132 | * @param objective the objective | |
133 | */ | |
134 | public void setObjectiveAchieved(Objective objective) { | |
135 | this.objectives.remove(objective); | |
136 | this.achievedObjectives.add(objective); | |
137 | } | |
138 | ||
139 | /** | |
140 | * redeem an objective | |
141 | * | |
142 | * @param objective the objective | |
143 | */ | |
144 | public void redeemObjective(Objective objective, BotState botState) { | |
145 | this.achievedObjectives.remove(objective); | |
146 |
1
1. redeemObjective : negated conditional → KILLED |
if (objective instanceof PandaObjective pandaObjective) { |
147 |
1
1. redeemObjective : removed call to com/takenoko/inventory/Inventory::useBamboo → TIMED_OUT |
botState.getInventory().useBamboo(pandaObjective.getBambooTarget()); |
148 | } | |
149 | this.redeemedObjectives.add(objective); | |
150 | } | |
151 | ||
152 | /** | |
153 | * Returns the sum of the points of all the panda objectives | |
154 | * | |
155 | * @return the sum of the points of all the panda objectives | |
156 | */ | |
157 | public int getPandaObjectiveScore() { | |
158 |
1
1. getPandaObjectiveScore : replaced int return with 0 for com/takenoko/engine/ObjectiveManager::getPandaObjectiveScore → KILLED |
return redeemedObjectives.stream() |
159 | .filter(PandaObjective.class::isInstance) | |
160 | .mapToInt(Objective::getPoints) | |
161 | .sum(); | |
162 | } | |
163 | ||
164 | /** | |
165 | * Set the starting deck for a bot | |
166 | * | |
167 | * @param objectives list of objectives | |
168 | */ | |
169 | public void setStartingDeck(List<Objective> objectives) { | |
170 | this.objectives.addAll(objectives); | |
171 | } | |
172 | ||
173 | /** | |
174 | * Return a copy of the current ObjectiveManager | |
175 | * | |
176 | * @return ObjectiveManager | |
177 | */ | |
178 | public ObjectiveManager copy() { | |
179 |
1
1. copy : replaced return value with null for com/takenoko/engine/ObjectiveManager::copy → NO_COVERAGE |
return new ObjectiveManager(this); |
180 | } | |
181 | ||
182 | /** Reset all the attributes of the ObjectiveManager */ | |
183 | public void reset() { | |
184 |
1
1. reset : removed call to java/util/List::clear → TIMED_OUT |
this.objectives.clear(); |
185 |
1
1. reset : removed call to java/util/List::clear → TIMED_OUT |
this.achievedObjectives.clear(); |
186 |
1
1. reset : removed call to java/util/List::clear → TIMED_OUT |
this.redeemedObjectives.clear(); |
187 | } | |
188 | ||
189 | @Override | |
190 | public boolean equals(Object o) { | |
191 |
2
1. equals : negated conditional → SURVIVED 2. equals : replaced boolean return with false for com/takenoko/engine/ObjectiveManager::equals → NO_COVERAGE |
if (this == o) return true; |
192 |
3
1. equals : replaced boolean return with true for com/takenoko/engine/ObjectiveManager::equals → NO_COVERAGE 2. equals : negated conditional → KILLED 3. equals : negated conditional → KILLED |
if (o == null || getClass() != o.getClass()) return false; |
193 | ObjectiveManager that = (ObjectiveManager) o; | |
194 |
2
1. equals : replaced boolean return with true for com/takenoko/engine/ObjectiveManager::equals → SURVIVED 2. equals : negated conditional → KILLED |
return Objects.equals(objectives, that.objectives) |
195 |
1
1. equals : negated conditional → KILLED |
&& Objects.equals(achievedObjectives, that.achievedObjectives) |
196 |
1
1. equals : negated conditional → KILLED |
&& Objects.equals(redeemedObjectives, that.redeemedObjectives); |
197 | } | |
198 | ||
199 | @Override | |
200 | public int hashCode() { | |
201 |
1
1. hashCode : replaced int return with 0 for com/takenoko/engine/ObjectiveManager::hashCode → SURVIVED |
return Objects.hash(objectives, achievedObjectives, redeemedObjectives); |
202 | } | |
203 | ||
204 | public List<Objective> getNotAchievedObjectives() { | |
205 |
1
1. getNotAchievedObjectives : replaced return value with Collections.emptyList for com/takenoko/engine/ObjectiveManager::getNotAchievedObjectives → TIMED_OUT |
return new ArrayList<>( |
206 |
2
1. lambda$getNotAchievedObjectives$0 : negated conditional → TIMED_OUT 2. lambda$getNotAchievedObjectives$0 : replaced boolean return with true for com/takenoko/engine/ObjectiveManager::lambda$getNotAchievedObjectives$0 → TIMED_OUT |
objectives.stream().filter(objective -> !objective.isAchieved()).toList()); |
207 | } | |
208 | } | |
Mutations | ||
33 |
1.1 |
|
42 |
1.1 |
|
51 |
1.1 |
|
60 |
1.1 |
|
71 |
1.1 |
|
74 |
1.1 |
|
94 |
1.1 |
|
99 |
1.1 |
|
104 |
1.1 |
|
110 |
1.1 |
|
115 |
1.1 |
|
146 |
1.1 |
|
147 |
1.1 |
|
158 |
1.1 |
|
179 |
1.1 |
|
184 |
1.1 |
|
185 |
1.1 |
|
186 |
1.1 |
|
191 |
1.1 2.2 |
|
192 |
1.1 2.2 3.3 |
|
194 |
1.1 2.2 |
|
195 |
1.1 |
|
196 |
1.1 |
|
201 |
1.1 |
|
205 |
1.1 |
|
206 |
1.1 2.2 |