1 | package com.takenoko.engine; | |
2 | ||
3 | import com.takenoko.bot.utils.HistoryAnalysis; | |
4 | import com.takenoko.stats.HistoryStatistics; | |
5 | import com.takenoko.stats.HistoryStatisticsItem; | |
6 | import java.util.*; | |
7 | import java.util.stream.Collectors; | |
8 | ||
9 | /** Class that stores the history of a game. */ | |
10 | public class History extends HashMap<UUID, List<TurnHistory>> { | |
11 | ||
12 | private UUID currentBotManagerUUID; | |
13 | private HistoryStatistics historyStatistics = new HistoryStatistics(); | |
14 | ||
15 | public History(History historyMap) { | |
16 | super(historyMap); | |
17 | currentBotManagerUUID = historyMap.currentBotManagerUUID; | |
18 | historyStatistics = historyMap.historyStatistics; | |
19 | } | |
20 | ||
21 | public History() { | |
22 | super(); | |
23 | } | |
24 | ||
25 | public UUID getCurrentBotManagerUUID() { | |
26 |
1
1. getCurrentBotManagerUUID : replaced return value with null for com/takenoko/engine/History::getCurrentBotManagerUUID → TIMED_OUT |
return currentBotManagerUUID; |
27 | } | |
28 | ||
29 | public void setCurrentBotManagerUUID(UUID currentBotManagerUUID) { | |
30 | this.currentBotManagerUUID = currentBotManagerUUID; | |
31 | } | |
32 | ||
33 | public void addBotManager(BotManager botManager) { | |
34 | put(botManager.getUniqueID(), new ArrayList<>(List.of())); | |
35 | historyStatistics.put(botManager, new HistoryStatisticsItem()); | |
36 | } | |
37 | ||
38 | public void addTurnHistory(BotManager botManager, TurnHistory turnHistory) { | |
39 |
1
1. lambda$addTurnHistory$0 : replaced return value with Collections.emptyList for com/takenoko/engine/History::lambda$addTurnHistory$0 → NO_COVERAGE |
computeIfAbsent(botManager.getUniqueID(), k -> new ArrayList<>()).add(turnHistory); |
40 | } | |
41 | ||
42 | public void updateHistoryStatistics(BotManager botManager) { | |
43 |
3
1. updateHistoryStatistics : changed conditional boundary → TIMED_OUT 2. updateHistoryStatistics : negated conditional → TIMED_OUT 3. updateHistoryStatistics : negated conditional → TIMED_OUT |
if (containsKey(botManager.getUniqueID()) && get(botManager.getUniqueID()).size() > 1) { |
44 |
1
1. updateHistoryStatistics : removed call to com/takenoko/stats/HistoryStatistics::incrementNumberOfRounds → TIMED_OUT |
historyStatistics.incrementNumberOfRounds( |
45 | botManager, HistoryAnalysis.getGameProgress(this)); | |
46 |
1
1. updateHistoryStatistics : removed call to com/takenoko/stats/HistoryStatistics::updateEvolution → TIMED_OUT |
historyStatistics.updateEvolution(botManager, this); |
47 | } | |
48 | } | |
49 | ||
50 | public History copy() { | |
51 |
1
1. copy : replaced return value with null for com/takenoko/engine/History::copy → KILLED |
return new History(this); |
52 | } | |
53 | ||
54 | /** | |
55 | * Returns a map of the latest history item for each bot manager in the history. | |
56 | * | |
57 | * @return a map of the latest history item for each bot manager. | |
58 | */ | |
59 | public Map<UUID, HistoryItem> getLatestHistoryItems() { | |
60 |
1
1. getLatestHistoryItems : replaced return value with Collections.emptyMap for com/takenoko/engine/History::getLatestHistoryItems → KILLED |
return entrySet().stream() |
61 |
2
1. lambda$getLatestHistoryItems$1 : replaced boolean return with true for com/takenoko/engine/History::lambda$getLatestHistoryItems$1 → TIMED_OUT 2. lambda$getLatestHistoryItems$1 : negated conditional → KILLED |
.filter(uuidListEntry -> !uuidListEntry.getValue().isEmpty()) |
62 | .map( | |
63 | uuidListEntry -> { | |
64 | TurnHistory lastRound = | |
65 | uuidListEntry | |
66 | .getValue() | |
67 |
1
1. lambda$getLatestHistoryItems$2 : Replaced integer subtraction with addition → KILLED |
.get(uuidListEntry.getValue().size() - 1); |
68 |
1
1. lambda$getLatestHistoryItems$2 : Replaced integer subtraction with addition → KILLED |
HistoryItem lastHistoryItem = lastRound.get(lastRound.size() - 1); |
69 | ||
70 |
1
1. lambda$getLatestHistoryItems$2 : replaced return value with null for com/takenoko/engine/History::lambda$getLatestHistoryItems$2 → KILLED |
return new AbstractMap.SimpleEntry<>( |
71 | uuidListEntry.getKey(), lastHistoryItem); | |
72 | }) | |
73 | .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); | |
74 | } | |
75 | ||
76 | @Override | |
77 | public boolean equals(Object o) { | |
78 |
2
1. equals : negated conditional → KILLED 2. equals : replaced boolean return with false for com/takenoko/engine/History::equals → KILLED |
if (this == o) return true; |
79 |
3
1. equals : negated conditional → KILLED 2. equals : negated conditional → KILLED 3. equals : replaced boolean return with true for com/takenoko/engine/History::equals → KILLED |
if (o == null || getClass() != o.getClass()) return false; |
80 |
2
1. equals : negated conditional → KILLED 2. equals : replaced boolean return with true for com/takenoko/engine/History::equals → KILLED |
if (!super.equals(o)) return false; |
81 | History history = (History) o; | |
82 |
2
1. equals : replaced boolean return with true for com/takenoko/engine/History::equals → SURVIVED 2. equals : replaced boolean return with false for com/takenoko/engine/History::equals → KILLED |
return Objects.equals(getCurrentBotManagerUUID(), history.getCurrentBotManagerUUID()); |
83 | } | |
84 | ||
85 | @Override | |
86 | public int hashCode() { | |
87 |
1
1. hashCode : replaced int return with 0 for com/takenoko/engine/History::hashCode → KILLED |
return Objects.hash(super.hashCode(), getCurrentBotManagerUUID()); |
88 | } | |
89 | ||
90 | public HistoryStatistics getHistoryStatistics() { | |
91 |
1
1. getHistoryStatistics : replaced return value with null for com/takenoko/engine/History::getHistoryStatistics → KILLED |
return historyStatistics; |
92 | } | |
93 | } | |
Mutations | ||
26 |
1.1 |
|
39 |
1.1 |
|
43 |
1.1 2.2 3.3 |
|
44 |
1.1 |
|
46 |
1.1 |
|
51 |
1.1 |
|
60 |
1.1 |
|
61 |
1.1 2.2 |
|
67 |
1.1 |
|
68 |
1.1 |
|
70 |
1.1 |
|
78 |
1.1 2.2 |
|
79 |
1.1 2.2 3.3 |
|
80 |
1.1 2.2 |
|
82 |
1.1 2.2 |
|
87 |
1.1 |
|
91 |
1.1 |