diff options
Diffstat (limited to 'backend/src/test')
-rw-r--r-- | backend/src/test/java/org/luxons/sevenwonders/game/GameTest.java | 57 |
1 files changed, 57 insertions, 0 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 new file mode 100644 index 00000000..a7d10394 --- /dev/null +++ b/backend/src/test/java/org/luxons/sevenwonders/game/GameTest.java @@ -0,0 +1,57 @@ +package org.luxons.sevenwonders.game; + +import java.util.Collection; + +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.data.GameDefinitionLoader; +import org.luxons.sevenwonders.game.moves.MoveType; +import org.luxons.sevenwonders.game.test.TestUtils; + +import static org.junit.Assert.assertEquals; + +public class GameTest { + + @Test + public void test() { + int nbPlayers = 5; + Game game = createGame(nbPlayers); + 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()); + PlayerMove move = getFirstAvailableMove(turnInfo); + game.prepareCard(turnInfo.getPlayerIndex(), move); + } + } + + private PlayerMove getFirstAvailableMove(PlayerTurnInfo turnInfo) { + for (HandCard handCard : turnInfo.getHand()) { + if (handCard.isPlayable()) { + return createMove(handCard, MoveType.PLAY); + } + } + return createMove(turnInfo.getHand().get(0), MoveType.DISCARD); + } + + private PlayerMove createMove(HandCard handCard, MoveType play) { + PlayerMove move = new PlayerMove(); + move.setCardName(handCard.getCard().getName()); + move.setType(play); + return move; + } + + private static Game createGame(int nbPlayers) { + CustomizableSettings settings = TestUtils.createCustomizableSettings(); + return new GameDefinitionLoader().getGameDefinition().initGame(0, settings, nbPlayers); + } +} |