summaryrefslogtreecommitdiff
path: root/sw-engine/src/test/kotlin/org/luxons
diff options
context:
space:
mode:
authorJoffrey Bion <joffrey.bion@booking.com>2020-05-28 09:57:13 +0200
committerJoffrey Bion <joffrey.bion@booking.com>2020-05-28 13:34:56 +0200
commit0f2ef6c219266b5ca877eef80020a0f2d14e4af7 (patch)
tree98181d1972d18ecc3ab134b82aedae5153802017 /sw-engine/src/test/kotlin/org/luxons
parentRename discardHand to clearHand for clarity (diff)
downloadseven-wonders-0f2ef6c219266b5ca877eef80020a0f2d14e4af7.tar.gz
seven-wonders-0f2ef6c219266b5ca877eef80020a0f2d14e4af7.tar.bz2
seven-wonders-0f2ef6c219266b5ca877eef80020a0f2d14e4af7.zip
Add server-side support for PLAY_FREE_DISCARDED special ability
So far, there was no "turn" generated for the player who could play a free card from the discarded pile.
Diffstat (limited to 'sw-engine/src/test/kotlin/org/luxons')
-rw-r--r--sw-engine/src/test/kotlin/org/luxons/sevenwonders/engine/GameTest.kt34
-rw-r--r--sw-engine/src/test/kotlin/org/luxons/sevenwonders/engine/test/TestUtils.kt2
2 files changed, 20 insertions, 16 deletions
diff --git a/sw-engine/src/test/kotlin/org/luxons/sevenwonders/engine/GameTest.kt b/sw-engine/src/test/kotlin/org/luxons/sevenwonders/engine/GameTest.kt
index 320b3e94..e1a1b4a7 100644
--- a/sw-engine/src/test/kotlin/org/luxons/sevenwonders/engine/GameTest.kt
+++ b/sw-engine/src/test/kotlin/org/luxons/sevenwonders/engine/GameTest.kt
@@ -50,17 +50,18 @@ class GameTest {
GameDefinition.load().initGame(0, testCustomizableSettings(), nbPlayers)
private fun playAge(nbPlayers: Int, game: Game, age: Int) {
- repeat(6) {
- playTurn(nbPlayers, game, age, 7 - it)
- }
+ do {
+ playTurn(nbPlayers, game, age)
+ } while (!game.getCurrentTurnInfo().first().isStartOfAge(age + 1))
}
- private fun playTurn(nbPlayers: Int, game: Game, ageToCheck: Int, handSize: Int) {
+ private fun PlayerTurnInfo.isStartOfAge(age: Int) = action == Action.WATCH_SCORE || currentAge == age
+
+ private fun playTurn(nbPlayers: Int, game: Game, ageToCheck: Int) {
val turnInfos = game.getCurrentTurnInfo()
assertEquals(nbPlayers, turnInfos.size)
turnInfos.forEach {
assertEquals(ageToCheck, it.currentAge)
- assertEquals(handSize, it.hand?.size)
}
val moveExpectations = turnInfos.mapNotNull { it.firstAvailableMove() }
@@ -76,6 +77,7 @@ class GameTest {
private fun PlayerTurnInfo.firstAvailableMove(): MoveExpectation? = when (action) {
Action.PLAY, Action.PLAY_2, Action.PLAY_LAST -> createPlayCardMove(this)
+ Action.PLAY_FREE_DISCARDED -> createPlayFreeDiscardedMove(this)
Action.PICK_NEIGHBOR_GUILD -> createPickGuildMove(this)
Action.WAIT, Action.SAY_READY -> null
Action.WATCH_SCORE -> fail("should not have WATCH_SCORE action before end of game")
@@ -95,6 +97,15 @@ class GameTest {
}
}
+ private fun createPlayFreeDiscardedMove(turn: PlayerTurnInfo): MoveExpectation {
+ val card = turn.discardedCards?.random() ?: error("No discarded card to play")
+ return MoveExpectation(
+ turn.playerIndex,
+ PlayerMove(MoveType.PLAY_FREE_DISCARDED, card.name, noTransactions()),
+ PlayedMove(turn.playerIndex, MoveType.PLAY_FREE_DISCARDED, card.toPlayedCard(), noTransactions())
+ )
+ }
+
private fun planMove(
turnInfo: PlayerTurnInfo,
moveType: MoveType,
@@ -111,18 +122,11 @@ class GameTest {
// the game should send action WAIT if no guild cards are available around
assertFalse(neighbourGuilds.isEmpty())
+ val card = neighbourGuilds.first()
return MoveExpectation(
turnInfo.playerIndex,
- PlayerMove(
- MoveType.COPY_GUILD,
- neighbourGuilds.first().name
- ),
- PlayedMove(
- turnInfo.playerIndex,
- MoveType.COPY_GUILD,
- neighbourGuilds.first(),
- noTransactions()
- )
+ PlayerMove(MoveType.COPY_GUILD, card.name),
+ PlayedMove(turnInfo.playerIndex, MoveType.COPY_GUILD, card.toPlayedCard(), noTransactions())
)
}
diff --git a/sw-engine/src/test/kotlin/org/luxons/sevenwonders/engine/test/TestUtils.kt b/sw-engine/src/test/kotlin/org/luxons/sevenwonders/engine/test/TestUtils.kt
index 7c1935ae..cc97dc54 100644
--- a/sw-engine/src/test/kotlin/org/luxons/sevenwonders/engine/test/TestUtils.kt
+++ b/sw-engine/src/test/kotlin/org/luxons/sevenwonders/engine/test/TestUtils.kt
@@ -129,7 +129,7 @@ internal fun playCardWithEffect(player: Player, color: Color, effect: Effect) {
}
internal fun createMove(context: PlayerContext, card: Card, type: MoveType): Move =
- type.resolve(PlayerMove(type, card.name), card, context)
+ type.resolve(PlayerMove(type, card.name), card, context, emptyList())
internal fun singleBoardPlayer(board: Board): Player = object : Player {
override val index = 0
bgstack15