From 47b33a1f3726a5b0ce9c60ec843ee66ee3689104 Mon Sep 17 00:00:00 2001 From: Joffrey Bion Date: Tue, 5 May 2020 17:43:41 +0200 Subject: Move score to common model (to enable passing it to client) --- .../kotlin/org/luxons/sevenwonders/engine/Game.kt | 5 +++-- .../org/luxons/sevenwonders/engine/boards/Board.kt | 4 ++-- .../org/luxons/sevenwonders/engine/score/Score.kt | 23 ---------------------- 3 files changed, 5 insertions(+), 27 deletions(-) delete mode 100644 sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/score/Score.kt (limited to 'sw-engine/src/main/kotlin/org') 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 25f1de6d..c6c6c546 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 @@ -12,7 +12,7 @@ import org.luxons.sevenwonders.engine.data.LAST_AGE import org.luxons.sevenwonders.engine.effects.SpecialAbility import org.luxons.sevenwonders.engine.moves.Move import org.luxons.sevenwonders.engine.moves.resolve -import org.luxons.sevenwonders.engine.score.ScoreBoard +import org.luxons.sevenwonders.model.score.ScoreBoard import org.luxons.sevenwonders.model.Action import org.luxons.sevenwonders.model.TableState import org.luxons.sevenwonders.model.PlayerMove @@ -184,7 +184,8 @@ class Game internal constructor( /** * Computes the score for all players. */ - fun computeScore(): ScoreBoard = ScoreBoard(table.boards.map { it.computeScore(players[it.playerIndex]) }) + fun computeScore(): ScoreBoard = + ScoreBoard(table.boards.map { it.computeScore(players[it.playerIndex]) }.sortedDescending()) private class MissingPreparedMoveException(playerIndex: Int) : IllegalStateException("Player $playerIndex has not prepared his move") diff --git a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/boards/Board.kt b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/boards/Board.kt index a98da0bf..dc02b080 100644 --- a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/boards/Board.kt +++ b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/boards/Board.kt @@ -7,11 +7,11 @@ import org.luxons.sevenwonders.engine.effects.SpecialAbility import org.luxons.sevenwonders.engine.resources.Production import org.luxons.sevenwonders.engine.resources.TradingRules import org.luxons.sevenwonders.engine.resources.mutableResourcesOf -import org.luxons.sevenwonders.engine.score.PlayerScore -import org.luxons.sevenwonders.engine.score.ScoreCategory import org.luxons.sevenwonders.engine.wonders.Wonder import org.luxons.sevenwonders.model.Age import org.luxons.sevenwonders.model.cards.Color +import org.luxons.sevenwonders.model.score.PlayerScore +import org.luxons.sevenwonders.model.score.ScoreCategory internal class Board(val wonder: Wonder, val playerIndex: Int, settings: Settings) { diff --git a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/score/Score.kt b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/score/Score.kt deleted file mode 100644 index 4da27a59..00000000 --- a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/score/Score.kt +++ /dev/null @@ -1,23 +0,0 @@ -package org.luxons.sevenwonders.engine.score - -class ScoreBoard(scores: Collection) { - - val scores: Collection = scores.sortedDescending() -} - -data class PlayerScore(val boardGold: Int, val pointsByCategory: Map) : Comparable { - - val totalPoints = pointsByCategory.map { it.value }.sum() - - override fun compareTo(other: PlayerScore) = compareValuesBy(this, other, { it.totalPoints }, { it.boardGold }) -} - -enum class ScoreCategory { - CIVIL, - SCIENCE, - MILITARY, - TRADE, - GUILD, - WONDER, - GOLD -} -- cgit