summaryrefslogtreecommitdiff
path: root/sw-engine/src
diff options
context:
space:
mode:
authorJoffrey Bion <joffrey.bion@gmail.com>2021-03-08 01:31:26 +0100
committerJoffrey Bion <joffrey.bion@gmail.com>2021-03-08 01:31:59 +0100
commit3f8a672dcfefdd9304ba8b489865cb12153a75e3 (patch)
tree3b5e091d37b9f821e189ec26791db7a4eec177b4 /sw-engine/src
parentMake SayReady action an object (diff)
downloadseven-wonders-3f8a672dcfefdd9304ba8b489865cb12153a75e3.tar.gz
seven-wonders-3f8a672dcfefdd9304ba8b489865cb12153a75e3.tar.bz2
seven-wonders-3f8a672dcfefdd9304ba8b489865cb12153a75e3.zip
Make turnInfo generic in its action type
Diffstat (limited to 'sw-engine/src')
-rw-r--r--sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/Game.kt10
-rw-r--r--sw-engine/src/test/kotlin/org/luxons/sevenwonders/engine/GameTest.kt12
2 files changed, 13 insertions, 9 deletions
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 6c44c7b3..5281c753 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
@@ -26,7 +26,7 @@ class Game internal constructor(
private val players: List<Player> = boards.map { SimplePlayer(it.playerIndex, table) }
private val discardedCards: MutableList<Card> = mutableListOf()
private val preparedMoves: MutableMap<Int, Move> = mutableMapOf()
- private var currentTurnInfo: List<PlayerTurnInfo> = emptyList()
+ private var currentTurnInfo: List<PlayerTurnInfo<*>> = emptyList()
private var hands: Hands = Hands(emptyList())
private var militaryConflictsResolved = false
@@ -88,7 +88,11 @@ class Game internal constructor(
}
val scoreBoard = computeScore()
currentTurnInfo = currentTurnInfo.map {
- it.copy(action = TurnAction.WatchScore(message = ActionMessages.WATCH_SCORE, scoreBoard = scoreBoard))
+ PlayerTurnInfo(
+ playerIndex = it.playerIndex,
+ table = it.table,
+ action = TurnAction.WatchScore(message = ActionMessages.WATCH_SCORE, scoreBoard = scoreBoard),
+ )
}
}
@@ -105,7 +109,7 @@ class Game internal constructor(
/**
* Returns information for each player about the current turn.
*/
- fun getCurrentTurnInfo(): List<PlayerTurnInfo> = currentTurnInfo
+ fun getCurrentTurnInfo(): List<PlayerTurnInfo<*>> = currentTurnInfo
/**
* Prepares the given [move] for the player at the given [playerIndex].
diff --git a/sw-engine/src/test/kotlin/org/luxons/sevenwonders/engine/GameTest.kt b/sw-engine/src/test/kotlin/org/luxons/sevenwonders/engine/GameTest.kt
index 09cdd970..5368fbc0 100644
--- a/sw-engine/src/test/kotlin/org/luxons/sevenwonders/engine/GameTest.kt
+++ b/sw-engine/src/test/kotlin/org/luxons/sevenwonders/engine/GameTest.kt
@@ -52,7 +52,7 @@ class GameTest {
} while (!game.getCurrentTurnInfo().first().isStartOfAge(age + 1))
}
- private fun PlayerTurnInfo.isStartOfAge(age: Int) = action is TurnAction.WatchScore || currentAge == age
+ private fun PlayerTurnInfo<*>.isStartOfAge(age: Int) = action is TurnAction.WatchScore || currentAge == age
private fun playTurn(nbPlayers: Int, game: Game, ageToCheck: Int) {
val turnInfos = game.getCurrentTurnInfo()
@@ -72,7 +72,7 @@ class GameTest {
assertEquals(expectedMoves, game.getCurrentTurnInfo()[0].table.lastPlayedMoves)
}
- private fun PlayerTurnInfo.firstAvailableMove(): MoveExpectation? = when (val a = action) {
+ private fun PlayerTurnInfo<*>.firstAvailableMove(): MoveExpectation? = when (val a = action) {
is TurnAction.PlayFromHand -> createPlayCardMove(this, a.hand)
is TurnAction.PlayFromDiscarded -> createPlayFreeDiscardedCardMove(this, a.discardedCards)
is TurnAction.PickNeighbourGuild -> createPickGuildMove(this, a.neighbourGuildCards)
@@ -81,7 +81,7 @@ class GameTest {
is TurnAction.WatchScore -> fail("should not have WATCH_SCORE action before end of game")
}
- private fun createPlayCardMove(turnInfo: PlayerTurnInfo, hand: List<HandCard>): MoveExpectation {
+ private fun createPlayCardMove(turnInfo: PlayerTurnInfo<*>, hand: List<HandCard>): MoveExpectation {
val wonderBuildability = turnInfo.wonderBuildability
if (wonderBuildability.isBuildable) {
val transactions = wonderBuildability.transactionsOptions.first()
@@ -95,7 +95,7 @@ class GameTest {
}
}
- private fun createPlayFreeDiscardedCardMove(turn: PlayerTurnInfo, discardedCards: List<HandCard>): MoveExpectation {
+ private fun createPlayFreeDiscardedCardMove(turn: PlayerTurnInfo<*>, discardedCards: List<HandCard>): MoveExpectation {
val card = discardedCards.random()
return MoveExpectation(
turn.playerIndex,
@@ -105,7 +105,7 @@ class GameTest {
}
private fun planMove(
- turnInfo: PlayerTurnInfo,
+ turnInfo: PlayerTurnInfo<*>,
moveType: MoveType,
card: HandCard,
transactions: ResourceTransactions,
@@ -115,7 +115,7 @@ class GameTest {
PlayedMove(turnInfo.playerIndex, moveType, card.toPlayedCard(), transactions),
)
- private fun createPickGuildMove(turnInfo: PlayerTurnInfo, neighbourGuilds: List<HandCard>): MoveExpectation {
+ private fun createPickGuildMove(turnInfo: PlayerTurnInfo<*>, neighbourGuilds: List<HandCard>): MoveExpectation {
// the game should send action WAIT if no guild cards are available around
assertFalse(neighbourGuilds.isEmpty())
val card = neighbourGuilds.first()
bgstack15