Commit 7cd1354f authored by Corentin Guillevic's avatar Corentin Guillevic
Browse files

Add the last tests for the SurvivalCard Powers ; Add some correction ; Rename...

Add the last tests for the SurvivalCard Powers ; Add some correction ; Rename PowerMoificator in PowerModifier
parent 8df229a8
......@@ -17,8 +17,8 @@ import fr.univnantes.alma.server.game.item.player.Player;
import fr.univnantes.alma.server.game.item.player.Traque;
import fr.univnantes.alma.server.game.item.power.Power;
import fr.univnantes.alma.server.game.item.power.PowerType;
import fr.univnantes.alma.server.game.item.power.modificator.PowerModificator;
import fr.univnantes.alma.server.game.item.power.modificator.PowerModificatorType;
import fr.univnantes.alma.server.game.item.power.modifier.PowerModifier;
import fr.univnantes.alma.server.game.item.power.modifier.PowerModifierType;
import fr.univnantes.alma.server.game.item.power.recurrent.PowerRecurrent;
import fr.univnantes.alma.server.game.utilitary.Conversion;
import fr.univnantes.alma.server.game.utilitary.Pair;
......@@ -501,7 +501,7 @@ public class Game implements GameInterface {
response = new Response(false, "You can play jeton only in Phase 2");
}
}
else if(gameRoundVariables.refugeIsActive() && placedJeton.getJeton().getType().equals(CIBLE)) {
else if(gameRoundVariables.refugeIsActive() && isJetonCibleOnThisPlace(placedJeton.getPlaces())) {
response = new Response(false, "Can't play JetonCible when Refuge is active");
}
else{
......@@ -556,7 +556,8 @@ public class Game implements GameInterface {
int cardsPerWillingness = 2 + traque.getNumberOfAdditionalCardsTakeBackPerPawnWillingnessLostWithResist();
int numberCard = Math.min(cardsPerWillingness * number, traque.defausseSize());
if(numberCard > 0) {
choosePlaceCardsAction(playerId, numberCard, traque.getDefausse());
List<PlaceCard> chosen = choosePlaceCardsAction(playerId, numberCard, traque.getDefausse());
traque.takeBackPlaceCard(chosen);
}
traque.getRights().setCanGiveUp(false);
traque.getRights().setCanResist(false);
......@@ -947,6 +948,8 @@ public class Game implements GameInterface {
List<TrackingCard> trackingCards = creature.getTrackingCardsPlayed();
boolean containsJetonCible = false;
boolean containsJetonArtemia = false;
boolean canPlaceOn6To10 = gameRoundVariables.canPlaceJetonCreatureOnPlaces6To10();
boolean placeBetween6To10 = false;
for(TrackingCard trackingCard : trackingCards) {
if(trackingCard.containsSymbol(CIBLE)){
......@@ -971,9 +974,14 @@ public class Game implements GameInterface {
return new Response(false, "JetonCreature can't be place on two adjacent places");
}
}
for(Place place : placedJeton.getPlaces()) {
if(Planet.placeToNumber(place) >= 6) {
placeBetween6To10 = true;
}
}
if( (type.equals(CIBLE) && containsJetonCible)
|| (type.equals(ARTEMIA) && (containsJetonArtemia || board.isArtemiaSquare()))
|| type.equals(JetonSymbol.CREATURE)) {
|| type.equals(JetonSymbol.CREATURE) && (canPlaceOn6To10 || !placeBetween6To10)) {
if(planet.placeJeton(placedJeton)) {
creature.playJeton(placedJeton.getJeton());
return new Response(true, "");
......@@ -1093,7 +1101,7 @@ public class Game implements GameInterface {
traque.takeBackPlayedPlaceCards();
}
else if(gameRoundVariables.ralliementIsActive() && gameRoundVariables.getPlayersWhoHasCaughtByCreature().contains(traque.getInGameId())) {
List<PlaceCard> placeCardsWhereIsJetonCreature = planet.getPlaceCardsWhereJetonIs(JetonSymbol.CREATURE);
List<PlaceCard> placeCardsWhereIsJetonCreature = planet.findPlaceCardsWhereJetonIs(JetonSymbol.CREATURE);
traque.takeBackPlaceCard(placeCardsWhereIsJetonCreature);
traque.throwAwayPlaceCard();
}
......@@ -1136,7 +1144,7 @@ public class Game implements GameInterface {
List<Power> newNextRoundPowers = new ArrayList<>();
for(Power power : nextRoundPowers) {
if(power.getType().equals(PowerType.MODIFICATOR)) {
applyModificatorPower((PowerModificator) power);
applyModificatorPower((PowerModifier) power);
}
else if(power.getType().equals(PowerType.RECURRENT)) {
PowerRecurrent powerRecurrent = (PowerRecurrent) power;
......@@ -1152,11 +1160,11 @@ public class Game implements GameInterface {
/**
* Apply a power modificator
*/
private void applyModificatorPower(PowerModificator power) {
PowerModificatorType type = power.getModificatorType();
private void applyModificatorPower(PowerModifier power) {
PowerModifierType type = power.getModificatorType();
Player player = getPlayer(power.getInGameIdPlayer());
if(player.getTeam().equals(CREATURE)) {
if(type.equals(PowerModificatorType.PLAYABLE_TRACKING_CARD)) {
if(type.equals(PowerModifierType.PLAYABLE_TRACKING_CARD)) {
creature.getRights().setMaxTrackingCardPlayable((int) power.getModifiedValue());
}
}
......@@ -1438,4 +1446,16 @@ public class Game implements GameInterface {
}
return map;
}
private boolean isJetonCibleOnThisPlace(List<Place> places) {
List<Place> jetonCiblePlaces = planet.findPlacesWhereJetonIs(CIBLE);
Iterator<Place> iterator = places.iterator();
boolean isJetonCibleOnThisPlace = false;
while (!isJetonCibleOnThisPlace && iterator.hasNext()) {
if(jetonCiblePlaces.contains(iterator.next())) {
isJetonCibleOnThisPlace = true;
}
}
return isJetonCibleOnThisPlace;
}
}
......@@ -6,10 +6,7 @@ import fr.univnantes.alma.server.game.item.Reserve;
import fr.univnantes.alma.server.game.item.board.Board;
import fr.univnantes.alma.server.game.item.board.BoardColor;
import fr.univnantes.alma.server.game.item.card.*;
import fr.univnantes.alma.server.game.item.jeton.Jeton;
import fr.univnantes.alma.server.game.item.jeton.JetonCreature;
import fr.univnantes.alma.server.game.item.jeton.JetonSymbol;
import fr.univnantes.alma.server.game.item.jeton.PlacedJeton;
import fr.univnantes.alma.server.game.item.jeton.*;
import fr.univnantes.alma.server.game.item.pioche.Pioche;
import fr.univnantes.alma.server.game.item.planet.PawnType;
import fr.univnantes.alma.server.game.item.planet.Place;
......@@ -19,8 +16,8 @@ import fr.univnantes.alma.server.game.item.player.Player;
import fr.univnantes.alma.server.game.item.player.PlayerTeam;
import fr.univnantes.alma.server.game.item.player.Traque;
import fr.univnantes.alma.server.game.item.power.Power;
import fr.univnantes.alma.server.game.item.power.modificator.PowerModificator;
import fr.univnantes.alma.server.game.item.power.modificator.PowerModificatorType;
import fr.univnantes.alma.server.game.item.power.modifier.PowerModifier;
import fr.univnantes.alma.server.game.item.power.modifier.PowerModifierType;
import fr.univnantes.alma.server.game.item.power.recurrent.PowerRecurrent;
import fr.univnantes.alma.server.game.utilitary.Pair;
......@@ -588,7 +585,7 @@ public class PowerApplicator {
List<String> powersDescription = database.findPowersDescription(RIVIERE);
int idPower = game.choosePower(idPlayer, powersDescription);
if(idPower == 0) {
Power power = new PowerModificator(idPlayer, PowerModificatorType.CHOOSABLE_PLACE_CARD, 2);
Power power = new PowerModifier(idPlayer, PowerModifierType.CHOOSABLE_PLACE_CARD, 2);
game.addPowerForNextRound(power);
}
else {
......@@ -749,8 +746,8 @@ public class PowerApplicator {
private static void applyPlaceBlueArtefact(int idPlayer, Game game, List<String> powersDescription) {
int idPower = game.choosePower(idPlayer, powersDescription);
if (idPower == 0) {
Power power1 = new PowerModificator(idPlayer, PowerModificatorType.CHOOSABLE_PLACE_CARD, 2);
Power power2 = new PowerModificator(idPlayer, PowerModificatorType.PLAYABLE_PLACE_CARD, 2);
Power power1 = new PowerModifier(idPlayer, PowerModifierType.CHOOSABLE_PLACE_CARD, 2);
Power power2 = new PowerModifier(idPlayer, PowerModifierType.PLAYABLE_PLACE_CARD, 2);
game.addPowerForNextRound(power1);
game.addPowerForNextRound(power2);
}
......@@ -840,9 +837,9 @@ public class PowerApplicator {
List<String> powersDescription = database.findPowersDescription(FJORD);
int idPower = game.choosePower(idPlayer, powersDescription);
if (idPower == 0) {
Power power = new PowerModificator(idPlayer, PowerModificatorType.CHOOSABLE_VISIBLE_ADDITIONAL_PLACE_CARD, 1);
Power power = new PowerModifier(idPlayer, PowerModifierType.CHOOSABLE_VISIBLE_ADDITIONAL_PLACE_CARD, 1);
game.addPowerForNextRound(power);
power = new PowerModificator(idPlayer, PowerModificatorType.USE_FJORD_IN_PREVIOUS_ROUND, null);
power = new PowerModifier(idPlayer, PowerModifierType.USE_FJORD_IN_PREVIOUS_ROUND, null);
game.addPowerForNextRound(power);
}
else {
......@@ -1042,7 +1039,7 @@ public class PowerApplicator {
BiConsumer<Integer, Game> action = (Integer id, Game g) -> {
Traque traque = (Traque) g.getPlayer(id);
List<PlaceCard> placeCards = traque.getPlaceCardsPlayed();
List<PlaceCard> jetonCiblePlaces = g.getPlanet().getPlaceCardsWhereJetonIs(JetonSymbol.CIBLE);
List<PlaceCard> jetonCiblePlaces = g.getPlanet().findPlaceCardsWhereJetonIs(JetonSymbol.CIBLE);
PlaceCard card = null;
PlaceCard aux;
//Find the placeCard who the player has been caught
......@@ -1224,7 +1221,7 @@ public class PowerApplicator {
}
private static void applyTrackingReperage(int idPlayer, Game game) {
Power power = new PowerModificator(idPlayer, PowerModificatorType.PLAYABLE_TRACKING_CARD, 2);
Power power = new PowerModifier(idPlayer, PowerModifierType.PLAYABLE_TRACKING_CARD, 2);
game.addPowerForNextRound(power);
}
......@@ -1406,8 +1403,8 @@ public class PowerApplicator {
private static void applySurvivalPlanques(int idPlayer, Game game) {
List<Place> places = game.choosePlace(idPlayer, 2);
List<SurvivalCard> survivalCards = game.getSurvivalCardPioche().draw(2);
Pair<Place, SurvivalCard> pair1 = new Pair<Place, SurvivalCard>(places.get(0), survivalCards.get(0));
Pair<Place, SurvivalCard> pair2 = new Pair<Place, SurvivalCard>(places.get(1), survivalCards.get(1));
Pair<Place, SurvivalCard> pair1 = new Pair<>(places.get(0), survivalCards.get(0));
Pair<Place, SurvivalCard> pair2 = new Pair<>(places.get(1), survivalCards.get(1));
game.getPlanet().putSurvivalCardOnPlace(Arrays.asList(pair1, pair2));
}
......@@ -1424,7 +1421,7 @@ public class PowerApplicator {
Pair<Place, Place> pair = chooseTwoAdjacentPlace(idPlayer, game);
PlacedJeton jetonCible = new PlacedJeton(JetonSymbol.CIBLE, Arrays.asList(pair.getKey(), pair.getValue()));
game.getPlanet().placeJeton(jetonCible);
game.getCreature().playJeton(new JetonCreature());
game.getCreature().playJeton(new JetonCible());
}
private static void applySurvivalRegeneration(int idPlayer, Game game) {
......@@ -1618,9 +1615,14 @@ public class PowerApplicator {
if(placeCards.isEmpty()) {
return;
}
int maxCardsToTakeBack = Math.min(numberCards,placeCards.size());
List<PlaceCard> cardsTakeBack = game.choosePlaceCardsAction(idPlayer, maxCardsToTakeBack, placeCards);
traque.takeBackPlaceCard(cardsTakeBack);
else if(placeCards.size() <= numberCards) {
traque.takeBackAllPlaceCardFromDefausse();
}
else {
int maxCardsToTakeBack = Math.min(numberCards,placeCards.size());
List<PlaceCard> cardsTakeBack = game.choosePlaceCardsAction(idPlayer, maxCardsToTakeBack, placeCards);
traque.takeBackPlaceCard(cardsTakeBack);
}
}
/**
......@@ -1728,7 +1730,6 @@ public class PowerApplicator {
choosableCards.add(pc);
}
}
PlaceCard copiedCard = game.choosePlaceCardsAction(idPlayer, 1, choosableCards).get(0);
applyPlaceCardPower(idPlayer, game, copiedCard.getCardName());
}
......@@ -1831,32 +1832,32 @@ public class PowerApplicator {
* @param game The game
*/
public static void moveTraqueOnAdjacentPlaceAndAddHimToRetraiteList(int idPlayer, Game game) {
Pair<Integer, Place> pair;
Pair<Integer, Place> playerAndPlace;
Player player;
Traque traque;
boolean isAdjacentPlace = false;
Planet planet = game.getPlanet();
List<PlaceCard> placeCards;
PlaceCard adjacent = null;
List<PlaceCard> placeCardsPlayed;
PlaceCard placeCardPlayedAndAdjacentToMovingPlace = null;
do{
pair = game.movePlayer(idPlayer);
player = game.getPlayer(pair.getKey());
playerAndPlace = game.movePlayer(idPlayer);
player = game.getPlayer(playerAndPlace.getKey());
checkPlayerIsNotCreature(player);
traque = (Traque) player;
placeCards = traque.getPlaceCards();
for(PlaceCard placeCard : placeCards) {
if(planet.isAdjacentPlaces(placeCard, pair.getValue())) {
adjacent = placeCard;
placeCardsPlayed = traque.getPlaceCardsPlayed();
for(PlaceCard placeCard : placeCardsPlayed) {
if(planet.isAdjacentPlaces(placeCard, playerAndPlace.getValue())) {
placeCardPlayedAndAdjacentToMovingPlace = placeCard;
isAdjacentPlace = true;
}
}
}
while (! isAdjacentPlace);
List<PlaceCard> placeCardsAfterMoving = placeCards;
placeCards.remove(adjacent);
placeCards.add(planet.placeToPlaceCard(pair.getValue()));
traque.addPlaceCardsAfterMoving(placeCards);
List<PlaceCard> placeCardsAfterMoving = new ArrayList<>(placeCardsPlayed);
placeCardsAfterMoving.remove(placeCardPlayedAndAdjacentToMovingPlace);
placeCardsAfterMoving.add(planet.placeToPlaceCard(playerAndPlace.getValue()));
traque.addPlaceCardsAfterMoving(placeCardsAfterMoving);
game.getGameRoundVariables().addPlayersWhoIsTargetByRetraite(traque.getInGameId());
}
......@@ -1869,7 +1870,7 @@ public class PowerApplicator {
public static void moveJetonOnAdjacentPlace(int idPlayer, Game game, JetonSymbol symbol) {
boolean isAdjacentPlace = false;
Planet planet = game.getPlanet();
List<Place> places = planet.getPlacesWhereJetonIs(symbol);
List<Place> places = planet.findPlacesWhereJetonIs(symbol);
Place adjacent = null;
do{
adjacent = game.choosePlace(idPlayer, 1, "Choose place adjacent to JetonCreature").get(0);
......@@ -1963,7 +1964,7 @@ public class PowerApplicator {
GameRoundVariables variables = game.getGameRoundVariables();
Planet planet = game.getPlanet();
if(variables.inertieTrackingCardIsPlayed()) {
List<Place> placesWhereJetonIs = planet.getPlacesWhereJetonIs(JetonSymbol.CIBLE);
List<Place> placesWhereJetonIs = planet.findPlacesWhereJetonIs(JetonSymbol.CIBLE);
boolean isTraqueOnThePlaces = false;
for(Traque traque : game.getTraques()) {
for(PlaceCard playerCard : traque.getPlaceCardsPlayed()) {
......@@ -1994,7 +1995,7 @@ public class PowerApplicator {
public static boolean checkIfAdjacentToJetonCible(Game game, PlaceCard placeCard) {
GameRoundVariables variables = game.getGameRoundVariables();
Planet planet = game.getPlanet();
List<Place> placesWhereJetonIs = planet.getPlacesWhereJetonIs(JetonSymbol.CIBLE);
List<Place> placesWhereJetonIs = planet.findPlacesWhereJetonIs(JetonSymbol.CIBLE);
boolean isAdjacent = false;
for(Place jetonPlace : placesWhereJetonIs){
if(planet.isAdjacentPlaces(placeCard, jetonPlace)){
......@@ -2007,7 +2008,7 @@ public class PowerApplicator {
public static PlaceCard findPlaceCardWhereTheJetonCibleIsAndAdjacent(Game game, PlaceCard placeCard) {
GameRoundVariables variables = game.getGameRoundVariables();
Planet planet = game.getPlanet();
List<Place> placesWhereJetonIs = planet.getPlacesWhereJetonIs(JetonSymbol.CIBLE);
List<Place> placesWhereJetonIs = planet.findPlacesWhereJetonIs(JetonSymbol.CIBLE);
PlaceCard jetonCiblePlaceCard = null;
for(Place jetonPlace : placesWhereJetonIs){
if(planet.isAdjacentPlaces(placeCard, jetonPlace)){
......
......@@ -20,7 +20,7 @@ public class Planet {
private Map<Place, List<Jeton>> mapPlaceToJetons;
private Map<Place, Boolean> blockedPlaces;
private Map<Place, SurvivalCard> placeSurvivalCardMap;
private Map<Place, List<SurvivalCard>> placeSurvivalCardMap;
private int numberMovesAllowInRound;
private PlaceDistribution placeDistribution;
private PlanetPawn planetPawn;
......@@ -64,7 +64,7 @@ public class Planet {
}
}
public List<Place> getPlacesWhereJetonIs(JetonSymbol symbol) {
public List<Place> findPlacesWhereJetonIs(JetonSymbol symbol) {
List<Place> places = new ArrayList<>();
List<Jeton> jetonsAux;
for(Place place : mapPlaceToJetons.keySet()) {
......@@ -78,7 +78,7 @@ public class Planet {
return places;
}
public List<PlaceCard> getPlaceCardsWhereJetonIs(JetonSymbol symbol) {
public List<PlaceCard> findPlaceCardsWhereJetonIs(JetonSymbol symbol) {
List<PlaceCard> placeCards = new ArrayList<>();
List<Jeton> jetonsAux;
for(Place place : mapPlaceToJetons.keySet()) {
......@@ -244,11 +244,18 @@ public class Planet {
}
public SurvivalCard takeSurvivalCardOnPlace(Place place) {
SurvivalCard survivalCard = placeSurvivalCardMap.getOrDefault(place, null);
if(survivalCard != null) {
placeSurvivalCardMap.remove(place);
List<SurvivalCard> survivalCards = placeSurvivalCardMap.getOrDefault(place, null);
SurvivalCard cardCaught = null;
if(survivalCards != null) {
if(!survivalCards.isEmpty()) {
cardCaught = survivalCards.get(0);
survivalCards.remove(cardCaught);
}
if(survivalCards.isEmpty()) {
placeSurvivalCardMap.remove(place);
}
}
return survivalCard;
return cardCaught;
}
public SurvivalCard takeSurvivalCardOnPlace(PlaceCard placeCard) {
......@@ -257,7 +264,8 @@ public class Planet {
public void putSurvivalCardOnPlace(Pair<Place, SurvivalCard> pair) {
placeSurvivalCardMap.putIfAbsent(pair.getKey(), pair.getValue());
placeSurvivalCardMap.putIfAbsent(pair.getKey(), new ArrayList<>());
placeSurvivalCardMap.get(pair.getKey()).add(pair.getValue());
}
public void putSurvivalCardOnPlace(List<Pair<Place, SurvivalCard>> pairs) {
......
package fr.univnantes.alma.server.game.item.power.modificator;
package fr.univnantes.alma.server.game.item.power.modifier;
import fr.univnantes.alma.server.game.item.power.Power;
import fr.univnantes.alma.server.game.item.power.PowerType;
public class PowerModificator extends Power {
public class PowerModifier extends Power {
private PowerModificatorType modificatorType;
private PowerModifierType modificatorType;
private Object modifiedValue;
public PowerModificator(int playerId, PowerModificatorType modificatorType, Object modifiedValue) {
public PowerModifier(int playerId, PowerModifierType modificatorType, Object modifiedValue) {
super(playerId);
this.modificatorType = modificatorType;
this.modifiedValue = modifiedValue;
}
public PowerModificatorType getModificatorType() {
public PowerModifierType getModificatorType() {
return modificatorType;
}
......
package fr.univnantes.alma.server.game.item.power.modificator;
package fr.univnantes.alma.server.game.item.power.modifier;
public enum PowerModificatorType {
public enum PowerModifierType {
CHOOSABLE_PLACE_CARD, PLAYABLE_PLACE_CARD, CHOOSABLE_VISIBLE_ADDITIONAL_PLACE_CARD, PLAYABLE_TRACKING_CARD,
USE_FJORD_IN_PREVIOUS_ROUND
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment