diff options
Diffstat (limited to 'game-engine')
31 files changed, 78 insertions, 80 deletions
diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/Game.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/Game.kt index 6caf41a2..639c5535 100644 --- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/Game.kt +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/Game.kt @@ -15,8 +15,11 @@ import org.luxons.sevenwonders.game.effects.SpecialAbility import org.luxons.sevenwonders.game.moves.Move import org.luxons.sevenwonders.game.score.ScoreBoard -class Game( - val id: Long, val settings: Settings, boards: List<Board>, private val decks: Decks +class Game internal constructor( + val id: Long, + private val settings: Settings, + boards: List<Board>, + private val decks: Decks ) { private val table: Table = Table(boards) private val players: List<Player> = boards.map { SimplePlayer(it.playerIndex, table) } @@ -42,12 +45,7 @@ class Game( private fun createPlayerTurnInfo(player: Player): PlayerTurnInfo { val hand = hands.createHand(player) val action = determineAction(hand, player.board) - - val neighbourGuildCards = if (action === Action.PICK_NEIGHBOR_GUILD) { - table.getNeighbourGuildCards(player.index) - } else { - emptyList() - } + val neighbourGuildCards = table.getNeighbourGuildCards(player.index) return PlayerTurnInfo(player.index, table, action, hand, neighbourGuildCards) } diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/Player.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/Player.kt index 1fc34711..c9e90f5c 100644 --- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/Player.kt +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/Player.kt @@ -5,13 +5,13 @@ import org.luxons.sevenwonders.game.boards.Board import org.luxons.sevenwonders.game.boards.RelativeBoardPosition import org.luxons.sevenwonders.game.cards.Card -interface Player { +internal interface Player { val index: Int val board: Board fun getBoard(relativePosition: RelativeBoardPosition): Board } -data class SimplePlayer( +internal data class SimplePlayer( override val index: Int, private val table: Table ): Player { @@ -19,7 +19,7 @@ data class SimplePlayer( override fun getBoard(relativePosition: RelativeBoardPosition) = table.getBoard(index, relativePosition) } -data class PlayerContext( +internal data class PlayerContext( override val index: Int, private val table: Table, val hand: List<Card> diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/Settings.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/Settings.kt index fac3979e..87ce323a 100644 --- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/Settings.kt +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/Settings.kt @@ -5,7 +5,7 @@ import org.luxons.sevenwonders.game.data.WonderSide import org.luxons.sevenwonders.game.data.WonderSidePickMethod import java.util.Random -class Settings @JvmOverloads constructor( +internal class Settings( val nbPlayers: Int, customSettings: CustomizableSettings = CustomizableSettings() ) { 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 index 22b04953..ca1ffd94 100644 --- 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 @@ -7,7 +7,7 @@ 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, player: Player) { +class HandCard internal constructor(val card: Card, player: Player) { val isChainable: Boolean = card.isChainableOn(player.board) val isFree: Boolean = card.isFreeFor(player.board) val isPlayable: Boolean = card.isPlayableBy(player) 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 index 3439a9af..abf4e7bb 100644 --- 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 @@ -2,7 +2,7 @@ package org.luxons.sevenwonders.game.api import org.luxons.sevenwonders.game.cards.Card -data class PlayerTurnInfo( +data class PlayerTurnInfo internal constructor( val playerIndex: Int, val table: Table, val action: Action, 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 index bf2bdfc7..9775b5ee 100644 --- 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 @@ -13,7 +13,7 @@ import org.luxons.sevenwonders.game.moves.Move * 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>) { +class Table internal constructor(val boards: List<Board>) { val nbPlayers: Int = boards.size @@ -30,11 +30,11 @@ class Table(val boards: List<Board>) { fun getBoard(playerIndex: Int, position: RelativeBoardPosition): Board = boards[position.getIndexFrom(playerIndex, nbPlayers)] - fun increaseCurrentAge() { + internal fun increaseCurrentAge() { this.currentAge++ } - fun resolveMilitaryConflicts() { + internal fun resolveMilitaryConflicts() { for (i in 0 until nbPlayers) { val board1 = getBoard(i) val board2 = getBoard(i, RelativeBoardPosition.RIGHT) @@ -54,7 +54,7 @@ class Table(val boards: List<Board>) { } } - fun getNeighbourGuildCards(playerIndex: Int): List<Card> = neighboursPositions() + internal fun getNeighbourGuildCards(playerIndex: Int): List<Card> = neighboursPositions() .flatMap { getBoard(playerIndex, it).getPlayedCards() } .filter { it.color == Color.PURPLE } } diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/boards/Board.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/boards/Board.kt index 34cccc49..64db9f41 100644 --- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/boards/Board.kt +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/boards/Board.kt @@ -12,7 +12,7 @@ import org.luxons.sevenwonders.game.score.PlayerScore import org.luxons.sevenwonders.game.score.ScoreCategory import org.luxons.sevenwonders.game.wonders.Wonder -class Board(val wonder: Wonder, val playerIndex: Int, settings: Settings) { +class Board internal constructor(val wonder: Wonder, val playerIndex: Int, settings: Settings) { val production = Production() val publicProduction = Production() @@ -74,7 +74,7 @@ class Board(val wonder: Wonder, val playerIndex: Int, settings: Settings) { consumedFreeCards[age] = true } - fun computeScore(player: Player): PlayerScore = PlayerScore( + internal fun computeScore(player: Player): PlayerScore = PlayerScore( gold, mapOf( ScoreCategory.CIVIL to computePointsForCards(player, Color.BLUE), ScoreCategory.MILITARY to military.totalPoints, 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 2c22ca54..56dc7077 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 @@ -7,7 +7,7 @@ import org.luxons.sevenwonders.game.resources.ResourceTransactions data class CardBack(val image: String) -data class Card( +data class Card internal constructor( val name: String, val color: Color, val requirements: Requirements, @@ -19,20 +19,20 @@ data class Card( ) { private fun isAllowedOnBoard(board: Board): Boolean = !board.isPlayed(name) // cannot play twice the same card - fun isFreeFor(board: Board): Boolean = isChainableOn(board) || isFreeWithoutChainingOn(board) + internal fun isFreeFor(board: Board): Boolean = isChainableOn(board) || isFreeWithoutChainingOn(board) - fun isChainableOn(board: Board): Boolean = + internal fun isChainableOn(board: Board): Boolean = isAllowedOnBoard(board) && chainParent != null && board.isPlayed(chainParent) private fun isFreeWithoutChainingOn(board: Board) = isAllowedOnBoard(board) && requirements.areMetWithoutNeighboursBy(board) && requirements.gold == 0 - fun isPlayableBy(player: Player): Boolean { + internal fun isPlayableBy(player: Player): Boolean { val board = player.board return isAllowedOnBoard(board) && (isChainableOn(board) || requirements.areMetBy(player)) } - fun applyTo(player: Player, transactions: ResourceTransactions) { + internal fun applyTo(player: Player, transactions: ResourceTransactions) { if (!isChainableOn(player.board)) { requirements.pay(player, transactions) } diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/cards/Decks.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/cards/Decks.kt index bd7b4bde..f3c5d471 100644 --- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/cards/Decks.kt +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/cards/Decks.kt @@ -1,6 +1,6 @@ package org.luxons.sevenwonders.game.cards -fun List<Card>.deal(nbPlayers: Int): Hands { +internal fun List<Card>.deal(nbPlayers: Int): Hands { val hands: Map<Int, List<Card>> = this.withIndex() .groupBy { (index, _) -> index % nbPlayers } .mapValues { it.value.map { (_, cards) -> cards } } @@ -9,7 +9,7 @@ fun List<Card>.deal(nbPlayers: Int): Hands { return Hands(allHands) } -class Decks(private val cardsPerAge: Map<Int, List<Card>>) { +internal class Decks(private val cardsPerAge: Map<Int, List<Card>>) { @Throws(Decks.CardNotFoundException::class) fun getCard(age: Int, cardName: String): Card = diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/cards/Hands.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/cards/Hands.kt index c64e1886..1e5f839a 100644 --- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/cards/Hands.kt +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/cards/Hands.kt @@ -3,7 +3,7 @@ package org.luxons.sevenwonders.game.cards import org.luxons.sevenwonders.game.Player import org.luxons.sevenwonders.game.api.HandCard -class Hands internal constructor(private val hands: List<List<Card>>) { +internal class Hands(private val hands: List<List<Card>>) { val isEmpty: Boolean = this.hands.all(List<Card>::isEmpty) diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/cards/Requirements.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/cards/Requirements.kt index c253f86c..6a38965f 100644 --- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/cards/Requirements.kt +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/cards/Requirements.kt @@ -6,7 +6,7 @@ import org.luxons.sevenwonders.game.resources.ResourceTransactions import org.luxons.sevenwonders.game.resources.Resources import org.luxons.sevenwonders.game.resources.bestPrice -data class Requirements @JvmOverloads constructor( +data class Requirements internal constructor( val gold: Int = 0, val resources: Resources = Resources() ) { @@ -17,7 +17,7 @@ data class Requirements @JvmOverloads constructor( * * @return true if the given board meets these requirements without any transaction with its neighbours */ - fun areMetWithoutNeighboursBy(board: Board): Boolean { + internal fun areMetWithoutNeighboursBy(board: Board): Boolean { return hasRequiredGold(board) && producesRequiredResources(board) } @@ -29,7 +29,7 @@ data class Requirements @JvmOverloads constructor( * * @return true if the given board meets these requirements */ - fun areMetWithHelpBy(board: Board, boughtResources: ResourceTransactions): Boolean { + internal fun areMetWithHelpBy(board: Board, boughtResources: ResourceTransactions): Boolean { if (!hasRequiredGold(board, boughtResources)) { return false } @@ -37,15 +37,14 @@ data class Requirements @JvmOverloads constructor( } /** - * Returns whether the given player's board meets these requirements, either on its own or by buying resources to + * Returns whether the given player meets these requirements, either on its own or by buying resources to * neighbours. * - * @param table the current game table - * @param playerIndex the index of the player to check + * @param player the player to check * * @return true if the given player's board could meet these requirements */ - fun areMetBy(player: Player): Boolean { + internal fun areMetBy(player: Player): Boolean { val board = player.board if (!hasRequiredGold(board)) { return false @@ -76,7 +75,7 @@ data class Requirements @JvmOverloads constructor( return board.production.contains(remainingResources) } - fun pay(player: Player, transactions: ResourceTransactions) { + internal fun pay(player: Player, transactions: ResourceTransactions) { player.board.removeGold(gold) transactions.execute(player) } diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/BonusPerBoardElement.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/BonusPerBoardElement.kt index bcac2a9c..ec446d40 100644 --- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/BonusPerBoardElement.kt +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/BonusPerBoardElement.kt @@ -11,7 +11,7 @@ enum class BoardElementType { DEFEAT_TOKEN } -data class BonusPerBoardElement ( +internal data class BonusPerBoardElement ( val boards: List<RelativeBoardPosition>, val type: BoardElementType, val gold: Int = 0, diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/Discount.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/Discount.kt index 56e9befb..981ad9bd 100644 --- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/Discount.kt +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/Discount.kt @@ -4,7 +4,7 @@ import org.luxons.sevenwonders.game.boards.Board import org.luxons.sevenwonders.game.resources.Provider import org.luxons.sevenwonders.game.resources.ResourceType -data class Discount( +internal data class Discount( val resourceTypes: List<ResourceType> = emptyList(), val providers: List<Provider> = emptyList(), val discountedPrice: Int = 1 diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/Effect.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/Effect.kt index c3b7b140..55744669 100644 --- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/Effect.kt +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/Effect.kt @@ -7,7 +7,7 @@ import org.luxons.sevenwonders.game.Player * may affect (or depend on) the adjacent boards. It can have an instantaneous effect on the board, or be postponed to * the end of game where point calculations take place. */ -interface Effect { +internal interface Effect { fun applyTo(player: Player) diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/EndGameEffect.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/EndGameEffect.kt index 09b86ab7..b4e7a683 100644 --- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/EndGameEffect.kt +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/EndGameEffect.kt @@ -2,7 +2,7 @@ package org.luxons.sevenwonders.game.effects import org.luxons.sevenwonders.game.Player -abstract class EndGameEffect : Effect { +internal abstract class EndGameEffect : Effect { // EndGameEffects don't do anything when applied to the board, they simply give more points in the end override fun applyTo(player: Player) = Unit diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/GoldIncrease.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/GoldIncrease.kt index 6f5e5b2a..f6e37841 100644 --- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/GoldIncrease.kt +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/GoldIncrease.kt @@ -2,7 +2,7 @@ package org.luxons.sevenwonders.game.effects import org.luxons.sevenwonders.game.boards.Board -data class GoldIncrease(val amount: Int) : InstantOwnBoardEffect() { +internal data class GoldIncrease(val amount: Int) : InstantOwnBoardEffect() { public override fun applyTo(board: Board) = board.addGold(amount) } diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/InstantOwnBoardEffect.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/InstantOwnBoardEffect.kt index fb0d155c..0b50656c 100644 --- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/InstantOwnBoardEffect.kt +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/InstantOwnBoardEffect.kt @@ -3,7 +3,7 @@ package org.luxons.sevenwonders.game.effects import org.luxons.sevenwonders.game.Player import org.luxons.sevenwonders.game.boards.Board -abstract class InstantOwnBoardEffect : Effect { +internal abstract class InstantOwnBoardEffect : Effect { override fun applyTo(player: Player) = applyTo(player.board) diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/MilitaryReinforcements.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/MilitaryReinforcements.kt index e01e9481..a168943c 100644 --- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/MilitaryReinforcements.kt +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/MilitaryReinforcements.kt @@ -2,7 +2,7 @@ package org.luxons.sevenwonders.game.effects import org.luxons.sevenwonders.game.boards.Board -data class MilitaryReinforcements(val count: Int) : InstantOwnBoardEffect() { +internal data class MilitaryReinforcements(val count: Int) : InstantOwnBoardEffect() { public override fun applyTo(board: Board) = board.military.addShields(count) } diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/ProductionIncrease.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/ProductionIncrease.kt index e8578eed..4bd4a27f 100644 --- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/ProductionIncrease.kt +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/ProductionIncrease.kt @@ -3,7 +3,7 @@ package org.luxons.sevenwonders.game.effects import org.luxons.sevenwonders.game.boards.Board import org.luxons.sevenwonders.game.resources.Production -data class ProductionIncrease(val production: Production, val isSellable: Boolean) : InstantOwnBoardEffect() { +internal data class ProductionIncrease(val production: Production, val isSellable: Boolean) : InstantOwnBoardEffect() { public override fun applyTo(board: Board) { board.production.addAll(production) diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/RawPointsIncrease.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/RawPointsIncrease.kt index f075742e..a47686da 100644 --- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/RawPointsIncrease.kt +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/RawPointsIncrease.kt @@ -2,7 +2,7 @@ package org.luxons.sevenwonders.game.effects import org.luxons.sevenwonders.game.Player -data class RawPointsIncrease(val points: Int) : EndGameEffect() { +internal data class RawPointsIncrease(val points: Int) : EndGameEffect() { override fun computePoints(player: Player): Int = points } diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/ScienceProgress.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/ScienceProgress.kt index af4c0d53..462330db 100644 --- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/ScienceProgress.kt +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/ScienceProgress.kt @@ -3,7 +3,7 @@ package org.luxons.sevenwonders.game.effects import org.luxons.sevenwonders.game.boards.Board import org.luxons.sevenwonders.game.boards.Science -class ScienceProgress(val science: Science) : InstantOwnBoardEffect() { +internal class ScienceProgress(val science: Science) : InstantOwnBoardEffect() { public override fun applyTo(board: Board) = board.science.addAll(science) } diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/SpecialAbility.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/SpecialAbility.kt index deddd780..d271134f 100644 --- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/SpecialAbility.kt +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/SpecialAbility.kt @@ -33,7 +33,7 @@ enum class SpecialAbility { } }; - fun apply(board: Board) = board.addSpecial(this) + internal fun apply(board: Board) = board.addSpecial(this) - open fun computePoints(player: Player): Int = 0 + internal open fun computePoints(player: Player): Int = 0 } diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/SpecialAbilityActivation.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/SpecialAbilityActivation.kt index 136beab1..66521679 100644 --- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/SpecialAbilityActivation.kt +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/SpecialAbilityActivation.kt @@ -2,7 +2,7 @@ package org.luxons.sevenwonders.game.effects import org.luxons.sevenwonders.game.Player -data class SpecialAbilityActivation(val specialAbility: SpecialAbility) : Effect { +internal data class SpecialAbilityActivation(val specialAbility: SpecialAbility) : Effect { override fun applyTo(player: Player) = specialAbility.apply(player.board) diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/moves/Move.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/moves/Move.kt index 86b26ca9..ce50e3e0 100644 --- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/moves/Move.kt +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/moves/Move.kt @@ -7,17 +7,18 @@ import org.luxons.sevenwonders.game.cards.Card import org.luxons.sevenwonders.game.resources.ResourceTransactions abstract class Move internal constructor( - move: PlayerMove, + val move: PlayerMove, val card: Card, internal val playerContext: PlayerContext ) { val type: MoveType = move.type - val transactions: ResourceTransactions = ResourceTransactions(move.transactions) + // TODO restore visibility to public + internal val transactions: ResourceTransactions = ResourceTransactions(move.transactions) - abstract fun place(discardedCards: MutableList<Card>, settings: Settings) + internal abstract fun place(discardedCards: MutableList<Card>, settings: Settings) - abstract fun activate(discardedCards: List<Card>, settings: Settings) + internal abstract fun activate(discardedCards: List<Card>, settings: Settings) } class InvalidMoveException internal constructor(move: Move, message: String) : IllegalArgumentException( diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/resources/BestPriceCalculator.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/resources/BestPriceCalculator.kt index 24149e59..3b86fd97 100644 --- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/resources/BestPriceCalculator.kt +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/resources/BestPriceCalculator.kt @@ -4,20 +4,20 @@ import org.luxons.sevenwonders.game.Player import java.util.ArrayList import java.util.EnumSet -fun bestPrice(resources: Resources, player: Player): Int? { +internal fun bestPrice(resources: Resources, player: Player): Int? { return bestSolution(resources, player)?.price } -fun bestTransaction(resources: Resources, player: Player): ResourceTransactions? { +internal fun bestTransaction(resources: Resources, player: Player): ResourceTransactions? { return bestSolution(resources, player)?.transactions } -fun bestSolution(resources: Resources, player: Player): TransactionPlan? { +internal fun bestSolution(resources: Resources, player: Player): TransactionPlan? { val calculator = BestPriceCalculator(resources, player) return calculator.computeBestSolution() } -data class TransactionPlan(val price: Int, val transactions: ResourceTransactions) +internal data class TransactionPlan(val price: Int, val transactions: ResourceTransactions) private class ResourcePool( val provider: Provider?, diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/resources/Production.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/resources/Production.kt index 1a3240c2..2dd6d60f 100644 --- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/resources/Production.kt +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/resources/Production.kt @@ -3,7 +3,7 @@ package org.luxons.sevenwonders.game.resources import java.util.Arrays import java.util.EnumSet -class Production { +class Production internal constructor() { val fixedResources = Resources() private val alternativeResources: MutableSet<Set<ResourceType>> = mutableSetOf() diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/resources/ResourceTransactions.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/resources/ResourceTransactions.kt index 1f92e764..52d10064 100644 --- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/resources/ResourceTransactions.kt +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/resources/ResourceTransactions.kt @@ -2,7 +2,7 @@ package org.luxons.sevenwonders.game.resources import org.luxons.sevenwonders.game.Player -data class ResourceTransactions(private val resourcesByProvider: MutableMap<Provider, Resources> = mutableMapOf()) { +internal data class ResourceTransactions(private val resourcesByProvider: MutableMap<Provider, Resources> = mutableMapOf()) { constructor(transactions: Collection<ResourceTransaction>) : this() { transactions.forEach { t -> add(t.provider, t.resources) } diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/resources/TradingRules.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/resources/TradingRules.kt index b6dc09e6..dc0dc489 100644 --- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/resources/TradingRules.kt +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/resources/TradingRules.kt @@ -1,6 +1,6 @@ package org.luxons.sevenwonders.game.resources -class TradingRules(private val defaultCost: Int) { +class TradingRules internal constructor(private val defaultCost: Int) { private val costs: MutableMap<ResourceType, MutableMap<Provider, Int>> = mutableMapOf() @@ -11,11 +11,11 @@ class TradingRules(private val defaultCost: Int) { internal fun getCost(type: ResourceType, provider: Provider): Int = costs.computeIfAbsent(type) { mutableMapOf() }.getOrDefault(provider, defaultCost) - fun setCost(type: ResourceType, provider: Provider, cost: Int) { + internal fun setCost(type: ResourceType, provider: Provider, cost: Int) { costs.computeIfAbsent(type) { mutableMapOf() }[provider] = cost } - fun computeCost(transactions: ResourceTransactions): Int { + internal fun computeCost(transactions: ResourceTransactions): Int { return transactions.asList().map { this.computeCost(it) }.sum() } diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/wonders/Wonder.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/wonders/Wonder.kt index e7b42eca..5d771491 100644 --- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/wonders/Wonder.kt +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/wonders/Wonder.kt @@ -6,7 +6,7 @@ import org.luxons.sevenwonders.game.cards.CardBack import org.luxons.sevenwonders.game.resources.ResourceTransactions import org.luxons.sevenwonders.game.resources.ResourceType -class Wonder( +class Wonder internal constructor( val name: String, val initialResource: ResourceType, val stages: List<WonderStage>, @@ -30,15 +30,15 @@ class Wonder( return stages[lastLevel] } - fun isNextStageBuildable(board: Board, boughtResources: ResourceTransactions): Boolean = + internal fun isNextStageBuildable(board: Board, boughtResources: ResourceTransactions): Boolean = nbBuiltStages < stages.size && nextStage.isBuildable(board, boughtResources) - fun placeCard(cardBack: CardBack) = nextStage.placeCard(cardBack) + internal fun placeCard(cardBack: CardBack) = nextStage.placeCard(cardBack) - fun activateLastBuiltStage(player: Player, boughtResources: ResourceTransactions) = + internal fun activateLastBuiltStage(player: Player, boughtResources: ResourceTransactions) = lastBuiltStage.activate(player, boughtResources) - fun computePoints(player: Player): Int = + internal fun computePoints(player: Player): Int = stages.filter { it.isBuilt } .flatMap { it.effects } .map { it.computePoints(player) } diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/wonders/WonderStage.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/wonders/WonderStage.kt index 04a6de0c..26d66f00 100644 --- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/wonders/WonderStage.kt +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/wonders/WonderStage.kt @@ -7,7 +7,7 @@ import org.luxons.sevenwonders.game.cards.Requirements import org.luxons.sevenwonders.game.effects.Effect import org.luxons.sevenwonders.game.resources.ResourceTransactions -class WonderStage(val requirements: Requirements, val effects: List<Effect>) { +class WonderStage internal constructor(val requirements: Requirements, val effects: List<Effect>) { var cardBack: CardBack? = null private set @@ -15,7 +15,7 @@ class WonderStage(val requirements: Requirements, val effects: List<Effect>) { val isBuilt: Boolean get() = cardBack != null - fun isBuildable(board: Board, boughtResources: ResourceTransactions): Boolean { + internal fun isBuildable(board: Board, boughtResources: ResourceTransactions): Boolean { return requirements.areMetWithHelpBy(board, boughtResources) } diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/test/TestUtils.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/test/TestUtils.kt index 2208431d..bf718d32 100644 --- a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/test/TestUtils.kt +++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/test/TestUtils.kt @@ -35,7 +35,7 @@ fun testCustomizableSettings(initialGold: Int = 0): CustomizableSettings { return CustomizableSettings(randomSeedForTests = SEED).copy(initialGold = initialGold) } -fun testSettings(nbPlayers: Int): Settings { +internal fun testSettings(nbPlayers: Int): Settings { return Settings(nbPlayers, testCustomizableSettings()) } @@ -43,7 +43,7 @@ fun testTable(nbPlayers: Int): Table { return testTable(testSettings(nbPlayers)) } -fun testTable(settings: Settings): Table { +internal fun testTable(settings: Settings): Table { return Table(testBoards(settings.nbPlayers, settings)) } @@ -103,12 +103,12 @@ fun createResources(vararg types: ResourceType): Resources { return resources } -fun createTransactions(provider: Provider, vararg resources: ResourceType): ResourceTransactions { +internal fun createTransactions(provider: Provider, vararg resources: ResourceType): ResourceTransactions { val transaction = createTransaction(provider, *resources) return ResourceTransactions(listOf(transaction)) } -fun createTransactions(vararg transactions: ResourceTransaction): ResourceTransactions { +internal fun createTransactions(vararg transactions: ResourceTransaction): ResourceTransactions { return ResourceTransactions(Arrays.asList(*transactions)) } @@ -133,7 +133,7 @@ fun testCard(color: Color): Card { return testCard("Test Card", color) } -fun testCard(color: Color, effect: Effect): Card { +internal fun testCard(color: Color, effect: Effect): Card { return testCard("Test Card", color, effect) } @@ -145,11 +145,11 @@ fun createGuildCards(count: Int): List<Card> { return IntRange(0, count).map { createGuildCard(it) } } -fun createGuildCard(num: Int, effect: Effect? = null): Card { +internal fun createGuildCard(num: Int, effect: Effect? = null): Card { return testCard("Test Guild $num", Color.PURPLE, effect) } -fun testCard( +internal fun testCard( name: String = "Test Card", color: Color = Color.BLUE, effect: Effect? = null, @@ -185,7 +185,7 @@ fun getDifferentColorFrom(vararg colors: Color): Color { throw IllegalArgumentException("All colors are forbidden!") } -fun createScienceProgress(compasses: Int, wheels: Int, tablets: Int, jokers: Int): ScienceProgress { +internal fun createScienceProgress(compasses: Int, wheels: Int, tablets: Int, jokers: Int): ScienceProgress { return ScienceProgress(createScience(compasses, wheels, tablets, jokers)) } @@ -206,18 +206,18 @@ fun createScience(compasses: Int, wheels: Int, tablets: Int, jokers: Int): Scien return science } -fun playCardWithEffect(player: Player, color: Color, effect: Effect) { +internal fun playCardWithEffect(player: Player, color: Color, effect: Effect) { val card = testCard(color, effect) player.board.addCard(card) card.applyTo(player, ResourceTransactions()) } -fun createMove(context: PlayerContext, card: Card, type: MoveType, vararg transactions: ResourceTransaction): Move { +internal fun createMove(context: PlayerContext, card: Card, type: MoveType, vararg transactions: ResourceTransaction): Move { val playerMove = PlayerMove(type, card.name, Arrays.asList(*transactions)) return type.create(playerMove, card, context) } -fun singleBoardPlayer(board: Board): Player { +internal fun singleBoardPlayer(board: Board): Player { return object: Player { override val index=0 override val board = board |