PriorityBot.java

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
Location : compute
Killed by : com.takenoko.bot.ColletBotTest.[engine:junit-jupiter]/[class:com.takenoko.bot.ColletBotTest]/[nested-class:IntegrationTests]/[method:whenTheBotRollsTheWeatherInTheEarlyGamePhaseHeTakesTheCloudyMeteo()]
removed call to com/takenoko/bot/PriorityBot::fillAction → KILLED

19

1.1
Location : compute
Killed by : com.takenoko.bot.ColletBotTest.[engine:junit-jupiter]/[class:com.takenoko.bot.ColletBotTest]/[nested-class:IntegrationTests]/[method:heCollectsAsManyBamboosAsPossibleEvenIfHeHasNoCardsWithTheCorrespondingColor()]
replaced return value with null for com/takenoko/bot/PriorityBot::compute → KILLED

23

1.1
Location : chooseAction
Killed by : com.takenoko.bot.ColletBotTest.[engine:junit-jupiter]/[class:com.takenoko.bot.ColletBotTest]/[nested-class:IntegrationTests]/[method:heCollectsAsManyBamboosAsPossibleEvenIfHeHasNoCardsWithTheCorrespondingColor()]
removed call to com/takenoko/bot/PriorityBot::fillAction → KILLED

31

1.1
Location : lambda$chooseAction$0
Killed by : com.takenoko.bot.ColletBotTest.[engine:junit-jupiter]/[class:com.takenoko.bot.ColletBotTest]/[nested-class:IntegrationTests]/[method:whenTheBotChoosesAnObjectiveItTakesThePandaOnesIfThereAreSomeAvailables()]
replaced boolean return with false for com/takenoko/bot/PriorityBot::lambda$chooseAction$0 → KILLED

2.2
Location : lambda$chooseAction$0
Killed by : com.takenoko.bot.unitary.SmartStoreIrrigationTest.[engine:junit-jupiter]/[class:com.takenoko.bot.unitary.SmartStoreIrrigationTest]/[nested-class:FillAction]/[method:shouldAddStoreIrrigationInInventoryActionToActions()]
replaced boolean return with true for com/takenoko/bot/PriorityBot::lambda$chooseAction$0 → KILLED

37

1.1
Location : chooseAction
Killed by : none
removed call to com/takenoko/ui/ConsoleUserInterface::displayDebug → TIMED_OUT

39

1.1
Location : chooseAction
Killed by : none
removed call to com/takenoko/ui/ConsoleUserInterface::displayDebug → TIMED_OUT

41

1.1
Location : chooseAction
Killed by : none
removed call to com/takenoko/ui/ConsoleUserInterface::displayDebug → TIMED_OUT

42

1.1
Location : chooseAction
Killed by : com.takenoko.bot.utils.HistoryAnalysisTest.[engine:junit-jupiter]/[class:com.takenoko.bot.utils.HistoryAnalysisTest]/[nested-class:IntegrationTest]/[method:test1()]
removed call to com/takenoko/bot/PriorityBot::clear → KILLED

43

1.1
Location : chooseAction
Killed by : com.takenoko.bot.unitary.SmartStoreIrrigationTest.[engine:junit-jupiter]/[class:com.takenoko.bot.unitary.SmartStoreIrrigationTest]/[nested-class:FillAction]/[method:shouldAddStoreIrrigationInInventoryActionToActions()]
replaced return value with null for com/takenoko/bot/PriorityBot::chooseAction → KILLED

45

1.1
Location : lambda$chooseAction$1
Killed by : none
removed call to com/takenoko/ui/ConsoleUserInterface::displayMessage → TIMED_OUT

47

1.1
Location : lambda$chooseAction$1
Killed by : com.takenoko.bot.unitary.SmartStoreIrrigationTest.[engine:junit-jupiter]/[class:com.takenoko.bot.unitary.SmartStoreIrrigationTest]/[nested-class:FillAction]/[method:shouldAddStoreIrrigationInInventoryActionToActions()]
replaced return value with null for com/takenoko/bot/PriorityBot::lambda$chooseAction$1 → KILLED

52

1.1
Location : addActionWithPriority
Killed by : com.takenoko.bot.unitary.SmartApplyWeatherTest.[engine:junit-jupiter]/[class:com.takenoko.bot.unitary.SmartApplyWeatherTest]/[method:shouldFillAndApplyWeather()]
negated conditional → KILLED

53

1.1
Location : addActionWithPriority
Killed by : none
removed call to com/takenoko/ui/ConsoleUserInterface::displayDebug → TIMED_OUT

60

1.1
Location : add
Killed by : none
removed call to com/takenoko/bot/PriorityBot::addWithOffset → NO_COVERAGE

65

1.1
Location : addWithOffset
Killed by : com.takenoko.bot.ColletBotTest.[engine:junit-jupiter]/[class:com.takenoko.bot.ColletBotTest]/[nested-class:IntegrationTests]/[method:whenTheBotRollsTheWeatherInTheEarlyGamePhaseHeTakesTheCloudyMeteo()]
removed call to com/takenoko/bot/PriorityBot::forEach → KILLED

67

1.1
Location : lambda$addWithOffset$2
Killed by : none
removed call to com/takenoko/ui/ConsoleUserInterface::displayDebug → TIMED_OUT

68

1.1
Location : lambda$addWithOffset$2
Killed by : none
Replaced double addition with subtraction → TIMED_OUT

69

1.1
Location : lambda$addWithOffset$2
Killed by : com.takenoko.bot.ColletBotTest.[engine:junit-jupiter]/[class:com.takenoko.bot.ColletBotTest]/[nested-class:IntegrationTests]/[method:whenTheBotRollsTheWeatherInTheEarlyGamePhaseHeTakesTheCloudyMeteo()]
Replaced double addition with subtraction → KILLED

75

1.1
Location : addWithLinear
Killed by : none
removed call to com/takenoko/bot/PriorityBot::forEach → NO_COVERAGE

2.2
Location : lambda$addWithLinear$3
Killed by : none
Replaced double addition with subtraction → NO_COVERAGE

80

1.1
Location : addWithAffine
Killed by : none
removed call to com/takenoko/bot/PriorityBot::forEach → NO_COVERAGE

2.2
Location : lambda$addWithAffine$4
Killed by : none
Replaced double multiplication with division → NO_COVERAGE

3.3
Location : lambda$addWithAffine$4
Killed by : none
Replaced double addition with subtraction → NO_COVERAGE

87

1.1
Location : addWithSquash
Killed by : none
Replaced double subtraction with addition → TIMED_OUT

88

1.1
Location : addWithSquash
Killed by : none
removed call to com/takenoko/bot/PriorityBot::forEach → TIMED_OUT

90

1.1
Location : lambda$addWithSquash$5
Killed by : none
Replaced double subtraction with addition → TIMED_OUT

2.2
Location : lambda$addWithSquash$5
Killed by : none
Replaced double division with multiplication → TIMED_OUT

91

1.1
Location : lambda$addWithSquash$5
Killed by : none
Replaced double subtraction with addition → TIMED_OUT

2.2
Location : lambda$addWithSquash$5
Killed by : none
Replaced double multiplication with division → TIMED_OUT

3.3
Location : lambda$addWithSquash$5
Killed by : none
Replaced double addition with subtraction → TIMED_OUT

97

1.1
Location : equals
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : equals
Killed by : none
replaced boolean return with false for com/takenoko/bot/PriorityBot::equals → NO_COVERAGE

98

1.1
Location : equals
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : equals
Killed by : none
negated conditional → NO_COVERAGE

3.3
Location : equals
Killed by : none
replaced boolean return with true for com/takenoko/bot/PriorityBot::equals → NO_COVERAGE

99

1.1
Location : equals
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : equals
Killed by : none
replaced boolean return with true for com/takenoko/bot/PriorityBot::equals → NO_COVERAGE

101

1.1
Location : equals
Killed by : none
replaced boolean return with false for com/takenoko/bot/PriorityBot::equals → NO_COVERAGE

2.2
Location : equals
Killed by : none
replaced boolean return with true for com/takenoko/bot/PriorityBot::equals → NO_COVERAGE

106

1.1
Location : hashCode
Killed by : none
replaced int return with 0 for com/takenoko/bot/PriorityBot::hashCode → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.8.0