diff options
author | Joffrey BION <joffrey.bion@gmail.com> | 2018-07-05 09:35:27 +0200 |
---|---|---|
committer | Joffrey Bion <joffrey.bion@amadeus.com> | 2018-07-06 14:17:16 +0200 |
commit | ccfd6d1d3ba64eef7df1645c24d979c284fd99da (patch) | |
tree | 441bc4e931fc998d86f642390096af4d30e9b85f /game-engine/src/main/kotlin/org | |
parent | Prevent PICK_NEIGHBOUR_GUILD action if no guild to pick (diff) | |
download | seven-wonders-ccfd6d1d3ba64eef7df1645c24d979c284fd99da.tar.gz seven-wonders-ccfd6d1d3ba64eef7df1645c24d979c284fd99da.tar.bz2 seven-wonders-ccfd6d1d3ba64eef7df1645c24d979c284fd99da.zip |
Kotlin mig: api package
Diffstat (limited to 'game-engine/src/main/kotlin/org')
6 files changed, 138 insertions, 0 deletions
diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/Action.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/Action.kt new file mode 100644 index 00000000..37ab3e6f --- /dev/null +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/Action.kt @@ -0,0 +1,10 @@ +package org.luxons.sevenwonders.game.api + +enum class Action constructor(val message: String) { + PLAY("Pick the card you want to play or discard."), + PLAY_2("Pick the first card you want to play or discard. Note that you have the ability to play these 2 last " + + "cards. You will choose how to play the last one during your next turn."), + PLAY_LAST("You have the special ability to play your last card. Choose how you want to play it."), + PICK_NEIGHBOR_GUILD("Choose a Guild card (purple) that you want to copy from one of your neighbours."), + WAIT("Please wait for other players to perform extra actions.") +} diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/CustomizableSettings.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/CustomizableSettings.kt new file mode 100644 index 00000000..354aecb6 --- /dev/null +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/CustomizableSettings.kt @@ -0,0 +1,15 @@ +package org.luxons.sevenwonders.game.api + +import org.luxons.sevenwonders.game.data.definitions.WonderSidePickMethod + +data class CustomizableSettings( + val randomSeedForTests: Long? = null, + val timeLimitInSeconds: Int = 45, + val wonderSidePickMethod: WonderSidePickMethod = WonderSidePickMethod.EACH_RANDOM, + val initialGold: Int = 3, + val discardedCardGold: Int = 3, + val defaultTradingCost: Int = 2, + val pointsPer3Gold: Int = 1, + val lostPointsPerDefeat: Int = 1, + val wonPointsPerVictoryPerAge: Map<Int, Int> = mapOf(1 to 1, 2 to 3, 3 to 5) +) diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/HandCard.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/HandCard.kt new file mode 100644 index 00000000..4c3a7a8d --- /dev/null +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/HandCard.kt @@ -0,0 +1,23 @@ +package org.luxons.sevenwonders.game.api + +import org.luxons.sevenwonders.game.cards.Card + +/** + * A card with contextual information relative to the hand it is sitting in. The extra information is especially useful + * because it frees the client from a painful business logic implementation. + */ +class HandCard(val card: Card, table: Table, playerIndex: Int) { + + val isChainable: Boolean + + val isFree: Boolean + + val isPlayable: Boolean + + init { + val board = table.getBoard(playerIndex) + this.isChainable = card.isChainableOn(board) + this.isFree = card.isFreeFor(board) + this.isPlayable = card.isPlayable(table, playerIndex) + } +} diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/PlayerMove.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/PlayerMove.kt new file mode 100644 index 00000000..d0a1e1b3 --- /dev/null +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/PlayerMove.kt @@ -0,0 +1,10 @@ +package org.luxons.sevenwonders.game.api + +import org.luxons.sevenwonders.game.moves.MoveType +import org.luxons.sevenwonders.game.resources.ResourceTransaction + +data class PlayerMove( + val type: MoveType, + val cardName: String?, + val transactions: Collection<ResourceTransaction> = emptyList() +) diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/PlayerTurnInfo.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/PlayerTurnInfo.kt new file mode 100644 index 00000000..3439a9af --- /dev/null +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/PlayerTurnInfo.kt @@ -0,0 +1,14 @@ +package org.luxons.sevenwonders.game.api + +import org.luxons.sevenwonders.game.cards.Card + +data class PlayerTurnInfo( + val playerIndex: Int, + val table: Table, + val action: Action, + val hand: List<HandCard>, + val neighbourGuildCards: List<Card> +) { + val currentAge: Int = table.currentAge + val message: String = action.message +} diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/Table.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/Table.kt new file mode 100644 index 00000000..9ecfa6b0 --- /dev/null +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/Table.kt @@ -0,0 +1,66 @@ +package org.luxons.sevenwonders.game.api + +import org.luxons.sevenwonders.game.boards.Board +import org.luxons.sevenwonders.game.boards.RelativeBoardPosition +import org.luxons.sevenwonders.game.cards.Card +import org.luxons.sevenwonders.game.cards.Color +import org.luxons.sevenwonders.game.cards.HandRotationDirection +import org.luxons.sevenwonders.game.moves.Move +import org.luxons.sevenwonders.game.resources.Provider + +/** + * The table contains what is visible by all the players in the game: the boards and their played cards, and the + * players' information. + */ +class Table(val boards: List<Board>) { + + val nbPlayers: Int = boards.size + + var currentAge = 0 + private set + + val handRotationDirection: HandRotationDirection + get() = HandRotationDirection.forAge(currentAge) + + var lastPlayedMoves: List<Move> = emptyList() + + fun getBoard(playerIndex: Int): Board { + return boards[playerIndex] + } + + fun getBoard(playerIndex: Int, position: RelativeBoardPosition): Board { + return boards[position.getIndexFrom(playerIndex, nbPlayers)] + } + + fun increaseCurrentAge() { + this.currentAge++ + } + + fun resolveMilitaryConflicts() { + for (i in 0 until nbPlayers) { + val board1 = getBoard(i) + val board2 = getBoard((i + 1) % nbPlayers) + resolveConflict(board1, board2, currentAge) + } + } + + private fun resolveConflict(board1: Board, board2: Board, age: Int) { + val shields1 = board1.military.nbShields + val shields2 = board2.military.nbShields + if (shields1 < shields2) { + board1.military.defeat() + board2.military.victory(age) + } else if (shields1 > shields2) { + board1.military.victory(age) + board2.military.defeat() + } + } + + fun getNeighbourGuildCards(playerIndex: Int): List<Card> { + return getNeighbourBoards(playerIndex).flatMap(Board::getPlayedCards).filter { c -> c.color == Color.PURPLE } + } + + private fun getNeighbourBoards(playerIndex: Int): List<Board> { + return Provider.values().map { getBoard(playerIndex, it.boardPosition) } + } +} |