UpdatePlayer.java

1
package re.forestier.edu.rpg;
2
3
import java.util.HashMap;
4
import java.util.Random;
5
6
public class UpdatePlayer {
7
8
    private final static String[] objectList = {"Lookout Ring : Prevents surprise attacks","Scroll of Stupidity : INT-2 when applied to an enemy", "Draupnir : Increases XP gained by 100%", "Magic Charm : Magic +10 for 5 rounds", "Rune Staff of Curse : May burn your ennemies... Or yourself. Who knows?", "Combat Edge : Well, that's an edge", "Holy Elixir : Recover your HP"
9
    };
10
11
    public static HashMap<String, HashMap<Integer, HashMap<String, Integer>>> abilitiesPerTypeAndLevel() {
12
        HashMap<String, HashMap<Integer, HashMap<String, Integer>>> abilitiesPerTypeAndLevel = new HashMap<>();
13
14
        HashMap<Integer, HashMap<String, Integer>> adventurerMap = new HashMap<>();
15
        HashMap<String, Integer> adventurerLevel1 = new HashMap<>();
16
        adventurerLevel1.put("INT", 1);
17
        adventurerLevel1.put("DEF", 1);
18
        adventurerLevel1.put("ATK", 3);
19
        adventurerLevel1.put("CHA", 2);
20
        adventurerMap.put(1, adventurerLevel1);
21
22
        HashMap<String, Integer> adventurerLevel2 = new HashMap<>();
23
        adventurerLevel1.put("INT", 2);
24
        adventurerLevel1.put("CHA", 3);
25
        adventurerMap.put(2, adventurerLevel2);
26
27
        HashMap<String, Integer> adventurerLevel3 = new HashMap<>();
28
        adventurerLevel3.put("ATK", 5);
29
        adventurerLevel3.put("ALC", 1);
30
        adventurerMap.put(3, adventurerLevel3);
31
32
        HashMap<String, Integer> adventurerLevel4 = new HashMap<>();
33
        adventurerLevel4.put("DEF", 3);
34
        adventurerMap.put(4, adventurerLevel4);
35
36
        HashMap<String, Integer> adventurerLevel5 = new HashMap<>();
37
        adventurerLevel5.put("VIS", 1);
38
        adventurerLevel5.put("DEF", 4);
39
        adventurerMap.put(5, adventurerLevel5);
40
41
        abilitiesPerTypeAndLevel.put("ADVENTURER", adventurerMap);
42
43
44
        HashMap<Integer, HashMap<String, Integer>> archerMap = new HashMap<>();
45
        HashMap<String, Integer> archerLevel1 = new HashMap<>();
46
        archerLevel1.put("INT", 1);
47
        archerLevel1.put("ATK", 3);
48
        archerLevel1.put("CHA", 1);
49
        archerLevel1.put("VIS", 3);
50
        archerMap.put(1, archerLevel1);
51
52
        HashMap<String, Integer> archerLevel2 = new HashMap<>();
53
        archerLevel2.put("DEF", 1);
54
        archerLevel2.put("CHA", 2);
55
        archerMap.put(2, archerLevel2);
56
57
        HashMap<String, Integer> archerLevel3 = new HashMap<>();
58
        archerLevel3.put("ATK", 3);
59
        archerMap.put(3, archerLevel3);
60
61
        HashMap<String, Integer> archerLevel4 = new HashMap<>();
62
        archerLevel4.put("DEF", 2);
63
        archerMap.put(4, archerLevel4);
64
65
        HashMap<String, Integer> archerLevel5 = new HashMap<>();
66
        archerLevel5.put("ATK", 4);
67
        archerMap.put(5, archerLevel5);
68
69
        abilitiesPerTypeAndLevel.put("ARCHER", archerMap);
70
71
72
        HashMap<Integer, HashMap<String, Integer>> dwarf = new HashMap<>();
73
        HashMap<String, Integer> dwarfLevel1 = new HashMap<>();
74
        dwarfLevel1.put("ALC", 4);
75
        dwarfLevel1.put("INT", 1);
76
        dwarfLevel1.put("ATK", 3);
77
        dwarf.put(1, dwarfLevel1);
78
79
        HashMap<String, Integer> dwarfLevel2 = new HashMap<>();
80
        dwarfLevel2.put("DEF", 1);
81
        dwarfLevel2.put("ALC", 5);
82
        dwarf.put(2, dwarfLevel2);
83
84
        HashMap<String, Integer> dwarfLevel3 = new HashMap<>();
85
        dwarfLevel3.put("ATK", 4);
86
        dwarf.put(3, dwarfLevel3);
87
88
        HashMap<String, Integer> dwarfLevel4 = new HashMap<>();
89
        dwarfLevel4.put("DEF", 2);
90
        dwarf.put(4, dwarfLevel4);
91
92
        HashMap<String, Integer> dwarfLevel5 = new HashMap<>();
93
        dwarfLevel5.put("CHA", 1);
94
        dwarf.put(5, dwarfLevel5);
95
96
        abilitiesPerTypeAndLevel.put("DWARF", dwarf);
97
98 1 1. abilitiesPerTypeAndLevel : replaced return value with null for re/forestier/edu/rpg/UpdatePlayer::abilitiesPerTypeAndLevel → KILLED
        return abilitiesPerTypeAndLevel;
99
    }
100
101
    public static boolean addXp(player player, int xp) {
102
        int currentLevel = player.retrieveLevel();
103 1 1. addXp : Replaced integer addition with subtraction → KILLED
        player.xp += xp;
104
        int newLevel = player.retrieveLevel();
105
106 1 1. addXp : negated conditional → KILLED
        if (newLevel != currentLevel) {
107
            // Player leveled-up!
108
            // Give a random object
109
            ;
110
            Random random = new Random();
111 2 1. addXp : Replaced integer subtraction with addition → SURVIVED
2. addXp : Replaced integer addition with subtraction → SURVIVED
            player.inventory.add(objectList[random.nextInt(objectList.length - 0) + 0]);
112
113
            // Add/upgrade abilities to player
114
            HashMap<String, Integer> abilities = abilitiesPerTypeAndLevel().get(player.getAvatarClass()).get(newLevel);
115 1 1. addXp : removed call to java/util/HashMap::forEach → KILLED
            abilities.forEach((ability, level) -> {
116
                player.abilities.put(ability, abilities.get(ability));
117
            });
118 1 1. addXp : replaced boolean return with false for re/forestier/edu/rpg/UpdatePlayer::addXp → KILLED
            return true;
119
        }
120 1 1. addXp : replaced boolean return with true for re/forestier/edu/rpg/UpdatePlayer::addXp → KILLED
        return false;
121
    }
122
123
124
125
    // majFinDeTour met à jour les points de vie
126
    public static void majFinDeTour(player player) {
127 1 1. majFinDeTour : negated conditional → KILLED
        if(player.currenthealthpoints == 0) {
128 1 1. majFinDeTour : removed call to java/io/PrintStream::println → KILLED
            System.out.println("Le joueur est KO !");
129
            return;
130
        }
131
132 3 1. majFinDeTour : changed conditional boundary → KILLED
2. majFinDeTour : Replaced integer division with multiplication → KILLED
3. majFinDeTour : negated conditional → KILLED
        if(player.currenthealthpoints < player.healthpoints/2) {
133 1 1. majFinDeTour : negated conditional → KILLED
            if(!player.getAvatarClass().equals("ADVENTURER")) {
134 1 1. majFinDeTour : negated conditional → KILLED
                if(player.getAvatarClass().equals("DWARF")) {
135 1 1. majFinDeTour : negated conditional → KILLED
                    if(player.inventory.contains("Holy Elixir")) {
136 1 1. majFinDeTour : Replaced integer addition with subtraction → KILLED
                        player.currenthealthpoints+=1;
137
                    }
138 1 1. majFinDeTour : Replaced integer addition with subtraction → KILLED
                    player.currenthealthpoints+=1;
139 1 1. majFinDeTour : negated conditional → KILLED
                } else if(player.getAvatarClass().equals("ADVENTURER")) {
140 1 1. majFinDeTour : Replaced integer addition with subtraction → NO_COVERAGE
                    player.currenthealthpoints+=2;
141
                }
142
143
144 1 1. majFinDeTour : negated conditional → KILLED
                if(player.getAvatarClass().equals("ARCHER")) {
145 1 1. majFinDeTour : Replaced integer addition with subtraction → KILLED
                    player.currenthealthpoints+=1;
146 1 1. majFinDeTour : negated conditional → KILLED
                    if(player.inventory.contains("Magic Bow")) {
147 3 1. majFinDeTour : Replaced integer subtraction with addition → KILLED
2. majFinDeTour : Replaced integer division with multiplication → KILLED
3. majFinDeTour : Replaced integer addition with subtraction → KILLED
                        player.currenthealthpoints+=player.currenthealthpoints/8-1;
148
                    }
149
                }
150
            } else {
151 1 1. majFinDeTour : Replaced integer addition with subtraction → KILLED
                player.currenthealthpoints+=2;
152 2 1. majFinDeTour : changed conditional boundary → KILLED
2. majFinDeTour : negated conditional → KILLED
                if(player.retrieveLevel() < 3) {
153 1 1. majFinDeTour : Replaced integer subtraction with addition → KILLED
                    player.currenthealthpoints-=1;
154
                }
155
            }
156 3 1. majFinDeTour : changed conditional boundary → SURVIVED
2. majFinDeTour : Replaced integer division with multiplication → SURVIVED
3. majFinDeTour : negated conditional → SURVIVED
        } else if(player.currenthealthpoints >= player.healthpoints/2){
157 2 1. majFinDeTour : changed conditional boundary → SURVIVED
2. majFinDeTour : negated conditional → KILLED
            if(player.currenthealthpoints >= player.healthpoints) {
158
                player.currenthealthpoints = player.healthpoints;
159
                return;
160
            }
161
        }
162
163
164 2 1. majFinDeTour : changed conditional boundary → SURVIVED
2. majFinDeTour : negated conditional → KILLED
        if(player.currenthealthpoints >= player.healthpoints) {
165
            player.currenthealthpoints = player.healthpoints;
166
        }
167
    }
168
169
170
}

Mutations

98

1.1
Location : abilitiesPerTypeAndLevel
Killed by : re.forestier.edu.UnitTests.[engine:junit-jupiter]/[class:re.forestier.edu.UnitTests]/[method:testPlayerName()]
replaced return value with null for re/forestier/edu/rpg/UpdatePlayer::abilitiesPerTypeAndLevel → KILLED

103

1.1
Location : addXp
Killed by : re.forestier.edu.UnitTests.[engine:junit-jupiter]/[class:re.forestier.edu.UnitTests]/[method:testRetrieveLevel()]
Replaced integer addition with subtraction → KILLED

106

1.1
Location : addXp
Killed by : re.forestier.edu.UnitTests.[engine:junit-jupiter]/[class:re.forestier.edu.UnitTests]/[method:testRetrieveLevel()]
negated conditional → KILLED

111

1.1
Location : addXp
Killed by : none
Replaced integer subtraction with addition → SURVIVED

2.2
Location : addXp
Killed by : none
Replaced integer addition with subtraction → SURVIVED

115

1.1
Location : addXp
Killed by : re.forestier.edu.UnitTests.[engine:junit-jupiter]/[class:re.forestier.edu.UnitTests]/[method:testRetrieveLevel()]
removed call to java/util/HashMap::forEach → KILLED

118

1.1
Location : addXp
Killed by : re.forestier.edu.UnitTests.[engine:junit-jupiter]/[class:re.forestier.edu.UnitTests]/[method:testRetrieveLevel()]
replaced boolean return with false for re/forestier/edu/rpg/UpdatePlayer::addXp → KILLED

120

1.1
Location : addXp
Killed by : re.forestier.edu.UnitTests.[engine:junit-jupiter]/[class:re.forestier.edu.UnitTests]/[method:testRetrieveLevel()]
replaced boolean return with true for re/forestier/edu/rpg/UpdatePlayer::addXp → KILLED

127

1.1
Location : majFinDeTour
Killed by : re.forestier.edu.UnitTests.[engine:junit-jupiter]/[class:re.forestier.edu.UnitTests]/[method:testMajFinTour()]
negated conditional → KILLED

128

1.1
Location : majFinDeTour
Killed by : re.forestier.edu.UnitTests.[engine:junit-jupiter]/[class:re.forestier.edu.UnitTests]/[method:testMajFinTour()]
removed call to java/io/PrintStream::println → KILLED

132

1.1
Location : majFinDeTour
Killed by : re.forestier.edu.UnitTests.[engine:junit-jupiter]/[class:re.forestier.edu.UnitTests]/[method:testMajFinTour()]
changed conditional boundary → KILLED

2.2
Location : majFinDeTour
Killed by : re.forestier.edu.UnitTests.[engine:junit-jupiter]/[class:re.forestier.edu.UnitTests]/[method:testMajFinTour()]
Replaced integer division with multiplication → KILLED

3.3
Location : majFinDeTour
Killed by : re.forestier.edu.UnitTests.[engine:junit-jupiter]/[class:re.forestier.edu.UnitTests]/[method:testMajFinTour()]
negated conditional → KILLED

133

1.1
Location : majFinDeTour
Killed by : re.forestier.edu.UnitTests.[engine:junit-jupiter]/[class:re.forestier.edu.UnitTests]/[method:testMajFinTour()]
negated conditional → KILLED

134

1.1
Location : majFinDeTour
Killed by : re.forestier.edu.UnitTests.[engine:junit-jupiter]/[class:re.forestier.edu.UnitTests]/[method:testMajFinTour()]
negated conditional → KILLED

135

1.1
Location : majFinDeTour
Killed by : re.forestier.edu.UnitTests.[engine:junit-jupiter]/[class:re.forestier.edu.UnitTests]/[method:testMajFinTour()]
negated conditional → KILLED

136

1.1
Location : majFinDeTour
Killed by : re.forestier.edu.UnitTests.[engine:junit-jupiter]/[class:re.forestier.edu.UnitTests]/[method:testMajFinTour()]
Replaced integer addition with subtraction → KILLED

138

1.1
Location : majFinDeTour
Killed by : re.forestier.edu.UnitTests.[engine:junit-jupiter]/[class:re.forestier.edu.UnitTests]/[method:testMajFinTour()]
Replaced integer addition with subtraction → KILLED

139

1.1
Location : majFinDeTour
Killed by : re.forestier.edu.UnitTests.[engine:junit-jupiter]/[class:re.forestier.edu.UnitTests]/[method:testMajFinTour()]
negated conditional → KILLED

140

1.1
Location : majFinDeTour
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

144

1.1
Location : majFinDeTour
Killed by : re.forestier.edu.UnitTests.[engine:junit-jupiter]/[class:re.forestier.edu.UnitTests]/[method:testMajFinTour()]
negated conditional → KILLED

145

1.1
Location : majFinDeTour
Killed by : re.forestier.edu.UnitTests.[engine:junit-jupiter]/[class:re.forestier.edu.UnitTests]/[method:testMajFinTour()]
Replaced integer addition with subtraction → KILLED

146

1.1
Location : majFinDeTour
Killed by : re.forestier.edu.UnitTests.[engine:junit-jupiter]/[class:re.forestier.edu.UnitTests]/[method:testMajFinTour()]
negated conditional → KILLED

147

1.1
Location : majFinDeTour
Killed by : re.forestier.edu.UnitTests.[engine:junit-jupiter]/[class:re.forestier.edu.UnitTests]/[method:testMajFinTour()]
Replaced integer subtraction with addition → KILLED

2.2
Location : majFinDeTour
Killed by : re.forestier.edu.UnitTests.[engine:junit-jupiter]/[class:re.forestier.edu.UnitTests]/[method:testMajFinTour()]
Replaced integer division with multiplication → KILLED

3.3
Location : majFinDeTour
Killed by : re.forestier.edu.UnitTests.[engine:junit-jupiter]/[class:re.forestier.edu.UnitTests]/[method:testMajFinTour()]
Replaced integer addition with subtraction → KILLED

151

1.1
Location : majFinDeTour
Killed by : re.forestier.edu.UnitTests.[engine:junit-jupiter]/[class:re.forestier.edu.UnitTests]/[method:testMajFinTour()]
Replaced integer addition with subtraction → KILLED

152

1.1
Location : majFinDeTour
Killed by : re.forestier.edu.UnitTests.[engine:junit-jupiter]/[class:re.forestier.edu.UnitTests]/[method:testMajFinTour()]
changed conditional boundary → KILLED

2.2
Location : majFinDeTour
Killed by : re.forestier.edu.UnitTests.[engine:junit-jupiter]/[class:re.forestier.edu.UnitTests]/[method:testMajFinTour()]
negated conditional → KILLED

153

1.1
Location : majFinDeTour
Killed by : re.forestier.edu.UnitTests.[engine:junit-jupiter]/[class:re.forestier.edu.UnitTests]/[method:testMajFinTour()]
Replaced integer subtraction with addition → KILLED

156

1.1
Location : majFinDeTour
Killed by : none
changed conditional boundary → SURVIVED

2.2
Location : majFinDeTour
Killed by : none
Replaced integer division with multiplication → SURVIVED

3.3
Location : majFinDeTour
Killed by : none
negated conditional → SURVIVED

157

1.1
Location : majFinDeTour
Killed by : re.forestier.edu.UnitTests.[engine:junit-jupiter]/[class:re.forestier.edu.UnitTests]/[method:testMajFinTour()]
negated conditional → KILLED

2.2
Location : majFinDeTour
Killed by : none
changed conditional boundary → SURVIVED

164

1.1
Location : majFinDeTour
Killed by : re.forestier.edu.UnitTests.[engine:junit-jupiter]/[class:re.forestier.edu.UnitTests]/[method:testMajFinTour()]
negated conditional → KILLED

2.2
Location : majFinDeTour
Killed by : none
changed conditional boundary → SURVIVED

Active mutators

Tests examined


Report generated by PIT 1.15.0