1 | package com.takenoko.engine; | |
2 | ||
3 | import java.util.HashMap; | |
4 | import java.util.List; | |
5 | import java.util.Map; | |
6 | ||
7 | /** This class is used to store the number of win for each bot. */ | |
8 | public class Scoreboard { | |
9 | private final HashMap<BotManager, Integer> numberOfVictoryHashMap; | |
10 | private final HashMap<BotManager, Integer> totalScore; | |
11 | ||
12 | public Scoreboard() { | |
13 | totalScore = new HashMap<>(); | |
14 | numberOfVictoryHashMap = new HashMap<>(); | |
15 | } | |
16 | ||
17 | public Map<BotManager, Integer> getTotalScore() { | |
18 |
1
1. getTotalScore : replaced return value with Collections.emptyMap for com/takenoko/engine/Scoreboard::getTotalScore → KILLED |
return totalScore; |
19 | } | |
20 | ||
21 | public void addBotManager(BotManager botManager) { | |
22 | totalScore.put(botManager, 0); | |
23 | numberOfVictoryHashMap.put(botManager, 0); | |
24 | } | |
25 | ||
26 | public void addBotManager(List<BotManager> botManagerList) { | |
27 | for (BotManager botManager : botManagerList) { | |
28 |
1
1. addBotManager : removed call to com/takenoko/engine/Scoreboard::addBotManager → KILLED |
addBotManager(botManager); |
29 | } | |
30 | } | |
31 | ||
32 | public void incrementNumberOfVictory(BotManager botManager) { | |
33 |
1
1. incrementNumberOfVictory : Replaced integer addition with subtraction → KILLED |
numberOfVictoryHashMap.put(botManager, numberOfVictoryHashMap.get(botManager) + 1); |
34 | } | |
35 | ||
36 | public void updateScore(BotManager botManager, int scoreToAdd) { | |
37 |
1
1. updateScore : Replaced integer addition with subtraction → KILLED |
totalScore.put(botManager, totalScore.get(botManager) + scoreToAdd); |
38 | } | |
39 | ||
40 | @Override | |
41 | public String toString() { | |
42 | StringBuilder stringBuilder = new StringBuilder(); | |
43 | String lineJump = "\n \t \t \t"; | |
44 | stringBuilder.append("============== Scoreboard ==============").append(lineJump); | |
45 | for (Map.Entry<BotManager, Integer> entry : numberOfVictoryHashMap.entrySet()) { | |
46 | stringBuilder | |
47 | .append("< ") | |
48 | .append(entry.getKey().getName()) | |
49 | .append(" : Wins-") | |
50 | .append(entry.getValue()) | |
51 | .append(" Total Score-") | |
52 | .append(totalScore.get(entry.getKey())) | |
53 | .append(" > | ") | |
54 | .append(lineJump); | |
55 | } | |
56 |
1
1. toString : replaced return value with "" for com/takenoko/engine/Scoreboard::toString → KILLED |
return stringBuilder.toString(); |
57 | } | |
58 | ||
59 | public int getNumberOfVictory(BotManager botManager) { | |
60 |
1
1. getNumberOfVictory : replaced int return with 0 for com/takenoko/engine/Scoreboard::getNumberOfVictory → KILLED |
return numberOfVictoryHashMap.get(botManager); |
61 | } | |
62 | ||
63 | public List<BotManager> getBotManagers() { | |
64 |
1
1. getBotManagers : replaced return value with Collections.emptyList for com/takenoko/engine/Scoreboard::getBotManagers → KILLED |
return List.copyOf(numberOfVictoryHashMap.keySet()); |
65 | } | |
66 | } | |
Mutations | ||
18 |
1.1 |
|
28 |
1.1 |
|
33 |
1.1 |
|
37 |
1.1 |
|
56 |
1.1 |
|
60 |
1.1 |
|
64 |
1.1 |