Fix: PickOptionalCard

This commit is contained in:
rubenpirreram
2026-04-02 17:10:52 +02:00
parent 5d273e66fe
commit 1e5037378d
@@ -27,28 +27,21 @@ public class Game {
private OrderLogicCard orderLogicCard; private OrderLogicCard orderLogicCard;
private Board board; private Board board;
public List<TribeCard>getUpperListTribeCards() {
List<TribeCard> cards = new ArrayList<>();
board.upperListTribe.forEach(x->cards.add(x.clone()));
return cards;
}
public CurrentState getCurrentState() {
return currentState;
};
public Player getPlayerByIndex(int playerIndex) throws IndexOutOfBoundsException { public Player getPlayerByIndex(int playerIndex) throws IndexOutOfBoundsException {
if(playerIndex >= playersList.size()) if(playerIndex >= playersList.size())
throw new IndexOutOfBoundsException("Player index out of bounds"); throw new IndexOutOfBoundsException("Player index out of bounds");
return playersList.get(playerIndex); return playersList.get(playerIndex);
} }
/*
public TribeCard getUpperTribeCardByIndex(int playerIndex) throws IndexOutOfBoundsException
{
}
public TribeCard getLowerTribeCardByIndex()
{
}
public BuildingCard getUpperBuildingCardByIndex(int playerIndex) throws IndexOutOfBoundsException
{
}
public BuildingCard getLowerBuildingCardByIndex(int playerIndex) throws IndexOutOfBoundsException
{
}
*/
public int getNPlayers() { public int getNPlayers() {
return nPlayers; return nPlayers;
@@ -69,14 +62,14 @@ public class Game {
public boolean addPlayer(Player player) { public boolean addPlayer(Player player) {
if(currentState.getGameStage()!= GameStages.WAITING) if(currentState.getGameStage()!= GameStages.WAITING)
return false; return false;
if(playersList.contains(player))
return false;
playersList.add(player); playersList.add(player);
if(playersList.size()>=nPlayers) if(playersList.size()>=nPlayers)
{ {
init(); init();
return true;
} }
return false; return true;
} }
public void init() { public void init() {
@@ -99,7 +92,9 @@ public class Game {
} }
//region Cotroller Methods //region Cotroller Methods
public boolean SlotChoice(Player player, Slot slot) { public boolean SlotChoiceByIndex(Player player, int slotIndex) {
if(slotIndex<0 || slotIndex>=slotMap.size())
return false;
if(currentState.getGameStage()!= GameStages.SLOT_CHOICE) if(currentState.getGameStage()!= GameStages.SLOT_CHOICE)
{ {
return false; return false;
@@ -108,23 +103,21 @@ public class Game {
{ {
return false; return false;
} }
Map.Entry<Slot, Player> slotPlayerEntry = new ArrayList<>(slotMap.entrySet()).get(slotIndex);
if(slotMap.get(slot)!=null) if(slotPlayerEntry.getValue()!=null)
{ {
return false; return false;
} }
if(!board.getSlotList().contains(slot)) slotMap.put(slotPlayerEntry.getKey(),player);
{
return false;
}
slotMap.put(slot,player);
nextPlayerSetup(); nextPlayerSetup();
return true; return true;
} }
//region Drawing Methods //region Drawing Methods
public boolean DrawUpperTribeCard(Player player,TribeCard tribeCard) { public boolean DrawUpperTribeCardByIndex(Player player,int cardIndex) {
if( cardIndex<0 || cardIndex >=board.upperListTribe.size())
return false;
if(currentState.getGameStage()!= GameStages.RESOLVING_ACTIONS) if(currentState.getGameStage()!= GameStages.RESOLVING_ACTIONS)
{ {
return false; return false;
@@ -133,11 +126,10 @@ public class Game {
{ {
return false; return false;
} }
if(!board.containsUpperTribeCard(tribeCard))
return false;
if(currentState.getNUpper() <1) if(currentState.getNUpper() <1)
return false; return false;
if(!tribeCard.IsEventCard()) TribeCard tribeCard = board.upperListTribe.get(cardIndex);
if(tribeCard.IsEventCard())
return false; return false;
Character tempCard = (Character) tribeCard; Character tempCard = (Character) tribeCard;
@@ -149,7 +141,9 @@ public class Game {
return true; return true;
} }
public boolean DrawLowerTribeCard(Player player,TribeCard tribeCard) { public boolean DrawLowerTribeCardByIndex(Player player, int cardIndex) {
if( cardIndex<0 || cardIndex >=board.lowerListTribe.size())
return false;
if(currentState.getGameStage()!= GameStages.RESOLVING_ACTIONS) if(currentState.getGameStage()!= GameStages.RESOLVING_ACTIONS)
{ {
return false; return false;
@@ -158,10 +152,11 @@ public class Game {
{ {
return false; return false;
} }
if(!board.containsLowerTribeCard(tribeCard))
return false;
if(currentState.getNLower() <1) if(currentState.getNLower() <1)
return false; return false;
TribeCard tribeCard = board.lowerListTribe.get(cardIndex);
if(!tribeCard.IsEventCard()) if(!tribeCard.IsEventCard())
return false; return false;
@@ -175,7 +170,9 @@ public class Game {
} }
public boolean DrawUpperBuildingCard(Player player,BuildingCard buildingCard) { public boolean DrawUpperBuildingCardByIndex(Player player,int cardIndex) {
if( cardIndex<0 || cardIndex >=board.upperListBuilding.size())
return false;
if(currentState.getGameStage()!= GameStages.RESOLVING_ACTIONS) if(currentState.getGameStage()!= GameStages.RESOLVING_ACTIONS)
{ {
return false; return false;
@@ -184,10 +181,7 @@ public class Game {
{ {
return false; return false;
} }
if(!board.containsUpperBuildingCard(buildingCard)) BuildingCard buildingCard = board.upperListBuilding.get(cardIndex);
{
return false;
}
if(currentState.getNUpper() <1) if(currentState.getNUpper() <1)
return false; return false;
if(buildingCard.buy(player)) if(buildingCard.buy(player))
@@ -202,19 +196,19 @@ public class Game {
return true; return true;
} }
public boolean DrawLowerBuildingCard(Player player,BuildingCard buildingCard) { public boolean DrawLowerBuildingCardByIndex(Player player,int cardIndex) {
if( cardIndex<0 || cardIndex >=board.lowerListBuilding.size())
return false;
if(currentState.getGameStage()!= GameStages.RESOLVING_ACTIONS) if(currentState.getGameStage()!= GameStages.RESOLVING_ACTIONS)
{ {
return false; return false;
} }
if(!player.equals(currentState.getCurrentPlayer())) if(!player.equals(currentState.getCurrentPlayer()))
{ {
return false; return false;
} }
if(!board.containsLowerBuildingCard(buildingCard)) BuildingCard buildingCard = board.lowerListBuilding.get(cardIndex);
{
return false;
}
if(currentState.getNLower() <1) if(currentState.getNLower() <1)
return false; return false;
if(buildingCard.buy(player)) if(buildingCard.buy(player))
@@ -234,7 +228,6 @@ public class Game {
//endregion //endregion
//region Optional Card Methods //region Optional Card Methods
// TODO fare mappa per contare più volte lo stesso player
public boolean PickOptionalTribeCard(Player player,TribeCard tribeCard) { public boolean PickOptionalTribeCard(Player player,TribeCard tribeCard) {
if(currentState.getGameStage() != GameStages.OPTIONAL_CARD_EFFECT){ if(currentState.getGameStage() != GameStages.OPTIONAL_CARD_EFFECT){
return false; return false;
@@ -242,7 +235,7 @@ public class Game {
if(!player.equals(currentState.getCurrentPlayer())){ if(!player.equals(currentState.getCurrentPlayer())){
return false; return false;
} }
if(!board.containsUpperTribeCard(tribeCard)){ if(!board.upperListTribe.contains(tribeCard)){
return false; return false;
} }
if(tribeCard.IsEventCard()){ if(tribeCard.IsEventCard()){
@@ -262,7 +255,7 @@ public class Game {
if(!player.equals(currentState.getCurrentPlayer())){ if(!player.equals(currentState.getCurrentPlayer())){
return false; return false;
} }
if(!board.containsUpperBuildingCard(buildingCard)){ if(!board.upperListBuilding.contains(buildingCard)){
return false; return false;
} }
if(buildingCard.buy(player)) { if(buildingCard.buy(player)) {
@@ -283,6 +276,8 @@ public class Game {
if(!player.equals(currentState.getCurrentPlayer())){ if(!player.equals(currentState.getCurrentPlayer())){
return false; return false;
} }
OptionalCardQueue.removeIf(x->x.equals(player));
nextPlayerSetup();
return true; return true;
} }
//endregion //endregion
@@ -291,11 +286,21 @@ public class Game {
private void nextPlayerSetup() { private void nextPlayerSetup() {
if(GameStages.SLOT_CHOICE==currentState.getGameStage()) { if(GameStages.SLOT_CHOICE==currentState.getGameStage()) {
currentState.PlayerUpdate(orderLogicCard.pull(), null); Player tempPlayer = orderLogicCard.pull();
if(currentState.getCurrentPlayer()==null)
{ if(tempPlayer!=null) {
currentState.GameStageUpdate(GameStages.RESOLVING_ACTIONS); currentState.PlayerUpdate(tempPlayer, null);
return;
} }
currentState.GameStageUpdate(GameStages.RESOLVING_ACTIONS);
for (Map.Entry<Slot,Player> s : slotMap.entrySet()) {
if (s.getValue()!=null) {
currentState.PlayerUpdate(s.getValue(), s.getKey());
return;
}
}
return;
} }
if(GameStages.RESOLVING_ACTIONS==currentState.getGameStage()) { if(GameStages.RESOLVING_ACTIONS==currentState.getGameStage()) {
orderLogicCard.push(currentState.getCurrentPlayer()); orderLogicCard.push(currentState.getCurrentPlayer());
@@ -308,7 +313,19 @@ public class Game {
if(slotMap.values().stream().allMatch(v -> v == null)) if(slotMap.values().stream().allMatch(v -> v == null))
{ {
currentState.GameStageUpdate(GameStages.OPTIONAL_CARD_EFFECT); currentState.GameStageUpdate(GameStages.OPTIONAL_CARD_EFFECT);
OptionalCardQueue=(playersList.stream().filter(x->x.buildingCards.stream().anyMatch(y->y.getEffectId()==12)).collect(Collectors.toCollection(LinkedList::new))); HashMap<Player,Integer> optional=new LinkedHashMap<>();
for (Player p : playersList) {
int tempCount=(int)p.buildingCards.stream().filter(x->x.getEffectId()==12).count();
if(tempCount>0)
{
optional.put(p,tempCount);
}
}
OptionalCardQueue=new LinkedList<>();
for(Map.Entry<Player,Integer> e : optional.entrySet())
{
OptionalCardQueue.add(e.getKey());
}
currentState.PlayerUpdate(OptionalCardQueue.remove(), null); currentState.PlayerUpdate(OptionalCardQueue.remove(), null);
if(currentState.getCurrentPlayer()==null) if(currentState.getCurrentPlayer()==null)
{ {
@@ -373,7 +390,6 @@ public class Game {
} }
// TODO pulire game ?
private void endGame() { private void endGame() {
playersList.forEach( playersList.forEach(
p -> p.buildingCards.stream().filter(x -> x.getEffectType() == EffectType.FINAL). p -> p.buildingCards.stream().filter(x -> x.getEffectType() == EffectType.FINAL).