GameNewTurn¶
data class GameNewTurn(
hands: Map<Player, Hand>,
val table: Deck,
val currentPlayer: Player,
val lastToPlay: Player?
) : GameHalfTurn
Game state when it's a new player's turn.
The very first instance of this type is generated when the game starts, before any player makes a move. At that point, currentPlayer is the first player.
The current player plays by calling play followed by GameSelectCard.selectCard.
Constructors¶
GameNewTurn¶
Types¶
CardsNotInHand¶
data class CardsNotInHand(
val currentHand: Hand,
val cardsPlayed: Deck,
val cardsNotInHand: Hand,
val player: Player
) : GameNewTurn.PlayFailures
PlayFailures¶
sealed interface PlayFailures
ValueTooLow¶
data class ValueTooLow(
val cardsPlayed: Deck,
val cardsOnTable: Deck,
val player: Player
) : GameNewTurn.PlayFailures
WrongNumberOfCards¶
data class WrongNumberOfCards(
val cardsPlayed: Deck,
val expectedCardCount: IntRange,
val player: Player
) : GameNewTurn.PlayFailures
Properties¶
allowedCounts¶
val allowedCounts: IntRange
How many cards currentPlayer may place, leaving aside placing their whole hand to win.
An opening turn allows a single card: an empty deck would not beat the empty table either.
currentPlayer¶
val currentPlayer: Player
lastToPlay¶
val lastToPlay: Player?
The last player to have played.
players¶
The set of players in the game.
This set is immutable and ordered: the players will play in the order in which they appear in this set.
table¶
Functions¶
handOf¶
hasLegalMove¶
fun hasLegalMove(): Boolean
Whether currentPlayer can place anything at all, or has no choice but to pass.
For a given number of cards, the highest ones always concatenate to the highest value, so only the best deck of each color and of each value has to be checked.
isWinning¶
Whether playing deck would empty currentPlayer's hand and end the game.
Such a move is exempt from the card count restriction, but only to open: with cards already on the table, the player has to take one back, so their hand does not stay empty.
pass¶
fun pass(): LegalMove<GameNewTurn>
If the currentPlayer has no legal move, or if they want to avoid selecting a card from the current table, they can pass their turn.
The next player can immediately play.
If all players pass in a row, the table is reset and the player who placed those cards gets to play again.
play¶
context(_: Raise<GameNewTurn.PlayFailures>)
fun play(deck: Deck): LegalMove<GameHalfTurn>
The currentPlayer plays the given deck.
deck must consist of cards that currentPlayer has in their hand.
The number of cards in deck must be either the same as the number of cards on the table, or exactly one more.
The value of the deck must be strictly greater than the value of the table.
Special case: if all the cards held by currentPlayer are a valid Deck and they are the first to play (the table is empty), then the player can play them all at once.
Return
If the player has no cards remaining, the game is over and GameFinished is returned. In all other cases, GameSelectCard is returned and the same player must select a card from the old table.