1 | package com.takenoko.actors; | |
2 | ||
3 | import com.takenoko.engine.Board; | |
4 | import com.takenoko.layers.bamboo.LayerBambooStack; | |
5 | import com.takenoko.vector.PositionVector; | |
6 | import com.takenoko.weather.Stormy; | |
7 | import com.takenoko.weather.Weather; | |
8 | import java.util.Map; | |
9 | import java.util.Optional; | |
10 | ||
11 | /** Panda class. The panda is an actor that can move on the board. */ | |
12 | public class Panda extends Actor { | |
13 | /** | |
14 | * Constructor for the Panda class. | |
15 | * | |
16 | * @param position the position of the panda | |
17 | */ | |
18 | public Panda(PositionVector position) { | |
19 | super(position); | |
20 | } | |
21 | ||
22 | /** Constructor for the Panda class. Instantiate the panda at the origin. */ | |
23 | public Panda() { | |
24 | this(new PositionVector(0, 0, 0)); | |
25 | } | |
26 | ||
27 | public Panda(Panda panda) { | |
28 | this(panda.getPositionVector().copy()); | |
29 | } | |
30 | ||
31 | /** | |
32 | * @return a string explaining where the panda is on the board | |
33 | */ | |
34 | public String positionMessage() { | |
35 |
1
1. positionMessage : replaced return value with "" for com/takenoko/actors/Panda::positionMessage → KILLED |
return "The panda is at " + this.getPositionVector(); |
36 | } | |
37 | ||
38 | /** | |
39 | * If the weather is a storm, the panda can move wherever he wants. Otherwise, the panda can | |
40 | * only move like a normal actor. | |
41 | * | |
42 | * @param vector the vector to move the panda | |
43 | * @param board the board on which the panda is moving | |
44 | * @return true if the move is possible, false otherwise | |
45 | */ | |
46 | @Override | |
47 | protected boolean isMovePossible(PositionVector vector, Board board) { | |
48 | Optional<Weather> weather = board.getWeather(); | |
49 |
2
1. isMovePossible : negated conditional → KILLED 2. isMovePossible : negated conditional → KILLED |
if (weather.isPresent() && weather.get().getClass().equals(Stormy.class)) { |
50 |
1
1. isMovePossible : replaced boolean return with false for com/takenoko/actors/Panda::isMovePossible → KILLED |
return true; |
51 | } | |
52 |
2
1. isMovePossible : replaced boolean return with false for com/takenoko/actors/Panda::isMovePossible → KILLED 2. isMovePossible : replaced boolean return with true for com/takenoko/actors/Panda::isMovePossible → KILLED |
return super.isMovePossible(vector, board); |
53 | } | |
54 | ||
55 | /** | |
56 | * After the panda moves, he can eat bamboo if there is bamboo on the tile he moved to. If there | |
57 | * is bamboo, the panda eats it and a map with the bamboo stack is returned. | |
58 | * | |
59 | * @param board the board on which the panda is moving | |
60 | * @return the bamboo stack that the panda ate | |
61 | */ | |
62 | public Map<PositionVector, LayerBambooStack> afterMove(Board board) { | |
63 | // check if the panda can eat bamboo | |
64 |
1
1. afterMove : negated conditional → KILLED |
if (board.isBambooEatableAt(this.getPositionVector())) { |
65 | // eat bamboo | |
66 |
1
1. afterMove : removed call to com/takenoko/engine/Board::eatBamboo → KILLED |
board.eatBamboo(this.getPositionVector()); |
67 |
1
1. afterMove : replaced return value with Collections.emptyMap for com/takenoko/actors/Panda::afterMove → KILLED |
return Map.of(this.getPositionVector(), new LayerBambooStack(1)); |
68 | } else { | |
69 |
1
1. afterMove : replaced return value with Collections.emptyMap for com/takenoko/actors/Panda::afterMove → TIMED_OUT |
return Map.of(); |
70 | } | |
71 | } | |
72 | ||
73 | public Panda copy() { | |
74 |
1
1. copy : replaced return value with null for com/takenoko/actors/Panda::copy → KILLED |
return new Panda(this); |
75 | } | |
76 | } | |
Mutations | ||
35 |
1.1 |
|
49 |
1.1 2.2 |
|
50 |
1.1 |
|
52 |
1.1 2.2 |
|
64 |
1.1 |
|
66 |
1.1 |
|
67 |
1.1 |
|
69 |
1.1 |
|
74 |
1.1 |