haverer-0.1.0.0: Implementation of the rules of Love Letter

Safe HaskellNone
LanguageHaskell2010

Haverer.Round

Synopsis

Documentation

data Round playerId Source

Instances

Show playerId => Show (Round playerId) Source 

makeRound :: (Ord playerId, Show playerId) => Deck Complete -> PlayerSet playerId -> Round playerId Source

Make a new round, given a complete Deck and a set of players.

playTurn :: (Ord playerId, Show playerId) => Round playerId -> Either (ActionM playerId (Result playerId, Round playerId)) (Card -> Play playerId -> ActionM playerId (Result playerId, Round playerId)) Source

Play a turn in a Round.

This is the main function in this module.

A turn has two steps. First, the player draws a card. If their hand "busts out" (due to holding the Minister and another high card), then they are eliminated and play proceeds to the next player. This is the Left return value, which returns the new Round and a Result indicating the player bust out.

Second, the player plays one of these two cards. This is the Right return value, a function that takes the players chosen card and play, and returns either a BadAction or a new Round together with the Result of the play.

playTurn' :: (Ord playerId, Show playerId) => Round playerId -> Maybe (Card, Play playerId) -> ActionM playerId (Result playerId, Round playerId) Source

Play a turn in a Round

Similar to playTurn, except that instead of splitting the turn into two phases, there is a single, optional play. If the hand is a busting hand, then the play must be Nothing; if not, the play must be specified.

data BadAction playerId Source

Instances

Show playerId => Show (BadAction playerId) Source 

data Result playerId Source

The result of a turn.

Constructors

BustedOut playerId Card Card

The player whose turn it was "busted out", they held the Minister and another high card, and thus didn't get to play.

Played (Action playerId) (Event playerId)

The player performed an Action resulting in Event.

Instances

Eq playerId => Eq (Result playerId) Source 
Show playerId => Show (Result playerId) Source 

data Event playerId Source

A change to the Round that comes as result of a player's actions.

Constructors

NoChange

Nothing happened. What the player did had no effect.

Protected playerId

The player is now protected.

SwappedHands playerId playerId

The first player has been forced to swap hands with the second.

Eliminated playerId

The player has been eliminated from the round.

ForcedDiscard playerId

The player has been forced to discard their hand.

ForcedReveal playerId playerId Card

The second player has been forced to show their hand to the first.

Instances

Eq playerId => Eq (Event playerId) Source 
Show playerId => Show (Event playerId) Source 

currentPlayer :: Round playerId -> Maybe playerId Source

The ID of the current player. If the Round is over or not started, this will be Nothing.

currentTurn :: Ord playerId => Round playerId -> Maybe (playerId, (Card, Card)) Source

getActivePlayers :: Round playerId -> [playerId] Source

The IDs of all of the active players.

getPlayer :: Ord playerId => Round playerId -> playerId -> Maybe Player Source

Get the player with the given ID. Nothing if there is no such player.

getPlayerMap :: Round playerId -> Map playerId Player Source

A map of player IDs to players.

getPlayers :: Round playerId -> [playerId] Source

The IDs of all of the players.

getWinners :: Victory playerId -> [playerId] Source

nextPlayer :: Round playerId -> Maybe playerId Source

remainingCards :: Round playerId -> Int Source

The number of cards remaining in the deck.

data Victory playerId Source

Constructors

SoleSurvivor playerId Card

The given player is the only survivor.

HighestCard Card [playerId] [(playerId, Card)]

These players have the highest card.

Instances

Eq playerId => Eq (Victory playerId) Source 
Show playerId => Show (Victory playerId) Source 

victory :: Round playerId -> Maybe (Victory playerId) Source

If the Round is Over, return the Victory data. Otherwise, Nothing.

prop_allCardsPresent :: Round playerId -> Bool Source

Are all the cards in the Round?

prop_ringIsActivePlayers :: Eq playerId => Round playerId -> Bool Source