View Source Briscola.Game (Briscola v0.1.0)
Briscola.Game
module implements a struct that represents a game state,
and functions to manipulate the game state according to the stages of the game.
Summary
Types
Options for creating a new game. Players is the number of players, can be 2 or 4. Goes first is the index of the player who goes first (zero indexed)
Functions
Check if the game is over, i.e. the deck is empty and all players have no cards.
Return players in order of highest score to lowest.
Create a new game of Briscola.
Redistribute one card to each player, call this after scoring a trick.
Score the current trick, moving the cards to the winning player's pile. Also clears the trick and sets the action to the winning player.
Check if the trick is over, i.e. all players have played a card.
Types
@type new_game_options() :: [players: 2 | 4, goes_first: non_neg_integer()]
Options for creating a new game. Players is the number of players, can be 2 or 4. Goes first is the index of the player who goes first (zero indexed)
@type t() :: %Briscola.Game{ action_on: integer(), briscola: Briscola.Card.t(), deck: Briscola.Deck.t(), players: [Briscola.Player.t()], trick: [Briscola.Card.t()] }
Functions
Check if the game is over, i.e. the deck is empty and all players have no cards.
@spec lead_suit(t()) :: Briscola.Card.suit()
@spec leaders(t()) :: [Briscola.Player.t()]
Return players in order of highest score to lowest.
@spec new(new_game_options()) :: t()
Create a new game of Briscola.
Redistribute one card to each player, call this after scoring a trick.
Since the last few turns of the game don't have enough cards to deal to all players, it's normal to get back {:error, :not_enough_cards} on the last few turns.
@spec score_trick(t()) :: {:ok, t(), non_neg_integer()} | {:error, :trick_not_over}
Score the current trick, moving the cards to the winning player's pile. Also clears the trick and sets the action to the winning player.
Check if the trick is over, i.e. all players have played a card.
@spec trump_suit(t()) :: Briscola.Card.suit()