| 1 | package com.takenoko.bot; | |
| 2 | ||
| 3 | import com.takenoko.actions.Action; | |
| 4 | import com.takenoko.engine.Board; | |
| 5 | import com.takenoko.engine.BotState; | |
| 6 | import com.takenoko.engine.History; | |
| 7 | import com.takenoko.ui.ConsoleUserInterface; | |
| 8 | import java.util.*; | |
| 9 | ||
| 10 | public abstract class PriorityBot extends HashMap<Action, Double> implements Bot { | |
| 11 | ||
| 12 | public static final int DEFAULT_PRIORITY = 0; | |
| 13 | transient ConsoleUserInterface consoleUserInterface = new ConsoleUserInterface(); | |
| 14 | ||
| 15 | protected abstract void fillAction(Board board, BotState botState, History history); | |
| 16 | ||
| 17 | protected PriorityBot compute(Board board, BotState botState, History history) { | |
| 18 |
1
1. compute : removed call to com/takenoko/bot/PriorityBot::fillAction → KILLED |
fillAction(board, botState, history); |
| 19 |
1
1. compute : replaced return value with null for com/takenoko/bot/PriorityBot::compute → KILLED |
return this; |
| 20 | } | |
| 21 | ||
| 22 | public Action chooseAction(Board board, BotState botState, History history) { | |
| 23 |
1
1. chooseAction : removed call to com/takenoko/bot/PriorityBot::fillAction → KILLED |
fillAction(board, botState, history); |
| 24 | // filtered = this.entrySet().stream() | |
| 25 | // Remove actions that are not available | |
| 26 | // .filter(v -> botState.getAvailableActions().contains(v.getKey().getClass())) | |
| 27 | ||
| 28 | Optional<Action> action = | |
| 29 | this.entrySet().stream() | |
| 30 | // Remove actions that are not available | |
| 31 |
2
1. lambda$chooseAction$0 : replaced boolean return with false for com/takenoko/bot/PriorityBot::lambda$chooseAction$0 → KILLED 2. lambda$chooseAction$0 : replaced boolean return with true for com/takenoko/bot/PriorityBot::lambda$chooseAction$0 → KILLED |
.filter(v -> botState.getAvailableActions().contains(v.getKey().getClass())) |
| 32 | // Order by priority | |
| 33 | .max(Comparator.comparingDouble(Entry::getValue)) | |
| 34 | // Get the action with the highest priority | |
| 35 | .map(Map.Entry::getKey); | |
| 36 | ||
| 37 |
1
1. chooseAction : removed call to com/takenoko/ui/ConsoleUserInterface::displayDebug → TIMED_OUT |
consoleUserInterface.displayDebug(botState.getAvailableActions() + ""); |
| 38 | ||
| 39 |
1
1. chooseAction : removed call to com/takenoko/ui/ConsoleUserInterface::displayDebug → TIMED_OUT |
consoleUserInterface.displayDebug("PriorityBot has these actions: " + this); |
| 40 | ||
| 41 |
1
1. chooseAction : removed call to com/takenoko/ui/ConsoleUserInterface::displayDebug → TIMED_OUT |
consoleUserInterface.displayDebug("PriorityBot chose action: " + action); |
| 42 |
1
1. chooseAction : removed call to com/takenoko/bot/PriorityBot::clear → KILLED |
clear(); |
| 43 |
1
1. chooseAction : replaced return value with null for com/takenoko/bot/PriorityBot::chooseAction → KILLED |
return action.orElseGet( |
| 44 | () -> { | |
| 45 |
1
1. lambda$chooseAction$1 : removed call to com/takenoko/ui/ConsoleUserInterface::displayMessage → TIMED_OUT |
consoleUserInterface.displayMessage( |
| 46 | "No actions defined with priority for this bot, using FullRandomBot"); | |
| 47 |
1
1. lambda$chooseAction$1 : replaced return value with null for com/takenoko/bot/PriorityBot::lambda$chooseAction$1 → KILLED |
return new FullRandomBot().chooseAction(board, botState, history); |
| 48 | }); | |
| 49 | } | |
| 50 | ||
| 51 | protected void addActionWithPriority(Action action, double priority) { | |
| 52 |
1
1. addActionWithPriority : negated conditional → KILLED |
if (action != null) { |
| 53 |
1
1. addActionWithPriority : removed call to com/takenoko/ui/ConsoleUserInterface::displayDebug → TIMED_OUT |
consoleUserInterface.displayDebug( |
| 54 | "Adding action " + action + " with priority " + priority); | |
| 55 | this.put(action, priority); | |
| 56 | } | |
| 57 | } | |
| 58 | ||
| 59 | protected void add(PriorityBot bot) { | |
| 60 |
1
1. add : removed call to com/takenoko/bot/PriorityBot::addWithOffset → NO_COVERAGE |
this.addWithOffset(bot, 0); |
| 61 | } | |
| 62 | ||
| 63 | /** This method is used to add a bot with an offset */ | |
| 64 | protected void addWithOffset(PriorityBot bot, double offset) { | |
| 65 |
1
1. addWithOffset : removed call to com/takenoko/bot/PriorityBot::forEach → KILLED |
bot.forEach( |
| 66 | (k, v) -> { | |
| 67 |
1
1. lambda$addWithOffset$2 : removed call to com/takenoko/ui/ConsoleUserInterface::displayDebug → TIMED_OUT |
consoleUserInterface.displayDebug( |
| 68 |
1
1. lambda$addWithOffset$2 : Replaced double addition with subtraction → TIMED_OUT |
"Adding action " + k + " with priority " + (v + offset)); |
| 69 |
1
1. lambda$addWithOffset$2 : Replaced double addition with subtraction → KILLED |
this.put(k, v + offset); |
| 70 | }); | |
| 71 | } | |
| 72 | ||
| 73 | /** This method is used to add a bot with a Linear function offset */ | |
| 74 | protected void addWithLinear(PriorityBot bot, double multiplier) { | |
| 75 |
2
1. addWithLinear : removed call to com/takenoko/bot/PriorityBot::forEach → NO_COVERAGE 2. lambda$addWithLinear$3 : Replaced double addition with subtraction → NO_COVERAGE |
bot.forEach((k, v) -> this.put(k, v + multiplier)); |
| 76 | } | |
| 77 | ||
| 78 | /** This method is used to add a bot with Affine function offset */ | |
| 79 | protected void addWithAffine(PriorityBot bot, double multiplier, double offset) { | |
| 80 |
3
1. addWithAffine : removed call to com/takenoko/bot/PriorityBot::forEach → NO_COVERAGE 2. lambda$addWithAffine$4 : Replaced double multiplication with division → NO_COVERAGE 3. lambda$addWithAffine$4 : Replaced double addition with subtraction → NO_COVERAGE |
bot.forEach((k, v) -> this.put(k, v * multiplier + offset)); |
| 81 | } | |
| 82 | ||
| 83 | /** This method is used to add a bot and squash the priority between two numbers */ | |
| 84 | protected void addWithSquash(PriorityBot bot, double min, double max) { | |
| 85 | double minPriority = bot.values().stream().min(Double::compareTo).orElse(0.0); | |
| 86 | double maxPriority = bot.values().stream().max(Double::compareTo).orElse(0.0); | |
| 87 |
1
1. addWithSquash : Replaced double subtraction with addition → TIMED_OUT |
double range = maxPriority - minPriority; |
| 88 |
1
1. addWithSquash : removed call to com/takenoko/bot/PriorityBot::forEach → TIMED_OUT |
bot.forEach( |
| 89 | (k, v) -> { | |
| 90 |
2
1. lambda$addWithSquash$5 : Replaced double subtraction with addition → TIMED_OUT 2. lambda$addWithSquash$5 : Replaced double division with multiplication → TIMED_OUT |
double priority = (v - minPriority) / range; |
| 91 |
3
1. lambda$addWithSquash$5 : Replaced double subtraction with addition → TIMED_OUT 2. lambda$addWithSquash$5 : Replaced double multiplication with division → TIMED_OUT 3. lambda$addWithSquash$5 : Replaced double addition with subtraction → TIMED_OUT |
this.put(k, min + priority * (max - min)); |
| 92 | }); | |
| 93 | } | |
| 94 | ||
| 95 | @Override | |
| 96 | public boolean equals(Object o) { | |
| 97 |
2
1. equals : negated conditional → NO_COVERAGE 2. equals : replaced boolean return with false for com/takenoko/bot/PriorityBot::equals → NO_COVERAGE |
if (this == o) return true; |
| 98 |
3
1. equals : negated conditional → NO_COVERAGE 2. equals : negated conditional → NO_COVERAGE 3. equals : replaced boolean return with true for com/takenoko/bot/PriorityBot::equals → NO_COVERAGE |
if (o == null || getClass() != o.getClass()) return false; |
| 99 |
2
1. equals : negated conditional → NO_COVERAGE 2. equals : replaced boolean return with true for com/takenoko/bot/PriorityBot::equals → NO_COVERAGE |
if (!super.equals(o)) return false; |
| 100 | PriorityBot that = (PriorityBot) o; | |
| 101 |
2
1. equals : replaced boolean return with false for com/takenoko/bot/PriorityBot::equals → NO_COVERAGE 2. equals : replaced boolean return with true for com/takenoko/bot/PriorityBot::equals → NO_COVERAGE |
return Objects.equals(consoleUserInterface, that.consoleUserInterface); |
| 102 | } | |
| 103 | ||
| 104 | @Override | |
| 105 | public int hashCode() { | |
| 106 |
1
1. hashCode : replaced int return with 0 for com/takenoko/bot/PriorityBot::hashCode → NO_COVERAGE |
return Objects.hash(super.hashCode(), consoleUserInterface); |
| 107 | } | |
| 108 | } | |
Mutations | ||
| 18 |
1.1 |
|
| 19 |
1.1 |
|
| 23 |
1.1 |
|
| 31 |
1.1 2.2 |
|
| 37 |
1.1 |
|
| 39 |
1.1 |
|
| 41 |
1.1 |
|
| 42 |
1.1 |
|
| 43 |
1.1 |
|
| 45 |
1.1 |
|
| 47 |
1.1 |
|
| 52 |
1.1 |
|
| 53 |
1.1 |
|
| 60 |
1.1 |
|
| 65 |
1.1 |
|
| 67 |
1.1 |
|
| 68 |
1.1 |
|
| 69 |
1.1 |
|
| 75 |
1.1 2.2 |
|
| 80 |
1.1 2.2 3.3 |
|
| 87 |
1.1 |
|
| 88 |
1.1 |
|
| 90 |
1.1 2.2 |
|
| 91 |
1.1 2.2 3.3 |
|
| 97 |
1.1 2.2 |
|
| 98 |
1.1 2.2 3.3 |
|
| 99 |
1.1 2.2 |
|
| 101 |
1.1 2.2 |
|
| 106 |
1.1 |