| 1 | package com.takenoko.stats; | |
| 2 | ||
| 3 | import com.takenoko.actions.Action; | |
| 4 | import com.takenoko.actions.actors.MoveGardenerAction; | |
| 5 | import com.takenoko.actions.actors.MovePandaAction; | |
| 6 | import com.takenoko.actions.irrigation.PlaceIrrigationAction; | |
| 7 | import com.takenoko.actions.irrigation.StoreIrrigationInInventoryAction; | |
| 8 | import com.takenoko.actions.objective.DrawObjectiveAction; | |
| 9 | import com.takenoko.actions.tile.PlaceTileAction; | |
| 10 | import com.takenoko.bot.utils.GameProgress; | |
| 11 | import com.takenoko.engine.HistoryItem; | |
| 12 | import com.takenoko.engine.TurnHistory; | |
| 13 | import com.takenoko.objective.Objective; | |
| 14 | import com.takenoko.objective.ObjectiveType; | |
| 15 | import java.util.HashMap; | |
| 16 | import java.util.List; | |
| 17 | import java.util.Map; | |
| 18 | import java.util.Objects; | |
| 19 | ||
| 20 | public class GameProgressStatistics { | |
| 21 | private final GameProgress gameProgress; | |
| 22 | private int totalNbOfRounds = 0; | |
| 23 | private int totalNbOfAction = 0; | |
| 24 | private final HashMap<String, Float> actions = new HashMap<>(); | |
| 25 | private int totalNbOfRedeemedObjectives = 0; | |
| 26 | private final HashMap<ObjectiveType, Float> objectives = new HashMap<>(); | |
| 27 | ||
| 28 | public GameProgressStatistics(GameProgress gameProgress) { | |
| 29 | this.gameProgress = gameProgress; | |
| 30 | actions.put(MovePandaAction.class.getSimpleName(), 0F); | |
| 31 | actions.put(MoveGardenerAction.class.getSimpleName(), 0F); | |
| 32 | actions.put(PlaceIrrigationAction.class.getSimpleName(), 0F); | |
| 33 | actions.put(PlaceTileAction.class.getSimpleName(), 0F); | |
| 34 | actions.put(StoreIrrigationInInventoryAction.class.getSimpleName(), 0F); | |
| 35 | actions.put(DrawObjectiveAction.class.getSimpleName(), 0F); | |
| 36 | } | |
| 37 | ||
| 38 | public void incrementNbOfRounds() { | |
| 39 |
1
1. incrementNbOfRounds : Replaced integer addition with subtraction → TIMED_OUT |
totalNbOfRounds++; |
| 40 | } | |
| 41 | ||
| 42 | public void updateActions(Action action) { | |
| 43 |
1
1. updateActions : negated conditional → KILLED |
if (action == null) { |
| 44 | throw new IllegalArgumentException(); | |
| 45 | } | |
| 46 |
1
1. updateActions : negated conditional → KILLED |
if (actions.containsKey(action.getClass().getSimpleName())) { |
| 47 |
1
1. updateActions : Replaced integer addition with subtraction → TIMED_OUT |
totalNbOfAction++; |
| 48 | actions.replace( | |
| 49 | action.getClass().getSimpleName(), | |
| 50 |
1
1. updateActions : Replaced float addition with subtraction → TIMED_OUT |
actions.get(action.getClass().getSimpleName()) + 1); |
| 51 | } | |
| 52 | } | |
| 53 | ||
| 54 | public Float actionPercentage(String action) { | |
| 55 | Float totalOfAction = actions.get(action); | |
| 56 |
3
1. actionPercentage : Replaced float division with multiplication → TIMED_OUT 2. actionPercentage : Replaced float multiplication with division → TIMED_OUT 3. actionPercentage : replaced Float return value with 0 for com/takenoko/stats/GameProgressStatistics::actionPercentage → TIMED_OUT |
return (totalOfAction / totalNbOfAction) * 100; |
| 57 | } | |
| 58 | ||
| 59 | public Float actionAverage(String action) { | |
| 60 | Float totalOfAction = actions.get(action); | |
| 61 |
2
1. actionAverage : Replaced float division with multiplication → TIMED_OUT 2. actionAverage : replaced Float return value with 0 for com/takenoko/stats/GameProgressStatistics::actionAverage → TIMED_OUT |
return (totalOfAction / totalNbOfRounds); |
| 62 | } | |
| 63 | ||
| 64 | public void updateRedeemedOneObjective(Objective objective) { | |
| 65 |
1
1. updateRedeemedOneObjective : negated conditional → KILLED |
if (objective == null) { |
| 66 | throw new IllegalArgumentException(); | |
| 67 | } | |
| 68 |
1
1. updateRedeemedOneObjective : Replaced integer addition with subtraction → TIMED_OUT |
totalNbOfRedeemedObjectives++; |
| 69 |
1
1. updateRedeemedOneObjective : negated conditional → KILLED |
if (objectives.containsKey(objective.getType())) { |
| 70 |
1
1. updateRedeemedOneObjective : Replaced float addition with subtraction → TIMED_OUT |
objectives.replace(objective.getType(), objectives.get(objective.getType()) + 1); |
| 71 | } else { | |
| 72 | objectives.put(objective.getType(), 1F); | |
| 73 | } | |
| 74 | } | |
| 75 | ||
| 76 | public Float objectiveAverage(ObjectiveType objectiveTypes) { | |
| 77 | Float totalOfRedeemedObjective = objectives.get(objectiveTypes); | |
| 78 |
2
1. objectiveAverage : Replaced float division with multiplication → TIMED_OUT 2. objectiveAverage : replaced Float return value with 0 for com/takenoko/stats/GameProgressStatistics::objectiveAverage → TIMED_OUT |
return (totalOfRedeemedObjective / totalNbOfRounds); |
| 79 | } | |
| 80 | ||
| 81 | public void updateRedeemedObjectives(List<Objective> objectiveList) { | |
| 82 | for (Objective objective : objectiveList) { | |
| 83 |
1
1. updateRedeemedObjectives : removed call to com/takenoko/stats/GameProgressStatistics::updateRedeemedOneObjective → TIMED_OUT |
updateRedeemedOneObjective(objective); |
| 84 | } | |
| 85 | } | |
| 86 | ||
| 87 | @Override | |
| 88 | public String toString() { | |
| 89 | StringBuilder statistics = new StringBuilder(); | |
| 90 | String indent = "\t\t"; | |
| 91 | String indentedLineJump = "\n" + indent; | |
| 92 | String doubleIndentedLineJump = indentedLineJump + "\t\t"; | |
| 93 | statistics | |
| 94 | .append("****") | |
| 95 | .append(gameProgress) | |
| 96 | .append("****") | |
| 97 | .append(indentedLineJump) | |
| 98 | .append("Total number of rounds : ") | |
| 99 | .append(totalNbOfRounds) | |
| 100 | .append(indent) | |
| 101 | .append("Actions performed : ") | |
| 102 | .append(totalNbOfAction); | |
| 103 | for (String action : actions.keySet()) { | |
| 104 | statistics | |
| 105 | .append(doubleIndentedLineJump) | |
| 106 | .append(action) | |
| 107 | .append("\t Choice Percentage : ") | |
| 108 | .append(actionPercentage(action)) | |
| 109 | .append("% | ") | |
| 110 | .append("Average use per round : ") | |
| 111 | .append(actionAverage(action)); | |
| 112 | } | |
| 113 | statistics | |
| 114 | .append(indentedLineJump) | |
| 115 | .append("Objectives redeemed : ") | |
| 116 | .append(totalNbOfRedeemedObjectives); | |
| 117 | for (ObjectiveType objectiveType : objectives.keySet()) { | |
| 118 | statistics | |
| 119 | .append(doubleIndentedLineJump) | |
| 120 | .append(objectiveType) | |
| 121 | .append(" Average per round : ") | |
| 122 | .append(objectiveAverage(objectiveType)); | |
| 123 | } | |
| 124 |
1
1. toString : replaced return value with "" for com/takenoko/stats/GameProgressStatistics::toString → TIMED_OUT |
return statistics.toString(); |
| 125 | } | |
| 126 | ||
| 127 | public void update(TurnHistory turnHistory) { | |
| 128 | for (HistoryItem latestHistoryItems : turnHistory) { | |
| 129 |
1
1. update : removed call to com/takenoko/stats/GameProgressStatistics::updateRedeemedObjectives → TIMED_OUT |
updateRedeemedObjectives(latestHistoryItems.redeemedObjectives()); |
| 130 |
1
1. update : removed call to com/takenoko/stats/GameProgressStatistics::updateActions → TIMED_OUT |
updateActions(latestHistoryItems.action()); |
| 131 | } | |
| 132 | } | |
| 133 | ||
| 134 | @Override | |
| 135 | public boolean equals(Object o) { | |
| 136 |
2
1. equals : negated conditional → KILLED 2. equals : replaced boolean return with false for com/takenoko/stats/GameProgressStatistics::equals → KILLED |
if (this == o) return true; |
| 137 |
3
1. equals : negated conditional → KILLED 2. equals : negated conditional → KILLED 3. equals : replaced boolean return with true for com/takenoko/stats/GameProgressStatistics::equals → KILLED |
if (o == null || getClass() != o.getClass()) return false; |
| 138 | GameProgressStatistics that = (GameProgressStatistics) o; | |
| 139 |
5
1. equals : negated conditional → KILLED 2. equals : negated conditional → KILLED 3. equals : negated conditional → KILLED 4. equals : negated conditional → KILLED 5. equals : replaced boolean return with true for com/takenoko/stats/GameProgressStatistics::equals → KILLED |
return totalNbOfRounds == that.totalNbOfRounds |
| 140 | && totalNbOfAction == that.totalNbOfAction | |
| 141 | && totalNbOfRedeemedObjectives == that.totalNbOfRedeemedObjectives | |
| 142 | && gameProgress == that.gameProgress | |
| 143 |
1
1. equals : negated conditional → KILLED |
&& actions.equals(that.actions) |
| 144 |
1
1. equals : negated conditional → KILLED |
&& objectives.equals(that.objectives); |
| 145 | } | |
| 146 | ||
| 147 | @Override | |
| 148 | public int hashCode() { | |
| 149 |
1
1. hashCode : replaced int return with 0 for com/takenoko/stats/GameProgressStatistics::hashCode → KILLED |
return Objects.hash( |
| 150 | gameProgress, | |
| 151 | totalNbOfRounds, | |
| 152 | totalNbOfAction, | |
| 153 | actions, | |
| 154 | totalNbOfRedeemedObjectives, | |
| 155 | objectives); | |
| 156 | } | |
| 157 | ||
| 158 | public Map<String, Float> getActions() { | |
| 159 |
1
1. getActions : replaced return value with Collections.emptyMap for com/takenoko/stats/GameProgressStatistics::getActions → KILLED |
return actions; |
| 160 | } | |
| 161 | } | |
Mutations | ||
| 39 |
1.1 |
|
| 43 |
1.1 |
|
| 46 |
1.1 |
|
| 47 |
1.1 |
|
| 50 |
1.1 |
|
| 56 |
1.1 2.2 3.3 |
|
| 61 |
1.1 2.2 |
|
| 65 |
1.1 |
|
| 68 |
1.1 |
|
| 69 |
1.1 |
|
| 70 |
1.1 |
|
| 78 |
1.1 2.2 |
|
| 83 |
1.1 |
|
| 124 |
1.1 |
|
| 129 |
1.1 |
|
| 130 |
1.1 |
|
| 136 |
1.1 2.2 |
|
| 137 |
1.1 2.2 3.3 |
|
| 139 |
1.1 2.2 3.3 4.4 5.5 |
|
| 143 |
1.1 |
|
| 144 |
1.1 |
|
| 149 |
1.1 |
|
| 159 |
1.1 |