diff options
author | Joffrey Bion <joffrey.bion@booking.com> | 2020-05-15 01:20:40 +0200 |
---|---|---|
committer | Joffrey Bion <joffrey.bion@booking.com> | 2020-05-15 01:20:40 +0200 |
commit | 6be4b282381546060b2496b9ea9c9c7318d63247 (patch) | |
tree | f7ff056f7727cf49aca5b007b53010c29ea70d9b /sw-engine/src/main | |
parent | Clean up (diff) | |
download | seven-wonders-6be4b282381546060b2496b9ea9c9c7318d63247.tar.gz seven-wonders-6be4b282381546060b2496b9ea9c9c7318d63247.tar.bz2 seven-wonders-6be4b282381546060b2496b9ea9c9c7318d63247.zip |
Send score at end of game
Diffstat (limited to 'sw-engine/src/main')
-rw-r--r-- | sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/Game.kt | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/Game.kt b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/Game.kt index c6c6c546..b79fd381 100644 --- a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/Game.kt +++ b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/Game.kt @@ -47,6 +47,19 @@ class Game internal constructor( currentTurnInfo = players.map { createPlayerTurnInfo(it) } } + private fun startEndGame() { + // some player may need to do additional stuff + startNewTurn() + val allDone = currentTurnInfo.all { it.action == Action.WAIT } + if (!allDone) { + return // we play the last turn like a normal one + } + val scoreBoard = computeScore() + currentTurnInfo = currentTurnInfo.map { + it.copy(action = Action.WATCH_SCORE, scoreBoard = scoreBoard) + } + } + private fun createPlayerTurnInfo(player: Player): PlayerTurnInfo { val hand = hands.createHand(player) val action = determineAction(hand, player.board) @@ -68,7 +81,10 @@ class Game internal constructor( fun getCurrentTurnInfo(): Collection<PlayerTurnInfo> = currentTurnInfo private fun determineAction(hand: List<HandCard>, board: Board): Action = when { - endOfGameReached() && board.hasSpecial(SpecialAbility.COPY_GUILD) -> determineCopyGuildAction(board) + endOfGameReached() -> when { + board.hasSpecial(SpecialAbility.COPY_GUILD) -> determineCopyGuildAction(board) + else -> Action.WAIT + } hand.size == 1 && board.hasSpecial(SpecialAbility.PLAY_LAST_CARD) -> Action.PLAY_LAST hand.size == 2 && board.hasSpecial(SpecialAbility.PLAY_LAST_CARD) -> Action.PLAY_2 hand.isEmpty() -> Action.WAIT @@ -115,7 +131,9 @@ class Game internal constructor( makeMoves() if (endOfAgeReached()) { executeEndOfAgeEvents() - if (!endOfGameReached()) { + if (endOfGameReached()) { + startEndGame() + } else { startNewAge() } } else { @@ -184,7 +202,7 @@ class Game internal constructor( /** * Computes the score for all players. */ - fun computeScore(): ScoreBoard = + private fun computeScore(): ScoreBoard = ScoreBoard(table.boards.map { it.computeScore(players[it.playerIndex]) }.sortedDescending()) private class MissingPreparedMoveException(playerIndex: Int) : |