diff options
author | Joffrey BION <joffrey.bion@gmail.com> | 2017-05-10 07:40:14 +0200 |
---|---|---|
committer | Joffrey BION <joffrey.bion@gmail.com> | 2017-05-10 07:40:14 +0200 |
commit | 240c8550b9b96fb4607e16a53f8245207eab3744 (patch) | |
tree | d52c6f1ca555a4afd8d6e99eafa9fec8ba4225c6 /backend/src/main | |
parent | Make BestPriceCalculator use the public production of the neighbours (diff) | |
download | seven-wonders-240c8550b9b96fb4607e16a53f8245207eab3744.tar.gz seven-wonders-240c8550b9b96fb4607e16a53f8245207eab3744.tar.bz2 seven-wonders-240c8550b9b96fb4607e16a53f8245207eab3744.zip |
Add neighbour guild cards info to help for COPY_GUILD action
Diffstat (limited to 'backend/src/main')
3 files changed, 37 insertions, 0 deletions
diff --git a/backend/src/main/java/org/luxons/sevenwonders/game/Game.java b/backend/src/main/java/org/luxons/sevenwonders/game/Game.java index 62cbab88..c34880d2 100644 --- a/backend/src/main/java/org/luxons/sevenwonders/game/Game.java +++ b/backend/src/main/java/org/luxons/sevenwonders/game/Game.java @@ -78,6 +78,9 @@ public class Game { Action action = determineAction(hand, table.getBoard(playerIndex)); pti.setAction(action); pti.setMessage(action.getMessage()); + if (action == Action.PICK_NEIGHBOR_GUILD) { + pti.setNeighbourGuildCards(table.getNeighbourGuildCards(playerIndex)); + } return pti; } diff --git a/backend/src/main/java/org/luxons/sevenwonders/game/api/PlayerTurnInfo.java b/backend/src/main/java/org/luxons/sevenwonders/game/api/PlayerTurnInfo.java index ccb045c2..3d92d40b 100644 --- a/backend/src/main/java/org/luxons/sevenwonders/game/api/PlayerTurnInfo.java +++ b/backend/src/main/java/org/luxons/sevenwonders/game/api/PlayerTurnInfo.java @@ -2,6 +2,8 @@ package org.luxons.sevenwonders.game.api; import java.util.List; +import org.luxons.sevenwonders.game.cards.Card; + public class PlayerTurnInfo { private final int playerIndex; @@ -14,6 +16,8 @@ public class PlayerTurnInfo { private List<HandCard> hand; + private List<Card> neighbourGuildCards; + private String message; public PlayerTurnInfo(int playerIndex, Table table) { @@ -42,6 +46,14 @@ public class PlayerTurnInfo { this.hand = hand; } + public List<Card> getNeighbourGuildCards() { + return neighbourGuildCards; + } + + public void setNeighbourGuildCards(List<Card> neighbourGuildCards) { + this.neighbourGuildCards = neighbourGuildCards; + } + public Action getAction() { return action; } diff --git a/backend/src/main/java/org/luxons/sevenwonders/game/api/Table.java b/backend/src/main/java/org/luxons/sevenwonders/game/api/Table.java index 8b831527..82f9055a 100644 --- a/backend/src/main/java/org/luxons/sevenwonders/game/api/Table.java +++ b/backend/src/main/java/org/luxons/sevenwonders/game/api/Table.java @@ -1,11 +1,16 @@ package org.luxons.sevenwonders.game.api; +import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; import org.luxons.sevenwonders.game.boards.Board; import org.luxons.sevenwonders.game.boards.RelativeBoardPosition; +import org.luxons.sevenwonders.game.cards.Card; +import org.luxons.sevenwonders.game.cards.Color; import org.luxons.sevenwonders.game.cards.HandRotationDirection; import org.luxons.sevenwonders.game.moves.Move; +import org.luxons.sevenwonders.game.resources.Provider; /** * The table contains what is visible by all the players in the game: the boards and their played cards, and the @@ -81,4 +86,21 @@ public class Table { board2.getMilitary().defeat(); } } + + public List<Card> getNeighbourGuildCards(int playerIndex) { + return getNeighbourBoards(playerIndex).stream() + .map(Board::getPlayedCards) + .flatMap(List::stream) + .filter(c -> c.getColor() == Color.PURPLE) + .collect(Collectors.toList()); + } + + private List<Board> getNeighbourBoards(int playerIndex) { + Provider[] providers = Provider.values(); + List<Board> boards = new ArrayList<>(providers.length); + for (Provider provider : providers) { + boards.add(getBoard(playerIndex, provider.getBoardPosition())); + } + return boards; + } } |