From 08610a3f41ff08816fda98e3f1f204a8f337fe15 Mon Sep 17 00:00:00 2001 From: Joffrey BION Date: Thu, 26 Apr 2018 01:36:22 +0200 Subject: Improve full game test by using bought resources --- .../java/org/luxons/sevenwonders/game/GameTest.java | 17 +++++++++++++++-- .../org/luxons/sevenwonders/game/test/TestUtils.java | 10 +++++++--- 2 files changed, 22 insertions(+), 5 deletions(-) (limited to 'game-engine/src/test') 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 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 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 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) { PlayerMove playerMove = new PlayerMove(); playerMove.setCardName(cardName); playerMove.setType(type); - playerMove.setBoughtResources(Arrays.asList(boughtResources)); + playerMove.setBoughtResources(boughtResources); return playerMove; } } -- cgit