diff options
author | Joffrey BION <joffrey.bion@gmail.com> | 2018-04-26 01:36:22 +0200 |
---|---|---|
committer | Joffrey BION <joffrey.bion@gmail.com> | 2018-04-26 01:36:22 +0200 |
commit | 08610a3f41ff08816fda98e3f1f204a8f337fe15 (patch) | |
tree | 47febf9941e65988d075562eb2e7fe0a44496f0a /game-engine/src/test | |
parent | Fix WONDER_LEVEL -> BUILT_WONDER_STAGES element type (diff) | |
download | seven-wonders-08610a3f41ff08816fda98e3f1f204a8f337fe15.tar.gz seven-wonders-08610a3f41ff08816fda98e3f1f204a8f337fe15.tar.bz2 seven-wonders-08610a3f41ff08816fda98e3f1f204a8f337fe15.zip |
Improve full game test by using bought resources
Diffstat (limited to 'game-engine/src/test')
-rw-r--r-- | game-engine/src/test/java/org/luxons/sevenwonders/game/GameTest.java | 17 | ||||
-rw-r--r-- | game-engine/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java | 10 |
2 files changed, 22 insertions, 5 deletions
diff --git a/game-engine/src/test/java/org/luxons/sevenwonders/game/GameTest.java b/game-engine/src/test/java/org/luxons/sevenwonders/game/GameTest.java index b9b399bb..73315dd2 100644 --- a/game-engine/src/test/java/org/luxons/sevenwonders/game/GameTest.java +++ b/game-engine/src/test/java/org/luxons/sevenwonders/game/GameTest.java @@ -1,6 +1,7 @@ package org.luxons.sevenwonders.game; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -15,6 +16,9 @@ import org.luxons.sevenwonders.game.cards.Card; import org.luxons.sevenwonders.game.data.GameDefinitionLoader; import org.luxons.sevenwonders.game.moves.Move; import org.luxons.sevenwonders.game.moves.MoveType; +import org.luxons.sevenwonders.game.resources.BestPriceCalculator; +import org.luxons.sevenwonders.game.resources.BoughtResources; +import org.luxons.sevenwonders.game.resources.Resources; import org.luxons.sevenwonders.game.test.TestUtils; import static org.junit.Assert.assertEquals; @@ -90,14 +94,23 @@ public class GameTest { private static PlayerMove createPlayCardMove(PlayerTurnInfo turnInfo) { for (HandCard handCard : turnInfo.getHand()) { - if (handCard.isFree()) { - return TestUtils.createPlayerMove(handCard.getCard().getName(), MoveType.PLAY); + if (handCard.isPlayable()) { + List<BoughtResources> resourcesToBuy = findResourcesToBuyFor(handCard, turnInfo); + return TestUtils.createPlayerMove(handCard.getCard().getName(), MoveType.PLAY, resourcesToBuy); } } HandCard firstCardInHand = turnInfo.getHand().get(0); return TestUtils.createPlayerMove(firstCardInHand.getCard().getName(), MoveType.DISCARD); } + private static List<BoughtResources> findResourcesToBuyFor(HandCard handCard, PlayerTurnInfo turnInfo) { + if (handCard.isFree()) { + return Collections.emptyList(); + } + Resources requiredResources = handCard.getCard().getRequirements().getResources(); + return BestPriceCalculator.bestSolution(requiredResources, turnInfo.getTable(), turnInfo.getPlayerIndex()); + } + private static PlayerMove createPickGuildMove(PlayerTurnInfo turnInfo) { List<Card> neighbourGuilds = turnInfo.getNeighbourGuildCards(); assertNotNull(neighbourGuilds); diff --git a/game-engine/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java b/game-engine/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java index 34b2e74f..5adaa098 100644 --- a/game-engine/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java +++ b/game-engine/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java @@ -220,15 +220,19 @@ public class TestUtils { } public static Move createMove(int playerIndex, Card card, MoveType type, BoughtResources... boughtResources) { - PlayerMove playerMove = createPlayerMove(card.getName(), type, boughtResources); + PlayerMove playerMove = createPlayerMove(card.getName(), type, Arrays.asList(boughtResources)); return type.resolve(playerIndex, card, playerMove); } - public static PlayerMove createPlayerMove(String cardName, MoveType type, BoughtResources... boughtResources) { + public static PlayerMove createPlayerMove(String cardName, MoveType type) { + return createPlayerMove(cardName, type, Collections.emptyList()); + } + + public static PlayerMove createPlayerMove(String cardName, MoveType type, List<BoughtResources> boughtResources) { PlayerMove playerMove = new PlayerMove(); playerMove.setCardName(cardName); playerMove.setType(type); - playerMove.setBoughtResources(Arrays.asList(boughtResources)); + playerMove.setBoughtResources(boughtResources); return playerMove; } } |