From 6be4b282381546060b2496b9ea9c9c7318d63247 Mon Sep 17 00:00:00 2001 From: Joffrey Bion Date: Fri, 15 May 2020 01:20:40 +0200 Subject: Send score at end of game --- .../kotlin/org/luxons/sevenwonders/engine/Game.kt | 24 +++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'sw-engine/src/main') 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 = currentTurnInfo private fun determineAction(hand: List, 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) : -- cgit