SmartPattern.java

1
package com.takenoko.bot.unitary;
2
3
import com.takenoko.actions.tile.PlaceTileAction;
4
import com.takenoko.actions.tile.PlaceTileWithImprovementAction;
5
import com.takenoko.bot.PriorityBot;
6
import com.takenoko.engine.Board;
7
import com.takenoko.engine.BotState;
8
import com.takenoko.engine.History;
9
import com.takenoko.layers.tile.ImprovementType;
10
import com.takenoko.layers.tile.Tile;
11
import com.takenoko.layers.tile.TileColor;
12
import com.takenoko.objective.Objective;
13
import com.takenoko.objective.PatternObjective;
14
import com.takenoko.shape.Shape;
15
import com.takenoko.vector.PositionVector;
16
import java.util.Comparator;
17
import java.util.List;
18
import java.util.Map;
19
import java.util.stream.Collectors;
20
import java.util.stream.Stream;
21
22
public class SmartPattern extends PriorityBot {
23
    @Override
24
    protected void fillAction(
25
            Board board,
26
            BotState botState,
27
            History history) { // Complete the shape of the current PatternObjective
28 1 1. fillAction : negated conditional → KILLED
        if (botState.getAvailableActions().contains(PlaceTileAction.class)
29 1 1. fillAction : negated conditional → KILLED
                || botState.getAvailableActions().contains(PlaceTileWithImprovementAction.class)) {
30
            Map<PatternObjective, List<Shape>> tileToPlaceWithPosition =
31
                    analyzeBoardToFindPlaceToCompleteShapeOfPatternObjective(board, botState);
32
33
            List<Tile> tilesDeck = board.peekTileDeck();
34
35
            for (Map.Entry<PatternObjective, List<Shape>> entry :
36
                    tileToPlaceWithPosition.entrySet()) {
37
                for (Shape shape : entry.getValue()) {
38
                    Map.Entry<PositionVector, Tile> tileToPlace =
39
                            shape.getElements().entrySet().stream()
40
                                    .filter(
41
                                            e ->
42 1 1. lambda$fillAction$1 : replaced boolean return with true for com/takenoko/bot/unitary/SmartPattern::lambda$fillAction$1 → KILLED
                                                    (tilesDeck.stream()
43 1 1. lambda$fillAction$1 : negated conditional → KILLED
                                                                    .anyMatch(
44
                                                                            t ->
45 2 1. lambda$fillAction$0 : replaced boolean return with false for com/takenoko/bot/unitary/SmartPattern::lambda$fillAction$0 → TIMED_OUT
2. lambda$fillAction$0 : replaced boolean return with true for com/takenoko/bot/unitary/SmartPattern::lambda$fillAction$0 → TIMED_OUT
                                                                                    t.getColor()
46
                                                                                            .equals(
47
                                                                                                    e.getValue()
48
                                                                                                            .getColor()))
49
                                                            && board.getAvailableTilePositions()
50 1 1. lambda$fillAction$1 : negated conditional → KILLED
                                                                    .contains(e.getKey())))
51
                                    .findFirst()
52
                                    .orElse(null);
53 1 1. fillAction : negated conditional → TIMED_OUT
                    if (tileToPlace != null) {
54
55
                        Tile tile =
56
                                tilesDeck.stream()
57
                                        .filter(
58
                                                t ->
59 2 1. lambda$fillAction$2 : replaced boolean return with true for com/takenoko/bot/unitary/SmartPattern::lambda$fillAction$2 → TIMED_OUT
2. lambda$fillAction$2 : replaced boolean return with false for com/takenoko/bot/unitary/SmartPattern::lambda$fillAction$2 → KILLED
                                                        t.getColor()
60
                                                                .equals(
61
                                                                        tileToPlace
62
                                                                                .getValue()
63
                                                                                .getColor()))
64
                                        .findFirst()
65
                                        .orElseThrow();
66
67
                        // We add both types of action to the bot. We consider that the wrong one
68
                        // will be
69
                        // sorted by the priority bot
70 1 1. fillAction : removed call to com/takenoko/bot/unitary/SmartPattern::addActionWithPriority → TIMED_OUT
                        this.addActionWithPriority(
71
                                new PlaceTileAction(tile, tileToPlace.getKey()),
72
                                calculatePriority(entry, shape));
73
74
                        // Verify that the tile to place does not already have an improvement
75 1 1. fillAction : negated conditional → KILLED
                        if (tile.getImprovement().isEmpty()) {
76
                            // We force the bot to place the watershed if he has one
77 1 1. fillAction : negated conditional → TIMED_OUT
                            if (botState.getInventory().hasImprovement(ImprovementType.WATERSHED)) {
78 1 1. fillAction : removed call to com/takenoko/bot/unitary/SmartPattern::addActionWithPriority → TIMED_OUT
                                this.addActionWithPriority(
79
                                        new PlaceTileWithImprovementAction(
80
                                                tile,
81
                                                tileToPlace.getKey(),
82
                                                ImprovementType.WATERSHED),
83
                                        calculatePriority(entry, shape));
84 1 1. fillAction : negated conditional → KILLED
                            } else if (botState.getInventory().hasImprovement()) {
85
                                // Otherwise place a """random""" one
86 1 1. fillAction : removed call to com/takenoko/bot/unitary/SmartPattern::addActionWithPriority → NO_COVERAGE
                                this.addActionWithPriority(
87
                                        new PlaceTileWithImprovementAction(
88
                                                tile,
89
                                                tileToPlace.getKey(),
90
                                                botState.getInventory()
91
                                                        .getInventoryImprovements()
92
                                                        .get(0)),
93
                                        calculatePriority(entry, shape));
94
                            }
95
                        }
96
                    }
97
                }
98
            }
99
        }
100
    }
101
102
    public static double calculatePriority(
103
            Map.Entry<PatternObjective, List<Shape>> entry, Shape shape) {
104 1 1. calculatePriority : replaced double return with 0.0d for com/takenoko/bot/unitary/SmartPattern::calculatePriority → TIMED_OUT
        return entry.getKey().getPoints()
105
                * (shape.getElements().size()
106 2 1. calculatePriority : Replaced double division with multiplication → TIMED_OUT
2. calculatePriority : Replaced double multiplication with division → TIMED_OUT
                        / (double) entry.getKey().getPattern().getElements().size());
107
    }
108
109
    public Map<PatternObjective, List<Shape>>
110
            analyzeBoardToFindPlaceToCompleteShapeOfPatternObjective(
111
                    Board board, BotState botState) {
112
        // Get all the pattern objectives of the bot
113
        Stream<PatternObjective> patternObjectives =
114
                getCurrentPatternObjectives(botState).stream()
115
                        .sorted(Comparator.comparing(Objective::getPoints).reversed());
116
117
        // Get all the shapes that could be completed by placing a tile
118
        Map<PatternObjective, List<Shape>> uncompletedSubsetOfShapes =
119
                patternObjectives
120
                        .map(
121
                                patternObjective ->
122 1 1. lambda$analyzeBoardToFindPlaceToCompleteShapeOfPatternObjective$3 : replaced return value with null for com/takenoko/bot/unitary/SmartPattern::lambda$analyzeBoardToFindPlaceToCompleteShapeOfPatternObjective$3 → KILLED
                                        Map.entry(
123
                                                patternObjective,
124
                                                patternObjective.getShapeToCompletePatternObjective(
125
                                                        board)))
126 2 1. lambda$analyzeBoardToFindPlaceToCompleteShapeOfPatternObjective$4 : negated conditional → TIMED_OUT
2. lambda$analyzeBoardToFindPlaceToCompleteShapeOfPatternObjective$4 : replaced boolean return with true for com/takenoko/bot/unitary/SmartPattern::lambda$analyzeBoardToFindPlaceToCompleteShapeOfPatternObjective$4 → TIMED_OUT
                        .filter(entry -> !entry.getValue().isEmpty())
127
                        .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
128
129
        // Get the available tiles to place
130
        List<Tile> deckAvailableTiles = board.peekTileDeck();
131
        List<TileColor> deckAvailableColors =
132
                deckAvailableTiles.stream().map(Tile::getColor).toList();
133
134 1 1. analyzeBoardToFindPlaceToCompleteShapeOfPatternObjective : replaced return value with Collections.emptyMap for com/takenoko/bot/unitary/SmartPattern::analyzeBoardToFindPlaceToCompleteShapeOfPatternObjective → TIMED_OUT
        return uncompletedSubsetOfShapes.entrySet().stream()
135
                .map(
136
                        entrySet ->
137 1 1. lambda$analyzeBoardToFindPlaceToCompleteShapeOfPatternObjective$7 : replaced return value with null for com/takenoko/bot/unitary/SmartPattern::lambda$analyzeBoardToFindPlaceToCompleteShapeOfPatternObjective$7 → KILLED
                                Map.entry(
138
                                        entrySet.getKey(),
139
                                        entrySet.getValue().stream()
140
                                                .filter(
141
                                                        shape ->
142 2 1. lambda$analyzeBoardToFindPlaceToCompleteShapeOfPatternObjective$6 : replaced boolean return with false for com/takenoko/bot/unitary/SmartPattern::lambda$analyzeBoardToFindPlaceToCompleteShapeOfPatternObjective$6 → TIMED_OUT
2. lambda$analyzeBoardToFindPlaceToCompleteShapeOfPatternObjective$6 : replaced boolean return with true for com/takenoko/bot/unitary/SmartPattern::lambda$analyzeBoardToFindPlaceToCompleteShapeOfPatternObjective$6 → TIMED_OUT
                                                                shape
143
                                                                        .getElements()
144
                                                                        .entrySet()
145
                                                                        .stream()
146
                                                                        .anyMatch(
147
                                                                                vectorTileEntry ->
148 1 1. lambda$analyzeBoardToFindPlaceToCompleteShapeOfPatternObjective$5 : replaced boolean return with true for com/takenoko/bot/unitary/SmartPattern::lambda$analyzeBoardToFindPlaceToCompleteShapeOfPatternObjective$5 → TIMED_OUT
                                                                                        deckAvailableColors
149 1 1. lambda$analyzeBoardToFindPlaceToCompleteShapeOfPatternObjective$5 : negated conditional → TIMED_OUT
                                                                                                        .contains(
150
                                                                                                                vectorTileEntry
151
                                                                                                                        .getValue()
152
                                                                                                                        .getColor())
153
                                                                                                && board.getAvailableTilePositions()
154 1 1. lambda$analyzeBoardToFindPlaceToCompleteShapeOfPatternObjective$5 : negated conditional → TIMED_OUT
                                                                                                        .contains(
155
                                                                                                                vectorTileEntry
156
                                                                                                                        .getKey())))
157
                                                .toList()))
158 2 1. lambda$analyzeBoardToFindPlaceToCompleteShapeOfPatternObjective$8 : negated conditional → TIMED_OUT
2. lambda$analyzeBoardToFindPlaceToCompleteShapeOfPatternObjective$8 : replaced boolean return with true for com/takenoko/bot/unitary/SmartPattern::lambda$analyzeBoardToFindPlaceToCompleteShapeOfPatternObjective$8 → TIMED_OUT
                .filter(entry -> !entry.getValue().isEmpty())
159
                .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
160
    }
161
162
    public List<PatternObjective> getCurrentPatternObjectives(BotState botState) {
163 1 1. getCurrentPatternObjectives : replaced return value with Collections.emptyList for com/takenoko/bot/unitary/SmartPattern::getCurrentPatternObjectives → TIMED_OUT
        return botState.getNotAchievedObjectives().stream()
164
                .filter(PatternObjective.class::isInstance)
165
                .map(PatternObjective.class::cast)
166
                .toList();
167
    }
168
}

Mutations

28

1.1
Location : fillAction
Killed by : com.takenoko.bot.utils.HistoryAnalysisTest.[engine:junit-jupiter]/[class:com.takenoko.bot.utils.HistoryAnalysisTest]/[nested-class:IntegrationTest]/[method:test1()]
negated conditional → KILLED

29

1.1
Location : fillAction
Killed by : com.takenoko.bot.utils.HistoryAnalysisTest.[engine:junit-jupiter]/[class:com.takenoko.bot.utils.HistoryAnalysisTest]/[nested-class:IntegrationTest]/[method:test1()]
negated conditional → KILLED

42

1.1
Location : lambda$fillAction$1
Killed by : com.takenoko.bot.utils.HistoryAnalysisTest.[engine:junit-jupiter]/[class:com.takenoko.bot.utils.HistoryAnalysisTest]/[nested-class:IntegrationTest]/[method:test1()]
replaced boolean return with true for com/takenoko/bot/unitary/SmartPattern::lambda$fillAction$1 → KILLED

43

1.1
Location : lambda$fillAction$1
Killed by : com.takenoko.bot.utils.HistoryAnalysisTest.[engine:junit-jupiter]/[class:com.takenoko.bot.utils.HistoryAnalysisTest]/[nested-class:IntegrationTest]/[method:test1()]
negated conditional → KILLED

45

1.1
Location : lambda$fillAction$0
Killed by : none
replaced boolean return with false for com/takenoko/bot/unitary/SmartPattern::lambda$fillAction$0 → TIMED_OUT

2.2
Location : lambda$fillAction$0
Killed by : none
replaced boolean return with true for com/takenoko/bot/unitary/SmartPattern::lambda$fillAction$0 → TIMED_OUT

50

1.1
Location : lambda$fillAction$1
Killed by : com.takenoko.bot.utils.HistoryAnalysisTest.[engine:junit-jupiter]/[class:com.takenoko.bot.utils.HistoryAnalysisTest]/[nested-class:IntegrationTest]/[method:test1()]
negated conditional → KILLED

53

1.1
Location : fillAction
Killed by : none
negated conditional → TIMED_OUT

59

1.1
Location : lambda$fillAction$2
Killed by : com.takenoko.bot.unitary.SmartPatternTest.[engine:junit-jupiter]/[class:com.takenoko.bot.unitary.SmartPatternTest]/[nested-class:fillAction]/[method:shouldTryToCompletePatternObjective()]
replaced boolean return with false for com/takenoko/bot/unitary/SmartPattern::lambda$fillAction$2 → KILLED

2.2
Location : lambda$fillAction$2
Killed by : none
replaced boolean return with true for com/takenoko/bot/unitary/SmartPattern::lambda$fillAction$2 → TIMED_OUT

70

1.1
Location : fillAction
Killed by : none
removed call to com/takenoko/bot/unitary/SmartPattern::addActionWithPriority → TIMED_OUT

75

1.1
Location : fillAction
Killed by : com.takenoko.bot.utils.HistoryAnalysisTest.[engine:junit-jupiter]/[class:com.takenoko.bot.utils.HistoryAnalysisTest]/[nested-class:IntegrationTest]/[method:test1()]
negated conditional → KILLED

77

1.1
Location : fillAction
Killed by : none
negated conditional → TIMED_OUT

78

1.1
Location : fillAction
Killed by : none
removed call to com/takenoko/bot/unitary/SmartPattern::addActionWithPriority → TIMED_OUT

84

1.1
Location : fillAction
Killed by : com.takenoko.bot.unitary.SmartPatternTest.[engine:junit-jupiter]/[class:com.takenoko.bot.unitary.SmartPatternTest]/[nested-class:fillAction]/[method:shouldTryToCompletePatternObjective()]
negated conditional → KILLED

86

1.1
Location : fillAction
Killed by : none
removed call to com/takenoko/bot/unitary/SmartPattern::addActionWithPriority → NO_COVERAGE

104

1.1
Location : calculatePriority
Killed by : none
replaced double return with 0.0d for com/takenoko/bot/unitary/SmartPattern::calculatePriority → TIMED_OUT

106

1.1
Location : calculatePriority
Killed by : none
Replaced double division with multiplication → TIMED_OUT

2.2
Location : calculatePriority
Killed by : none
Replaced double multiplication with division → TIMED_OUT

122

1.1
Location : lambda$analyzeBoardToFindPlaceToCompleteShapeOfPatternObjective$3
Killed by : com.takenoko.bot.unitary.SmartPatternTest.[engine:junit-jupiter]/[class:com.takenoko.bot.unitary.SmartPatternTest]/[nested-class:fillAction]/[method:shouldTryToCompletePatternObjective()]
replaced return value with null for com/takenoko/bot/unitary/SmartPattern::lambda$analyzeBoardToFindPlaceToCompleteShapeOfPatternObjective$3 → KILLED

126

1.1
Location : lambda$analyzeBoardToFindPlaceToCompleteShapeOfPatternObjective$4
Killed by : none
negated conditional → TIMED_OUT

2.2
Location : lambda$analyzeBoardToFindPlaceToCompleteShapeOfPatternObjective$4
Killed by : none
replaced boolean return with true for com/takenoko/bot/unitary/SmartPattern::lambda$analyzeBoardToFindPlaceToCompleteShapeOfPatternObjective$4 → TIMED_OUT

134

1.1
Location : analyzeBoardToFindPlaceToCompleteShapeOfPatternObjective
Killed by : none
replaced return value with Collections.emptyMap for com/takenoko/bot/unitary/SmartPattern::analyzeBoardToFindPlaceToCompleteShapeOfPatternObjective → TIMED_OUT

137

1.1
Location : lambda$analyzeBoardToFindPlaceToCompleteShapeOfPatternObjective$7
Killed by : com.takenoko.bot.unitary.SmartPatternTest.[engine:junit-jupiter]/[class:com.takenoko.bot.unitary.SmartPatternTest]/[nested-class:fillAction]/[method:shouldTryToCompletePatternObjective()]
replaced return value with null for com/takenoko/bot/unitary/SmartPattern::lambda$analyzeBoardToFindPlaceToCompleteShapeOfPatternObjective$7 → KILLED

142

1.1
Location : lambda$analyzeBoardToFindPlaceToCompleteShapeOfPatternObjective$6
Killed by : none
replaced boolean return with false for com/takenoko/bot/unitary/SmartPattern::lambda$analyzeBoardToFindPlaceToCompleteShapeOfPatternObjective$6 → TIMED_OUT

2.2
Location : lambda$analyzeBoardToFindPlaceToCompleteShapeOfPatternObjective$6
Killed by : none
replaced boolean return with true for com/takenoko/bot/unitary/SmartPattern::lambda$analyzeBoardToFindPlaceToCompleteShapeOfPatternObjective$6 → TIMED_OUT

148

1.1
Location : lambda$analyzeBoardToFindPlaceToCompleteShapeOfPatternObjective$5
Killed by : none
replaced boolean return with true for com/takenoko/bot/unitary/SmartPattern::lambda$analyzeBoardToFindPlaceToCompleteShapeOfPatternObjective$5 → TIMED_OUT

149

1.1
Location : lambda$analyzeBoardToFindPlaceToCompleteShapeOfPatternObjective$5
Killed by : none
negated conditional → TIMED_OUT

154

1.1
Location : lambda$analyzeBoardToFindPlaceToCompleteShapeOfPatternObjective$5
Killed by : none
negated conditional → TIMED_OUT

158

1.1
Location : lambda$analyzeBoardToFindPlaceToCompleteShapeOfPatternObjective$8
Killed by : none
negated conditional → TIMED_OUT

2.2
Location : lambda$analyzeBoardToFindPlaceToCompleteShapeOfPatternObjective$8
Killed by : none
replaced boolean return with true for com/takenoko/bot/unitary/SmartPattern::lambda$analyzeBoardToFindPlaceToCompleteShapeOfPatternObjective$8 → TIMED_OUT

163

1.1
Location : getCurrentPatternObjectives
Killed by : none
replaced return value with Collections.emptyList for com/takenoko/bot/unitary/SmartPattern::getCurrentPatternObjectives → TIMED_OUT

Active mutators

Tests examined


Report generated by PIT 1.8.0