summaryrefslogtreecommitdiff
path: root/sw-bot/src/main/kotlin/org
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-bot/src/main/kotlin/org
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-bot/src/main/kotlin/org')
-rw-r--r--sw-bot/src/main/kotlin/org/luxons/sevenwonders/bot/SevenWondersBot.kt6
1 files changed, 6 insertions, 0 deletions
diff --git a/sw-bot/src/main/kotlin/org/luxons/sevenwonders/bot/SevenWondersBot.kt b/sw-bot/src/main/kotlin/org/luxons/sevenwonders/bot/SevenWondersBot.kt
index c58eaea8..80bad9e4 100644
--- a/sw-bot/src/main/kotlin/org/luxons/sevenwonders/bot/SevenWondersBot.kt
+++ b/sw-bot/src/main/kotlin/org/luxons/sevenwonders/bot/SevenWondersBot.kt
@@ -59,6 +59,7 @@ class SevenWondersBot(
private suspend fun SevenWondersSession.playTurn(turn: PlayerTurnInfo): Boolean {
when (turn.action) {
Action.PLAY, Action.PLAY_2, Action.PLAY_LAST -> prepareMove(createPlayCardMove(turn))
+ Action.PLAY_FREE_DISCARDED -> prepareMove(createPlayFreeDiscardedMove(turn))
Action.PICK_NEIGHBOR_GUILD -> prepareMove(createPickGuildMove(turn))
Action.SAY_READY -> sayReady()
Action.WAIT -> Unit
@@ -84,5 +85,10 @@ private fun createPlayCardMove(turnInfo: PlayerTurnInfo): PlayerMove {
}
}
+private fun createPlayFreeDiscardedMove(turn: PlayerTurnInfo): PlayerMove {
+ val card = turn.discardedCards?.random() ?: error("No discarded card to play")
+ return PlayerMove(MoveType.PLAY_FREE_DISCARDED, card.name)
+}
+
private fun createPickGuildMove(turnInfo: PlayerTurnInfo): PlayerMove =
PlayerMove(MoveType.COPY_GUILD, turnInfo.neighbourGuildCards.random().name)
bgstack15