Safe Haskell | None |
---|---|
Language | Haskell2010 |
Implementation of the rules of Love Letter.
- data Game playerId
- makeGame :: Ord playerId => PlayerSet playerId -> Game playerId
- newRound :: (Functor m, MonadRandom m, Ord playerId, Show playerId) => Game playerId -> m (Round playerId)
- newRound' :: (Ord playerId, Show playerId) => Game playerId -> Deck Complete -> Round playerId
- players :: Game playerId -> PlayerSet playerId
- roundsPlayed :: Game playerId -> Int
- finalScores :: Ord playerId => Outcome playerId -> [(playerId, Int)]
- scores :: Ord playerId => Game playerId -> [(playerId, Int)]
- winners :: Ord playerId => Outcome playerId -> [playerId]
- data Round playerId
- data BadAction playerId
- data Result playerId
- data Event playerId
- = NoChange
- | Protected playerId
- | SwappedHands playerId playerId
- | Eliminated playerId
- | ForcedDiscard playerId
- | ForcedReveal playerId playerId Card
- playTurn :: (Ord playerId, Show playerId) => Round playerId -> Either (ActionM playerId (Result playerId, Round playerId)) (Card -> Play playerId -> ActionM playerId (Result playerId, Round playerId))
- playTurn' :: (Ord playerId, Show playerId) => Round playerId -> Maybe (Card, Play playerId) -> ActionM playerId (Result playerId, Round playerId)
- getPlayers :: Round playerId -> [playerId]
- getPlayerMap :: Round playerId -> Map playerId Player
- currentPlayer :: Round playerId -> Maybe playerId
- currentTurn :: Ord playerId => Round playerId -> Maybe (playerId, (Card, Card))
- data Card
- data Deck a
- data Complete
- newDeck :: MonadRandom m => m (Deck Complete)
- data Play target
- viewAction :: Action target -> (target, Card, Play target)
- data Player
- getDiscards :: Player -> [Card]
- getHand :: Player -> Maybe Card
- isProtected :: Player -> Maybe Bool
- toPlayers :: PlayerSet a -> [a]
- toPlayerSet :: Ord a => [a] -> Either (Error a) (PlayerSet a)
Documentation
makeGame :: Ord playerId => PlayerSet playerId -> Game playerId Source
Create a new game for the given set of players.
newRound :: (Functor m, MonadRandom m, Ord playerId, Show playerId) => Game playerId -> m (Round playerId) Source
Start a new round of the game, shuffling the deck cards ourselves.
newRound' :: (Ord playerId, Show playerId) => Game playerId -> Deck Complete -> Round playerId Source
Start a new round of the game with an already-shuffled deck of cards.
roundsPlayed :: Game playerId -> Int Source
Return the number of rounds played.
finalScores :: Ord playerId => Outcome playerId -> [(playerId, Int)] Source
Get the final scores at the end of the game.
scores :: Ord playerId => Game playerId -> [(playerId, Int)] Source
Return the current scores of all the players.
The result of a turn.
A change to the Round that comes as result of a player's actions.
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. |
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.
getPlayers :: Round playerId -> [playerId] Source
The IDs of all of the players.
getPlayerMap :: Round playerId -> Map playerId Player Source
A map of player IDs to players.
currentPlayer :: Round playerId -> Maybe playerId Source
The ID of the current player. If the Round is over or not started, this will be Nothing.
newDeck :: MonadRandom m => m (Deck Complete) Source
A thing that can be done with a card.
viewAction :: Action target -> (target, Card, Play target) Source
getDiscards :: Player -> [Card] Source
isProtected :: Player -> Maybe Bool Source