| 1 | package com.takenoko.actions.actors; | |
| 2 | ||
| 3 | import com.takenoko.actions.ActionResult; | |
| 4 | import com.takenoko.actions.DefaultAction; | |
| 5 | import com.takenoko.actions.annotations.ActionAnnotation; | |
| 6 | import com.takenoko.actions.annotations.ActionType; | |
| 7 | import com.takenoko.engine.Board; | |
| 8 | import com.takenoko.engine.BotManager; | |
| 9 | import com.takenoko.layers.bamboo.LayerBambooStack; | |
| 10 | import com.takenoko.vector.PositionVector; | |
| 11 | import java.util.Map; | |
| 12 | import java.util.Objects; | |
| 13 | ||
| 14 | /** This class represents the action of moving the panda. */ | |
| 15 | @ActionAnnotation(ActionType.DEFAULT) | |
| 16 | public class MovePandaAction implements DefaultAction { | |
| 17 | private final PositionVector relativePositionVector; | |
| 18 | ||
| 19 | /** | |
| 20 | * Constructor for the MovePandaAction class. | |
| 21 | * | |
| 22 | * @param relativePositionVector the position vector to move the panda | |
| 23 | */ | |
| 24 | public MovePandaAction(PositionVector relativePositionVector) { | |
| 25 | this.relativePositionVector = relativePositionVector; | |
| 26 | } | |
| 27 | ||
| 28 | public static boolean canBePlayed(Board board) { | |
| 29 |
2
1. canBePlayed : negated conditional → KILLED 2. canBePlayed : replaced boolean return with true for com/takenoko/actions/actors/MovePandaAction::canBePlayed → KILLED |
return !board.getTilesWithoutPond().isEmpty(); |
| 30 | } | |
| 31 | ||
| 32 | /** | |
| 33 | * Move the panda with a vector on the board and display a message. | |
| 34 | * | |
| 35 | * @param board the board | |
| 36 | * @param botManager the bot manager | |
| 37 | * @return the action result | |
| 38 | */ | |
| 39 | @Override | |
| 40 | public ActionResult execute(Board board, BotManager botManager) { | |
| 41 | // move the panda | |
| 42 | Map<PositionVector, LayerBambooStack> bambooStack = board.movePanda(relativePositionVector); | |
| 43 |
1
1. execute : removed call to com/takenoko/engine/BotManager::displayMessage → TIMED_OUT |
botManager.displayMessage( |
| 44 | botManager.getName() | |
| 45 | + " moved the panda with " | |
| 46 | + relativePositionVector | |
| 47 | + " to position " | |
| 48 | + board.getPandaPosition()); | |
| 49 | ||
| 50 |
1
1. execute : negated conditional → KILLED |
if (!bambooStack.isEmpty()) { |
| 51 | // eat bamboo | |
| 52 | botManager | |
| 53 | .getInventory() | |
| 54 |
1
1. execute : removed call to com/takenoko/inventory/Inventory::collectBamboo → KILLED |
.collectBamboo(board.getTileAt(board.getPandaPosition()).getColor()); |
| 55 | botManager | |
| 56 | .getSingleBotStatistics() | |
| 57 |
1
1. execute : removed call to com/takenoko/stats/SingleBotStatistics::updateEatenBambooCounter → KILLED |
.updateEatenBambooCounter(board.getTileAt(board.getPandaPosition()).getColor()); |
| 58 |
1
1. execute : removed call to com/takenoko/stats/SingleBotStatistics::updateActions → KILLED |
botManager.getSingleBotStatistics().updateActions(getClass().getSimpleName()); |
| 59 |
1
1. execute : removed call to com/takenoko/engine/BotManager::displayMessage → TIMED_OUT |
botManager.displayMessage( |
| 60 | "Panda ate one " | |
| 61 | + board.getTileAt(board.getPandaPosition()).getColor() | |
| 62 | + " bamboo for " | |
| 63 | + botManager.getName()); | |
| 64 | } else { | |
| 65 | // no bamboo to eat | |
| 66 |
1
1. execute : removed call to com/takenoko/engine/BotManager::displayMessage → TIMED_OUT |
botManager.displayMessage("Panda didn't eat any bamboo"); |
| 67 | } | |
| 68 |
1
1. execute : replaced return value with null for com/takenoko/actions/actors/MovePandaAction::execute → KILLED |
return new ActionResult(1); |
| 69 | } | |
| 70 | ||
| 71 | @Override | |
| 72 | public String toString() { | |
| 73 |
1
1. toString : replaced return value with "" for com/takenoko/actions/actors/MovePandaAction::toString → TIMED_OUT |
return "MovePandaAction {pos_vect=" + relativePositionVector + "}"; |
| 74 | } | |
| 75 | ||
| 76 | @Override | |
| 77 | public boolean equals(Object o) { | |
| 78 |
2
1. equals : replaced boolean return with false for com/takenoko/actions/actors/MovePandaAction::equals → NO_COVERAGE 2. equals : negated conditional → TIMED_OUT |
if (this == o) return true; |
| 79 |
3
1. equals : negated conditional → TIMED_OUT 2. equals : negated conditional → TIMED_OUT 3. equals : replaced boolean return with true for com/takenoko/actions/actors/MovePandaAction::equals → TIMED_OUT |
if (o == null || getClass() != o.getClass()) return false; |
| 80 | MovePandaAction that = (MovePandaAction) o; | |
| 81 |
2
1. equals : replaced boolean return with false for com/takenoko/actions/actors/MovePandaAction::equals → TIMED_OUT 2. equals : replaced boolean return with true for com/takenoko/actions/actors/MovePandaAction::equals → TIMED_OUT |
return Objects.equals(relativePositionVector, that.relativePositionVector); |
| 82 | } | |
| 83 | ||
| 84 | @Override | |
| 85 | public int hashCode() { | |
| 86 |
1
1. hashCode : replaced int return with 0 for com/takenoko/actions/actors/MovePandaAction::hashCode → TIMED_OUT |
return Objects.hash(relativePositionVector); |
| 87 | } | |
| 88 | } | |
Mutations | ||
| 29 |
1.1 2.2 |
|
| 43 |
1.1 |
|
| 50 |
1.1 |
|
| 54 |
1.1 |
|
| 57 |
1.1 |
|
| 58 |
1.1 |
|
| 59 |
1.1 |
|
| 66 |
1.1 |
|
| 68 |
1.1 |
|
| 73 |
1.1 |
|
| 78 |
1.1 2.2 |
|
| 79 |
1.1 2.2 3.3 |
|
| 81 |
1.1 2.2 |
|
| 86 |
1.1 |