summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoffrey BION <joffrey.bion@gmail.com>2017-05-10 08:30:28 +0200
committerJoffrey BION <joffrey.bion@gmail.com>2017-05-10 08:30:28 +0200
commit36cbe0dad9af0fbee8bef2ccd6315bda19b52795 (patch)
tree8f87f3744b703173fe90cd8d921a8a5c8b857179
parentChange move validation system and fix chained cards validation (diff)
downloadseven-wonders-36cbe0dad9af0fbee8bef2ccd6315bda19b52795.tar.gz
seven-wonders-36cbe0dad9af0fbee8bef2ccd6315bda19b52795.tar.bz2
seven-wonders-36cbe0dad9af0fbee8bef2ccd6315bda19b52795.zip
Add test to play a whole game trivially
-rw-r--r--backend/src/test/java/org/luxons/sevenwonders/game/GameTest.java72
1 files changed, 56 insertions, 16 deletions
diff --git a/backend/src/test/java/org/luxons/sevenwonders/game/GameTest.java b/backend/src/test/java/org/luxons/sevenwonders/game/GameTest.java
index 98247bb2..377f1a88 100644
--- a/backend/src/test/java/org/luxons/sevenwonders/game/GameTest.java
+++ b/backend/src/test/java/org/luxons/sevenwonders/game/GameTest.java
@@ -1,18 +1,21 @@
package org.luxons.sevenwonders.game;
import java.util.Collection;
+import java.util.List;
import org.junit.Test;
-import org.luxons.sevenwonders.game.api.Action;
import org.luxons.sevenwonders.game.api.CustomizableSettings;
import org.luxons.sevenwonders.game.api.HandCard;
import org.luxons.sevenwonders.game.api.PlayerMove;
import org.luxons.sevenwonders.game.api.PlayerTurnInfo;
+import org.luxons.sevenwonders.game.cards.Card;
import org.luxons.sevenwonders.game.data.GameDefinitionLoader;
import org.luxons.sevenwonders.game.moves.MoveType;
import org.luxons.sevenwonders.game.test.TestUtils;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
public class GameTest {
@@ -20,38 +23,75 @@ public class GameTest {
public void test() {
int nbPlayers = 5;
Game game = createGame(nbPlayers);
- Collection<PlayerTurnInfo> turnInfos = game.getCurrentTurnInfo();
- assertEquals(nbPlayers, turnInfos.size());
+ for (int age = 1; age <= 3; age++) {
+ playAge(nbPlayers, game, age);
+ }
+ }
+
+ private void playAge(int nbPlayers, Game game, int age) {
+ for (int i = 0; i < 6; i++) {
+ playTurn(nbPlayers, game, age, 7 - i);
+ }
+ }
+ private static Game createGame(int nbPlayers) {
+ CustomizableSettings settings = TestUtils.createCustomizableSettings();
+ return new GameDefinitionLoader().getGameDefinition().initGame(0, settings, nbPlayers);
+ }
+
+ private static void playTurn(int nbPlayers, Game game, int ageToCheck, int handSize) {
+ Collection<PlayerTurnInfo> turnInfos = game.getCurrentTurnInfo();
+ assertEquals(nbPlayers, turnInfos.size());
for (PlayerTurnInfo turnInfo : turnInfos) {
- Action action = turnInfo.getAction();
- assertEquals(Action.PLAY, action);
- assertEquals(1, turnInfo.getCurrentAge());
- assertEquals(7, turnInfo.getHand().size());
+ assertEquals(ageToCheck, turnInfo.getCurrentAge());
+ assertEquals(handSize, turnInfo.getHand().size());
PlayerMove move = getFirstAvailableMove(turnInfo);
- game.prepareMove(turnInfo.getPlayerIndex(), move);
+ if (move != null) {
+ game.prepareMove(turnInfo.getPlayerIndex(), move);
+ }
+ }
+ assertTrue(game.areAllPlayersReady());
+ game.playTurn();
+ }
+
+ private static PlayerMove getFirstAvailableMove(PlayerTurnInfo turnInfo) {
+ switch (turnInfo.getAction()) {
+ case PLAY:
+ case PLAY_2:
+ case PLAY_LAST:
+ return createPlayCardMove(turnInfo);
+ case PICK_NEIGHBOR_GUILD:
+ return createPickGuildMove(turnInfo);
+ case WAIT:
+ default:
+ return null;
}
}
- private PlayerMove getFirstAvailableMove(PlayerTurnInfo turnInfo) {
+ private static PlayerMove createPlayCardMove(PlayerTurnInfo turnInfo) {
for (HandCard handCard : turnInfo.getHand()) {
- if (handCard.isPlayable()) {
+ if (handCard.isFree()) {
return createMove(handCard, MoveType.PLAY);
}
}
return createMove(turnInfo.getHand().get(0), MoveType.DISCARD);
}
- private PlayerMove createMove(HandCard handCard, MoveType play) {
+ private static PlayerMove createPickGuildMove(PlayerTurnInfo turnInfo) {
+ List<Card> neighbourGuilds = turnInfo.getNeighbourGuildCards();
+ assertNotNull(neighbourGuilds);
+ String cardName = neighbourGuilds.isEmpty() ? null : neighbourGuilds.get(0).getName();
PlayerMove move = new PlayerMove();
- move.setCardName(handCard.getCard().getName());
- move.setType(play);
+ move.setCardName(cardName);
+ move.setType(MoveType.COPY_GUILD);
return move;
}
- private static Game createGame(int nbPlayers) {
- CustomizableSettings settings = TestUtils.createCustomizableSettings();
- return new GameDefinitionLoader().getGameDefinition().initGame(0, settings, nbPlayers);
+ private static PlayerMove createMove(HandCard handCard, MoveType type) {
+ PlayerMove move = new PlayerMove();
+ move.setCardName(handCard.getCard().getName());
+ move.setType(type);
+ return move;
}
}
bgstack15