Skip to content

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

constructor(
    hands: Map<Player, Hand>, 
    table: Deck, 
    currentPlayer: Player, 
    lastToPlay: Player?
)

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

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

lastToPlay

The last player to have played.

players

open override val players: Set<Player>

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

val table: Deck

Functions

handOf

open override fun handOf(player: Player): Hand

Returns the Hand (the cards) of player.

If player is not part of the game, an error is thrown.

hasLegalMove

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

fun isWinning(deck: Deck): Boolean

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

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

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.