Copyright | (c) Henry J. Wylde, 2016 |
---|---|
License | BSD3 |
Maintainer | public@hjwylde.com |
Safe Haskell | None |
Language | Haskell2010 |
Game functions are defined in Game.Werewolf.Internal.Game. This module just re-exports the functions relevant to the public interface.
- data Game
- stage :: Lens' Game Stage
- round :: Lens' Game Int
- players :: Lens' Game [Player]
- events :: Lens' Game [Event]
- passes :: Lens' Game [Text]
- allowedVoters :: Lens' Game [Text]
- heal :: Lens' Game Bool
- healUsed :: Lens' Game Bool
- poison :: Lens' Game (Maybe Text)
- poisonUsed :: Lens' Game Bool
- priorProtect :: Lens' Game (Maybe Text)
- protect :: Lens' Game (Maybe Text)
- roleModel :: Lens' Game (Maybe Text)
- scapegoatBlamed :: Lens' Game Bool
- see :: Lens' Game (Maybe Text)
- villageIdiotRevealed :: Lens' Game Bool
- votes :: Lens' Game (Map Text Text)
- data Stage
- data Event
- isDefendersTurn :: Game -> Bool
- isGameOver :: Game -> Bool
- isScapegoatsTurn :: Game -> Bool
- isSeersTurn :: Game -> Bool
- isSunrise :: Game -> Bool
- isSunset :: Game -> Bool
- isVillagesTurn :: Game -> Bool
- isWerewolvesTurn :: Game -> Bool
- isWildChildsTurn :: Game -> Bool
- isWitchsTurn :: Game -> Bool
- isWolfHoundsTurn :: Game -> Bool
- doesPlayerExist :: Text -> Game -> Bool
Game
There are a few key pieces of information that a game always needs to hold. These are:
- the
stage
, - the
round
number, - the
players
and - the
events
.
Any further fields on the game are specific to one or more roles (and their respective turns!).
Some of the additional fields are reset each round (e.g., the Seer's see
) while others are
kept around for the whole game (e.g., the Wild-child's roleModel
).
In order to advance a game's state, a Command
from a user needs to be received. Afterwards
the following steps should be performed:
apply
theCommand
.- run
checkStage
. - run
checkGameOver
.
checkStage
will perform any additional checks and manipulations to the
game state before advancing the game's stage
. It also runs any relevant events
.
checkGameOver
will check to see if any of the win conditions are met and
if so, advance the game's stage
to GameOver
.
allowedVoters :: Lens' Game [Text] Source
Most of these are fairly self-sufficient (the turn stages). Sunrise
and Sunset
are provided
as meaningful breaks between the day and night as, for example, a VillagesTurn
may not always
be available (curse that retched Scapegoat).
Once the game reaches a turn stage, it requires a Command
to help push
it past. Often only certain roles and commands may be performed at any given stage.
Events occur after a stage is advanced. This is automatically handled in
checkStage
, while an event's specific behaviour is defined by
eventAvailable
and applyEvent
.
For the most part events are used to allow something to happen on a stage different to when it was triggered. E.g., the devour event occurs after the village wakes up rather than when the Werewolves' vote, this gives the Witch a chance to heal the victim.
DevourEvent Text | Werewolves |
NoDevourEvent | Defender, Werewolves and Witch |
PoisonEvent Text | Witch |
Queries
isDefendersTurn :: Game -> Bool Source
isDefendersTurn game = game ^. stage == DefendersTurn
isGameOver :: Game -> Bool Source
isGameOver game = game ^. stage == GameOver
isScapegoatsTurn :: Game -> Bool Source
isScapegoatsTurn game = game ^. stage == ScapegoatsTurn
isSeersTurn :: Game -> Bool Source
isSeersTurn game = game ^. stage == SeersTurn
isVillagesTurn :: Game -> Bool Source
isVillagesTurn game = game ^. stage == VillagesTurn
isWerewolvesTurn :: Game -> Bool Source
isWerewolvesTurn game = game ^. stage == WerewolvesTurn
isWildChildsTurn :: Game -> Bool Source
isWildChildsTurn game = game ^. stage == WildChildsTurn
isWitchsTurn :: Game -> Bool Source
isWitchsTurn game = game ^. stage == WitchsTurn
isWolfHoundsTurn :: Game -> Bool Source
isWolfHoundsTurn game = game ^. stage == WolfHoundsTurn
doesPlayerExist :: Text -> Game -> Bool Source
Queries whether the player is in the game.