From 20625511ff872404e70984f5b21e3f514793c511 Mon Sep 17 00:00:00 2001 From: jbion Date: Tue, 26 Feb 2019 22:12:37 +0100 Subject: Add support for multiple columns --- .../kotlin/org/luxons/sevenwonders/game/api/Boards.kt | 15 +++++++++++++-- .../kotlin/org/luxons/sevenwonders/game/cards/Cards.kt | 16 ++++++++-------- 2 files changed, 21 insertions(+), 10 deletions(-) (limited to 'game-engine/src/main') diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/Boards.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/Boards.kt index 2dd481ca..470b4efa 100644 --- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/Boards.kt +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/Boards.kt @@ -23,7 +23,7 @@ data class Board( val publicProduction: ApiProduction, val science: ApiScience, val military: ApiMilitary, - val playedCards: List, + val playedCards: List>, val gold: Int ) @@ -34,10 +34,21 @@ internal fun InternalBoard.toApiBoard(player: Player, lastMove: Move?): Board = publicProduction = publicProduction.toApiProduction(), science = science.toApiScience(), military = military.toApiMilitary(), - playedCards = getPlayedCards().map { it.toTableCard(lastMove) }, + playedCards = getPlayedCards().map { it.toTableCard(lastMove) }.toColumns(), gold = gold ) +internal fun List.toColumns(): List> { + val cardsByColor = this.groupBy { it.color } + val (resourceCardsCols, otherCols) = cardsByColor.values.partition { it[0].color.isResource } + val resourceCardsCol = resourceCardsCols.flatten() + val otherColsSorted = otherCols.sortedBy { it[0].color } + if (resourceCardsCol.isEmpty()) { + return otherColsSorted // we want only non-empty columns + } + return listOf(resourceCardsCol) + otherColsSorted +} + data class Wonder( val name: String, val initialResource: ResourceType, diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/cards/Cards.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/cards/Cards.kt index cf4df44e..18d9cb96 100644 --- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/cards/Cards.kt +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/cards/Cards.kt @@ -41,14 +41,14 @@ internal data class Card( } } -enum class Color { - BROWN, - GREY, - YELLOW, - BLUE, - GREEN, - RED, - PURPLE +enum class Color(val isResource: Boolean) { + BROWN(true), + GREY(true), + YELLOW(false), + BLUE(false), + GREEN(false), + RED(false), + PURPLE(false) } data class CardPlayability( -- cgit