summaryrefslogtreecommitdiff
path: root/src/main/java/org/luxons
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/luxons')
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/Game.java26
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/api/Action.java1
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/boards/Board.java9
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/moves/BuildWonderMove.java7
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/moves/CardFromHandMove.java20
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/moves/CopyGuildMove.java49
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/moves/DiscardMove.java7
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/moves/Move.java2
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/moves/MoveType.java6
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/moves/PlayCardMove.java7
10 files changed, 110 insertions, 24 deletions
diff --git a/src/main/java/org/luxons/sevenwonders/game/Game.java b/src/main/java/org/luxons/sevenwonders/game/Game.java
index 59ab869c..9f1529a2 100644
--- a/src/main/java/org/luxons/sevenwonders/game/Game.java
+++ b/src/main/java/org/luxons/sevenwonders/game/Game.java
@@ -22,6 +22,8 @@ import org.luxons.sevenwonders.game.scoring.ScoreBoard;
public class Game {
+ private static final int LAST_AGE = 3;
+
private final long id;
private final Settings settings;
@@ -84,12 +86,14 @@ public class Game {
}
private Action determineAction(List<HandCard> hand, Board board) {
- if (hand.isEmpty()) {
- return Action.WAIT;
+ if (endOfGameReached() && board.hasSpecial(SpecialAbility.COPY_GUILD)) {
+ return Action.PICK_NEIGHBOR_GUILD;
} else if (hand.size() == 1 && board.hasSpecial(SpecialAbility.PLAY_LAST_CARD)) {
return Action.PLAY_LAST;
} else if (hand.size() == 2 && board.hasSpecial(SpecialAbility.PLAY_LAST_CARD)) {
return Action.PLAY_2;
+ } else if (hand.isEmpty()) {
+ return Action.WAIT;
} else {
return Action.PLAY;
}
@@ -113,15 +117,7 @@ public class Game {
private void validate(Move move) throws InvalidMoveException {
List<Card> hand = hands.get(move.getPlayerIndex());
- if (hand == null) {
- throw new InvalidMoveException("Invalid player index " + move.getPlayerIndex());
- }
- Card card = move.getCard();
- if (!hand.contains(card)) {
- throw new InvalidMoveException(
- "Player " + move.getPlayerIndex() + " does not have the card " + move.getCard().getName());
- }
- if (!move.isValid(table)) {
+ if (!move.isValid(table, hand)) {
throw new InvalidMoveException(
"Player " + move.getPlayerIndex() + " cannot play the card " + move.getCard().getName());
}
@@ -135,7 +131,9 @@ public class Game {
makeMoves();
if (endOfAgeReached()) {
executeEndOfAgeEvents();
- startNewAge();
+ if (!endOfGameReached()) {
+ startNewAge();
+ }
} else if (!hands.maxOneCardRemains()) {
// we don't rotate hands if some player can play his last card (with the special ability)
hands.rotate(getHandRotationOffset());
@@ -215,6 +213,10 @@ public class Game {
return currentAge % 2 == 0 ? -1 : 1;
}
+ private boolean endOfGameReached() {
+ return endOfAgeReached() && currentAge == LAST_AGE;
+ }
+
public ScoreBoard computeScore() {
ScoreBoard scoreBoard = new ScoreBoard();
table.getBoards().stream().map(b -> b.computePoints(table)).forEach(scoreBoard::add);
diff --git a/src/main/java/org/luxons/sevenwonders/game/api/Action.java b/src/main/java/org/luxons/sevenwonders/game/api/Action.java
index 786ab668..9cd98291 100644
--- a/src/main/java/org/luxons/sevenwonders/game/api/Action.java
+++ b/src/main/java/org/luxons/sevenwonders/game/api/Action.java
@@ -5,6 +5,7 @@ public enum Action {
PLAY_2("Pick the card you want to play first. Note that you have the ability to play these 2 last cards. "
+ "You will choose how to play the last one during your next turn."),
PLAY_LAST("You have the special ability to play your last card. Choose how you want to play it."),
+ PICK_NEIGHBOR_GUILD("Choose a Guild card (purple) that you want to copy from one of your neighbours."),
WAIT("Please wait for other players to perform extra actions.");
private final String message;
diff --git a/src/main/java/org/luxons/sevenwonders/game/boards/Board.java b/src/main/java/org/luxons/sevenwonders/game/boards/Board.java
index 3b4cfe40..23f85af7 100644
--- a/src/main/java/org/luxons/sevenwonders/game/boards/Board.java
+++ b/src/main/java/org/luxons/sevenwonders/game/boards/Board.java
@@ -35,7 +35,7 @@ public class Board {
private final Set<SpecialAbility> specialAbilities = EnumSet.noneOf(SpecialAbility.class);
-
+ private Card copiedGuild;
private int gold;
@@ -115,6 +115,13 @@ public class Board {
return specialAbilities.contains(specialAbility);
}
+ public void setCopiedGuild(Card copiedGuild) {
+ if (copiedGuild.getColor() != Color.PURPLE) {
+ throw new IllegalArgumentException("The given card '" + copiedGuild + "' is not a Guild card");
+ }
+ this.copiedGuild = copiedGuild;
+ }
+
public PlayerScore computePoints(Table table) {
PlayerScore score = new PlayerScore(player, gold);
score.put(ScoreCategory.CIVIL, computePointsForCards(table, Color.BLUE));
diff --git a/src/main/java/org/luxons/sevenwonders/game/moves/BuildWonderMove.java b/src/main/java/org/luxons/sevenwonders/game/moves/BuildWonderMove.java
index ebc9ac99..bddd6ec6 100644
--- a/src/main/java/org/luxons/sevenwonders/game/moves/BuildWonderMove.java
+++ b/src/main/java/org/luxons/sevenwonders/game/moves/BuildWonderMove.java
@@ -8,14 +8,17 @@ import org.luxons.sevenwonders.game.api.Table;
import org.luxons.sevenwonders.game.boards.Board;
import org.luxons.sevenwonders.game.cards.Card;
-public class BuildWonderMove extends Move {
+public class BuildWonderMove extends CardFromHandMove {
BuildWonderMove(int playerIndex, Card card, PlayerMove move) {
super(playerIndex, card, move);
}
@Override
- public boolean isValid(Table table) {
+ public boolean isValid(Table table, List<Card> playerHand) {
+ if (!super.isValid(table, playerHand)) {
+ return false;
+ }
Board board = table.getBoard(getPlayerIndex());
return board.getWonder().isNextStageBuildable(table, getPlayerIndex(), getBoughtResources());
}
diff --git a/src/main/java/org/luxons/sevenwonders/game/moves/CardFromHandMove.java b/src/main/java/org/luxons/sevenwonders/game/moves/CardFromHandMove.java
new file mode 100644
index 00000000..7bbee1e5
--- /dev/null
+++ b/src/main/java/org/luxons/sevenwonders/game/moves/CardFromHandMove.java
@@ -0,0 +1,20 @@
+package org.luxons.sevenwonders.game.moves;
+
+import java.util.List;
+
+import org.luxons.sevenwonders.game.api.PlayerMove;
+import org.luxons.sevenwonders.game.api.Table;
+import org.luxons.sevenwonders.game.cards.Card;
+
+public abstract class CardFromHandMove extends Move {
+
+ CardFromHandMove(int playerIndex, Card card, PlayerMove move) {
+ super(playerIndex, card, move);
+ }
+
+ @Override
+ public boolean isValid(Table table, List<Card> playerHand) {
+ return playerHand.contains(getCard());
+ }
+
+}
diff --git a/src/main/java/org/luxons/sevenwonders/game/moves/CopyGuildMove.java b/src/main/java/org/luxons/sevenwonders/game/moves/CopyGuildMove.java
new file mode 100644
index 00000000..5ebde772
--- /dev/null
+++ b/src/main/java/org/luxons/sevenwonders/game/moves/CopyGuildMove.java
@@ -0,0 +1,49 @@
+package org.luxons.sevenwonders.game.moves;
+
+import java.util.List;
+
+import org.luxons.sevenwonders.game.Settings;
+import org.luxons.sevenwonders.game.api.PlayerMove;
+import org.luxons.sevenwonders.game.api.Table;
+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.effects.SpecialAbility;
+
+public class CopyGuildMove extends Move {
+
+ CopyGuildMove(int playerIndex, Card card, PlayerMove move) {
+ super(playerIndex, card, move);
+ }
+
+ @Override
+ public boolean isValid(Table table, List<Card> playerHand) {
+ Board board = table.getBoard(getPlayerIndex());
+ if (!board.hasSpecial(SpecialAbility.COPY_GUILD)) {
+ return false;
+ }
+ if (getCard().getColor() != Color.PURPLE) {
+ return false;
+ }
+ boolean leftNeighbourHasIt = neighbourHasTheCard(table, RelativeBoardPosition.LEFT);
+ boolean rightNeighbourHasIt = neighbourHasTheCard(table, RelativeBoardPosition.RIGHT);
+ return leftNeighbourHasIt || rightNeighbourHasIt;
+ }
+
+ private boolean neighbourHasTheCard(Table table, RelativeBoardPosition position) {
+ Board neighbourBoard = table.getBoard(getPlayerIndex(), position);
+ return neighbourBoard.getPlayedCards().contains(getCard());
+ }
+
+ @Override
+ public void place(Table table, List<Card> discardedCards, Settings settings) {
+ // nothing special to do here
+ }
+
+ @Override
+ public void activate(Table table, List<Card> discardedCards, Settings settings) {
+ Board board = table.getBoard(getPlayerIndex());
+ board.setCopiedGuild(getCard());
+ }
+}
diff --git a/src/main/java/org/luxons/sevenwonders/game/moves/DiscardMove.java b/src/main/java/org/luxons/sevenwonders/game/moves/DiscardMove.java
index 30c2472d..076a593c 100644
--- a/src/main/java/org/luxons/sevenwonders/game/moves/DiscardMove.java
+++ b/src/main/java/org/luxons/sevenwonders/game/moves/DiscardMove.java
@@ -8,18 +8,13 @@ import org.luxons.sevenwonders.game.api.Table;
import org.luxons.sevenwonders.game.boards.Board;
import org.luxons.sevenwonders.game.cards.Card;
-public class DiscardMove extends Move {
+public class DiscardMove extends CardFromHandMove {
DiscardMove(int playerIndex, Card card, PlayerMove move) {
super(playerIndex, card, move);
}
@Override
- public boolean isValid(Table table) {
- return true;
- }
-
- @Override
public void place(Table table, List<Card> discardedCards, Settings settings) {
discardedCards.add(getCard());
}
diff --git a/src/main/java/org/luxons/sevenwonders/game/moves/Move.java b/src/main/java/org/luxons/sevenwonders/game/moves/Move.java
index 584589a8..8b6b60a8 100644
--- a/src/main/java/org/luxons/sevenwonders/game/moves/Move.java
+++ b/src/main/java/org/luxons/sevenwonders/game/moves/Move.java
@@ -42,7 +42,7 @@ public abstract class Move {
return boughtResources;
}
- public abstract boolean isValid(Table table);
+ public abstract boolean isValid(Table table, List<Card> playerHand);
public abstract void place(Table table, List<Card> discardedCards, Settings settings);
diff --git a/src/main/java/org/luxons/sevenwonders/game/moves/MoveType.java b/src/main/java/org/luxons/sevenwonders/game/moves/MoveType.java
index ff521bae..4887c6f1 100644
--- a/src/main/java/org/luxons/sevenwonders/game/moves/MoveType.java
+++ b/src/main/java/org/luxons/sevenwonders/game/moves/MoveType.java
@@ -21,6 +21,12 @@ public enum MoveType {
public Move resolve(int playerIndex, Card card, PlayerMove move) {
return new DiscardMove(playerIndex, card, move);
}
+ },
+ COPY_GUILD {
+ @Override
+ public Move resolve(int playerIndex, Card card, PlayerMove move) {
+ return new CopyGuildMove(playerIndex, card, move);
+ }
};
public abstract Move resolve(int playerIndex, Card card, PlayerMove move);
diff --git a/src/main/java/org/luxons/sevenwonders/game/moves/PlayCardMove.java b/src/main/java/org/luxons/sevenwonders/game/moves/PlayCardMove.java
index ee8e2128..affebc4a 100644
--- a/src/main/java/org/luxons/sevenwonders/game/moves/PlayCardMove.java
+++ b/src/main/java/org/luxons/sevenwonders/game/moves/PlayCardMove.java
@@ -8,14 +8,17 @@ import org.luxons.sevenwonders.game.api.Table;
import org.luxons.sevenwonders.game.boards.Board;
import org.luxons.sevenwonders.game.cards.Card;
-public class PlayCardMove extends Move {
+public class PlayCardMove extends CardFromHandMove {
PlayCardMove(int playerIndex, Card card, PlayerMove move) {
super(playerIndex, card, move);
}
@Override
- public boolean isValid(Table table) {
+ public boolean isValid(Table table, List<Card> playerHand) {
+ if (!super.isValid(table, playerHand)) {
+ return false;
+ }
return getCard().getRequirements().isAffordedBy(table, getPlayerIndex(), getBoughtResources());
}
bgstack15