| 1 | package com.takenoko.bot; | |
| 2 | ||
| 3 | import com.takenoko.actions.Action; | |
| 4 | import com.takenoko.actions.actors.ForcedMovePandaAction; | |
| 5 | import com.takenoko.actions.actors.MoveGardenerAction; | |
| 6 | import com.takenoko.actions.actors.MovePandaAction; | |
| 7 | import com.takenoko.actions.bamboo.GrowBambooAction; | |
| 8 | import com.takenoko.actions.improvement.ApplyImprovementAction; | |
| 9 | import com.takenoko.actions.improvement.ApplyImprovementFromInventoryAction; | |
| 10 | import com.takenoko.actions.improvement.DrawImprovementAction; | |
| 11 | import com.takenoko.actions.improvement.StoreImprovementAction; | |
| 12 | import com.takenoko.actions.irrigation.DrawIrrigationAction; | |
| 13 | import com.takenoko.actions.irrigation.PlaceIrrigationAction; | |
| 14 | import com.takenoko.actions.irrigation.PlaceIrrigationFromInventoryAction; | |
| 15 | import com.takenoko.actions.irrigation.StoreIrrigationInInventoryAction; | |
| 16 | import com.takenoko.actions.objective.DrawObjectiveAction; | |
| 17 | import com.takenoko.actions.objective.RedeemObjectiveAction; | |
| 18 | import com.takenoko.actions.tile.DrawTileAction; | |
| 19 | import com.takenoko.actions.tile.PlaceTileAction; | |
| 20 | import com.takenoko.actions.weather.ChooseAndApplyWeatherAction; | |
| 21 | import com.takenoko.actions.weather.ChooseIfApplyWeatherAction; | |
| 22 | import com.takenoko.engine.Board; | |
| 23 | import com.takenoko.engine.BotState; | |
| 24 | import com.takenoko.engine.History; | |
| 25 | import com.takenoko.layers.irrigation.EdgePosition; | |
| 26 | import com.takenoko.layers.tile.ImprovementType; | |
| 27 | import com.takenoko.layers.tile.Tile; | |
| 28 | import com.takenoko.objective.ObjectiveType; | |
| 29 | import com.takenoko.vector.PositionVector; | |
| 30 | import com.takenoko.weather.Weather; | |
| 31 | import com.takenoko.weather.WeatherFactory; | |
| 32 | import java.security.SecureRandom; | |
| 33 | import java.util.*; | |
| 34 | ||
| 35 | public class FullRandomBot implements Bot { | |
| 36 | final SecureRandom random; | |
| 37 | ||
| 38 | public FullRandomBot() { | |
| 39 | random = new SecureRandom(); | |
| 40 | } | |
| 41 | ||
| 42 | @Override | |
| 43 | public Action chooseAction(Board board, BotState botState, History history) { | |
| 44 | List<Action> actions = new ArrayList<>(); | |
| 45 | ||
| 46 |
1
1. chooseAction : negated conditional → KILLED |
if (botState.getAvailableActions().contains(ChooseIfApplyWeatherAction.class)) { |
| 47 |
1
1. chooseAction : replaced return value with null for com/takenoko/bot/FullRandomBot::chooseAction → KILLED |
return new ChooseIfApplyWeatherAction(random.nextBoolean()); |
| 48 | } | |
| 49 | ||
| 50 |
1
1. chooseAction : negated conditional → KILLED |
if (botState.getAvailableActions().contains(DrawTileAction.class)) { |
| 51 | actions.add(new DrawTileAction()); | |
| 52 | } | |
| 53 | ||
| 54 |
1
1. chooseAction : negated conditional → KILLED |
if (botState.getAvailableActions().contains(PlaceTileAction.class)) { |
| 55 | actions.add(getRandomPlaceTileAction(board)); | |
| 56 | } | |
| 57 | ||
| 58 |
1
1. chooseAction : negated conditional → KILLED |
if (botState.getAvailableActions().contains(MoveGardenerAction.class)) { |
| 59 | actions.add(getRandomMoveGardenerAction(board)); | |
| 60 | } | |
| 61 | ||
| 62 |
1
1. chooseAction : negated conditional → KILLED |
if (botState.getAvailableActions().contains(MovePandaAction.class)) { |
| 63 | actions.add(getRandomMovePandaAction(board)); | |
| 64 | } | |
| 65 | ||
| 66 |
1
1. chooseAction : negated conditional → KILLED |
if (botState.getAvailableActions().contains(ApplyImprovementAction.class)) { |
| 67 | actions.add(getRandomApplyImprovementAction(board)); | |
| 68 | } | |
| 69 | ||
| 70 |
1
1. chooseAction : negated conditional → KILLED |
if (botState.getAvailableActions().contains(StoreImprovementAction.class)) { |
| 71 | actions.add(new StoreImprovementAction()); | |
| 72 | } | |
| 73 | ||
| 74 |
1
1. chooseAction : negated conditional → KILLED |
if (botState.getAvailableActions().contains(DrawImprovementAction.class)) { |
| 75 | actions.add(getRandomDrawAction(board)); | |
| 76 | } | |
| 77 | ||
| 78 |
1
1. chooseAction : negated conditional → KILLED |
if (botState.getAvailableActions().contains(ApplyImprovementFromInventoryAction.class)) { |
| 79 | actions.add(getRandomApplyImprovementFromInventoryAction(board, botState)); | |
| 80 | } | |
| 81 | ||
| 82 |
1
1. chooseAction : negated conditional → KILLED |
if (botState.getAvailableActions().contains(ChooseAndApplyWeatherAction.class)) { |
| 83 | actions.add(getRandomChooseAndApplyWeatherAction()); | |
| 84 | } | |
| 85 |
1
1. chooseAction : negated conditional → KILLED |
if (botState.getAvailableActions().contains(DrawObjectiveAction.class)) { |
| 86 | actions.add(getRandomDrawObjectiveAction(board)); | |
| 87 | } | |
| 88 |
1
1. chooseAction : negated conditional → KILLED |
if (botState.getAvailableActions().contains(RedeemObjectiveAction.class)) { |
| 89 | actions.add(getRandomRedeemObjectiveAction(botState)); | |
| 90 | } | |
| 91 |
1
1. chooseAction : negated conditional → KILLED |
if (botState.getAvailableActions().contains(DrawIrrigationAction.class)) { |
| 92 | actions.add(new DrawIrrigationAction()); | |
| 93 | } | |
| 94 |
1
1. chooseAction : negated conditional → KILLED |
if (botState.getAvailableActions().contains(PlaceIrrigationAction.class)) { |
| 95 | actions.add(getRandomPlaceIrrigationAction(board)); | |
| 96 | } | |
| 97 |
1
1. chooseAction : negated conditional → KILLED |
if (botState.getAvailableActions().contains(PlaceIrrigationFromInventoryAction.class)) { |
| 98 | actions.add(getRandomPlaceIrrigationFromInventoryAction(board)); | |
| 99 | } | |
| 100 |
1
1. chooseAction : negated conditional → KILLED |
if (botState.getAvailableActions().contains(StoreIrrigationInInventoryAction.class)) { |
| 101 | actions.add(new StoreIrrigationInInventoryAction()); | |
| 102 | } | |
| 103 |
1
1. chooseAction : negated conditional → KILLED |
if (botState.getAvailableActions().contains(ForcedMovePandaAction.class)) { |
| 104 | actions.add(getRandomForcedMovePandaAction(board)); | |
| 105 | } | |
| 106 | ||
| 107 |
1
1. chooseAction : negated conditional → KILLED |
if (botState.getAvailableActions().contains(GrowBambooAction.class)) { |
| 108 | actions.add(getRandomGrowBambooAction(board)); | |
| 109 | } | |
| 110 | ||
| 111 | actions.removeIf(Objects::isNull); | |
| 112 | ||
| 113 |
1
1. chooseAction : negated conditional → KILLED |
if (actions.isEmpty()) |
| 114 | throw new IllegalStateException( | |
| 115 | "FullRandomBot didn't find any action (" | |
| 116 | + botState.getAvailableActions() | |
| 117 | + ")"); | |
| 118 | ||
| 119 |
1
1. chooseAction : replaced return value with null for com/takenoko/bot/FullRandomBot::chooseAction → KILLED |
return actions.get(random.nextInt(actions.size())); |
| 120 | } | |
| 121 | ||
| 122 | private Action getRandomGrowBambooAction(Board board) { | |
| 123 | List<PositionVector> positions = board.getGrowablePositions(); | |
| 124 |
1
1. getRandomGrowBambooAction : negated conditional → KILLED |
if (positions.isEmpty()) return null; |
| 125 |
1
1. getRandomGrowBambooAction : replaced return value with null for com/takenoko/bot/FullRandomBot::getRandomGrowBambooAction → KILLED |
return new GrowBambooAction(positions.get(random.nextInt(positions.size()))); |
| 126 | } | |
| 127 | ||
| 128 | public Action getRandomForcedMovePandaAction(Board board) { | |
| 129 | List<PositionVector> pandaPossibleMoves = board.getPandaPossibleMoves(); | |
| 130 |
1
1. getRandomForcedMovePandaAction : negated conditional → TIMED_OUT |
if (pandaPossibleMoves.isEmpty()) { |
| 131 | return null; | |
| 132 | } | |
| 133 |
1
1. getRandomForcedMovePandaAction : replaced return value with null for com/takenoko/bot/FullRandomBot::getRandomForcedMovePandaAction → TIMED_OUT |
return new ForcedMovePandaAction( |
| 134 | pandaPossibleMoves.get(random.nextInt(pandaPossibleMoves.size()))); | |
| 135 | } | |
| 136 | ||
| 137 | private Action getRandomApplyImprovementFromInventoryAction(Board board, BotState botState) { | |
| 138 | List<ImprovementType> availableImprovements = | |
| 139 | botState.getInventory().getInventoryImprovements(); | |
| 140 | List<PositionVector> availablePositions = board.getAvailableImprovementPositions(); | |
| 141 |
1
1. getRandomApplyImprovementFromInventoryAction : negated conditional → TIMED_OUT |
if (availableImprovements.isEmpty()) { |
| 142 | return null; | |
| 143 | } | |
| 144 |
1
1. getRandomApplyImprovementFromInventoryAction : replaced return value with null for com/takenoko/bot/FullRandomBot::getRandomApplyImprovementFromInventoryAction → TIMED_OUT |
return new ApplyImprovementFromInventoryAction( |
| 145 | availableImprovements.get(random.nextInt(availableImprovements.size())), | |
| 146 | availablePositions.get(random.nextInt(availablePositions.size()))); | |
| 147 | } | |
| 148 | ||
| 149 | private Action getRandomPlaceIrrigationAction(Board board) { | |
| 150 | List<EdgePosition> positions = board.getAvailableIrrigationPositions(); | |
| 151 | ||
| 152 |
1
1. getRandomPlaceIrrigationAction : negated conditional → TIMED_OUT |
if (positions.isEmpty()) return null; |
| 153 | ||
| 154 |
1
1. getRandomPlaceIrrigationAction : replaced return value with null for com/takenoko/bot/FullRandomBot::getRandomPlaceIrrigationAction → TIMED_OUT |
return new PlaceIrrigationAction(positions.get(random.nextInt(positions.size()))); |
| 155 | } | |
| 156 | ||
| 157 | private Action getRandomPlaceIrrigationFromInventoryAction(Board board) { | |
| 158 | List<EdgePosition> availableIrrigationPositions = board.getAvailableIrrigationPositions(); | |
| 159 |
1
1. getRandomPlaceIrrigationFromInventoryAction : negated conditional → TIMED_OUT |
if (availableIrrigationPositions.isEmpty()) { |
| 160 | return null; | |
| 161 | } | |
| 162 |
1
1. getRandomPlaceIrrigationFromInventoryAction : replaced return value with null for com/takenoko/bot/FullRandomBot::getRandomPlaceIrrigationFromInventoryAction → TIMED_OUT |
return new PlaceIrrigationFromInventoryAction( |
| 163 | availableIrrigationPositions.get( | |
| 164 | random.nextInt(availableIrrigationPositions.size()))); | |
| 165 | } | |
| 166 | ||
| 167 | private Action getRandomRedeemObjectiveAction(BotState botState) { | |
| 168 |
1
1. getRandomRedeemObjectiveAction : replaced return value with null for com/takenoko/bot/FullRandomBot::getRandomRedeemObjectiveAction → TIMED_OUT |
return new RedeemObjectiveAction( |
| 169 | botState.getAchievedObjectives() | |
| 170 | .get(random.nextInt(botState.getAchievedObjectives().size()))); | |
| 171 | } | |
| 172 | ||
| 173 | private Action getRandomChooseAndApplyWeatherAction() { | |
| 174 | Weather weather = | |
| 175 | WeatherFactory.values()[random.nextInt(WeatherFactory.values().length)] | |
| 176 | .createWeather(); | |
| 177 |
1
1. getRandomChooseAndApplyWeatherAction : replaced return value with null for com/takenoko/bot/FullRandomBot::getRandomChooseAndApplyWeatherAction → KILLED |
return new ChooseAndApplyWeatherAction(weather); |
| 178 | } | |
| 179 | ||
| 180 | private Action getRandomDrawAction(Board board) { | |
| 181 | List<ImprovementType> improvements = new ArrayList<>(); | |
| 182 | ||
| 183 |
1
1. getRandomDrawAction : negated conditional → NO_COVERAGE |
if (board.hasImprovementInDeck(ImprovementType.ENCLOSURE)) { |
| 184 | improvements.add(ImprovementType.ENCLOSURE); | |
| 185 | } | |
| 186 | ||
| 187 |
1
1. getRandomDrawAction : negated conditional → NO_COVERAGE |
if (board.hasImprovementInDeck(ImprovementType.FERTILIZER)) { |
| 188 | improvements.add(ImprovementType.FERTILIZER); | |
| 189 | } | |
| 190 |
2
1. getRandomDrawAction : negated conditional → NO_COVERAGE 2. getRandomDrawAction : replaced return value with null for com/takenoko/bot/FullRandomBot::getRandomDrawAction → NO_COVERAGE |
if (improvements.isEmpty()) return new DrawImprovementAction(ImprovementType.FERTILIZER); |
| 191 | ||
| 192 |
1
1. getRandomDrawAction : replaced return value with null for com/takenoko/bot/FullRandomBot::getRandomDrawAction → NO_COVERAGE |
return new DrawImprovementAction(improvements.get(random.nextInt(improvements.size()))); |
| 193 | } | |
| 194 | ||
| 195 | private Action getRandomApplyImprovementAction(Board board) { | |
| 196 | List<PositionVector> positions = board.getAvailableImprovementPositions(); | |
| 197 | ||
| 198 | List<ImprovementType> imp = new ArrayList<>(); | |
| 199 |
1
1. getRandomApplyImprovementAction : negated conditional → TIMED_OUT |
if (board.hasImprovementInDeck(ImprovementType.FERTILIZER)) { |
| 200 | imp.add(ImprovementType.FERTILIZER); | |
| 201 | } | |
| 202 |
1
1. getRandomApplyImprovementAction : negated conditional → TIMED_OUT |
if (board.hasImprovementInDeck(ImprovementType.ENCLOSURE)) { |
| 203 | imp.add(ImprovementType.ENCLOSURE); | |
| 204 | } | |
| 205 | ||
| 206 |
2
1. getRandomApplyImprovementAction : negated conditional → TIMED_OUT 2. getRandomApplyImprovementAction : negated conditional → KILLED |
if (positions.isEmpty() || imp.isEmpty()) return null; |
| 207 | ||
| 208 |
1
1. getRandomApplyImprovementAction : replaced return value with null for com/takenoko/bot/FullRandomBot::getRandomApplyImprovementAction → TIMED_OUT |
return new ApplyImprovementAction(positions.get(random.nextInt(positions.size()))); |
| 209 | } | |
| 210 | ||
| 211 | private Action getRandomPlaceTileAction(Board board) { | |
| 212 | List<Tile> availableTiles = board.peekTileDeck(); | |
| 213 | List<PositionVector> availableTilePositions = board.getAvailableTilePositions(); | |
| 214 |
2
1. getRandomPlaceTileAction : negated conditional → KILLED 2. getRandomPlaceTileAction : negated conditional → KILLED |
if (availableTiles.isEmpty() || availableTilePositions.isEmpty()) { |
| 215 | return null; | |
| 216 | } | |
| 217 |
1
1. getRandomPlaceTileAction : replaced return value with null for com/takenoko/bot/FullRandomBot::getRandomPlaceTileAction → KILLED |
return new PlaceTileAction( |
| 218 | availableTiles.get(random.nextInt(availableTiles.size())), | |
| 219 | availableTilePositions.get(random.nextInt(availableTilePositions.size()))); | |
| 220 | } | |
| 221 | ||
| 222 | public Action getRandomMovePandaAction(Board board) { | |
| 223 | List<PositionVector> pandaPossibleMoves = board.getPandaPossibleMoves(); | |
| 224 |
1
1. getRandomMovePandaAction : negated conditional → KILLED |
if (pandaPossibleMoves.isEmpty()) { |
| 225 | return null; | |
| 226 | } | |
| 227 |
1
1. getRandomMovePandaAction : replaced return value with null for com/takenoko/bot/FullRandomBot::getRandomMovePandaAction → KILLED |
return new MovePandaAction( |
| 228 | pandaPossibleMoves.get(random.nextInt(pandaPossibleMoves.size()))); | |
| 229 | } | |
| 230 | ||
| 231 | private Action getRandomMoveGardenerAction(Board board) { | |
| 232 | List<PositionVector> gardenerPossibleMoves = board.getGardenerPossibleMoves(); | |
| 233 |
1
1. getRandomMoveGardenerAction : negated conditional → KILLED |
if (gardenerPossibleMoves.isEmpty()) { |
| 234 | return null; | |
| 235 | } | |
| 236 |
1
1. getRandomMoveGardenerAction : replaced return value with null for com/takenoko/bot/FullRandomBot::getRandomMoveGardenerAction → KILLED |
return new MoveGardenerAction( |
| 237 | gardenerPossibleMoves.get(random.nextInt(gardenerPossibleMoves.size()))); | |
| 238 | } | |
| 239 | ||
| 240 | private Action getRandomDrawObjectiveAction(Board board) { | |
| 241 | List<ObjectiveType> objectiveType = | |
| 242 | EnumSet.allOf(ObjectiveType.class).stream() | |
| 243 | .filter(board::hasObjectiveTypeInDeck) | |
| 244 | .toList(); | |
| 245 |
1
1. getRandomDrawObjectiveAction : replaced return value with null for com/takenoko/bot/FullRandomBot::getRandomDrawObjectiveAction → TIMED_OUT |
return new DrawObjectiveAction( |
| 246 | objectiveType.stream().toList().get(random.nextInt(objectiveType.size()))); | |
| 247 | } | |
| 248 | } | |
Mutations | ||
| 46 |
1.1 |
|
| 47 |
1.1 |
|
| 50 |
1.1 |
|
| 54 |
1.1 |
|
| 58 |
1.1 |
|
| 62 |
1.1 |
|
| 66 |
1.1 |
|
| 70 |
1.1 |
|
| 74 |
1.1 |
|
| 78 |
1.1 |
|
| 82 |
1.1 |
|
| 85 |
1.1 |
|
| 88 |
1.1 |
|
| 91 |
1.1 |
|
| 94 |
1.1 |
|
| 97 |
1.1 |
|
| 100 |
1.1 |
|
| 103 |
1.1 |
|
| 107 |
1.1 |
|
| 113 |
1.1 |
|
| 119 |
1.1 |
|
| 124 |
1.1 |
|
| 125 |
1.1 |
|
| 130 |
1.1 |
|
| 133 |
1.1 |
|
| 141 |
1.1 |
|
| 144 |
1.1 |
|
| 152 |
1.1 |
|
| 154 |
1.1 |
|
| 159 |
1.1 |
|
| 162 |
1.1 |
|
| 168 |
1.1 |
|
| 177 |
1.1 |
|
| 183 |
1.1 |
|
| 187 |
1.1 |
|
| 190 |
1.1 2.2 |
|
| 192 |
1.1 |
|
| 199 |
1.1 |
|
| 202 |
1.1 |
|
| 206 |
1.1 2.2 |
|
| 208 |
1.1 |
|
| 214 |
1.1 2.2 |
|
| 217 |
1.1 |
|
| 224 |
1.1 |
|
| 227 |
1.1 |
|
| 233 |
1.1 |
|
| 236 |
1.1 |
|
| 245 |
1.1 |