werewolf-1.5.1.1: A game engine for playing werewolf within an arbitrary chat client

Copyright | (c) Henry J. Wylde 2016
License | BSD3
Maintainer | public@hjwylde.com
Safe Haskell | None
Language | Haskell2010

Game.Werewolf.Game

Contents

- Game
  - Folds
  - Prisms
  - Searches
  - Queries

Description

A game is not quite as simple as players! Roughly speaking though, this engine is stateful. The game state only changes when a command is issued. Thus, this module defines the `Game` data structure and any fields required to keep track of the current state.

Synopsis

- data Game
- variant :: Lens' Game Variant
- stage :: Lens' Game Stage
- round :: Lens' Game Int
- players :: Lens' Game [Player]
- boots :: Lens' Game (Map Text [Text])
- chosenVoters :: Lens' Game [Text]
- deadRaised :: Lens' Game Bool
- divine :: Lens' Game (Maybe Text)
- fallenAngelLynched :: Lens' Game Bool
- healUsed :: Lens' Game Bool
- hunterRetaliated :: Lens' Game Bool
- jesterRevealed :: Lens' Game Bool
- marks :: Lens' Game [Text]
- passed :: 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)
- votes :: Lens' Game (Map Text Text)
- data Stage
  - = DruidsTurn
  - | GameOver
  - | HuntersTurn1
  - | HuntersTurn2
  - | Lynching
  - | NecromancersTurn
  - | OraclesTurn
  - | OrphansTurn
  - | ProtectorsTurn
  - | ScapegoatsTurn
  - | SeersTurn
  - | Sunrise
  - | Sunset
  - | VillageDrunksTurn
  - | VillagesTurn
  - | WerewolvesTurn
  - | WitchsTurn
- _DruidsTurn :: Prism' Stage ()
- _GameOver :: Prism' Stage ()
- _HuntersTurn1 :: Prism' Stage ()
- _HuntersTurn2 :: Prism' Stage ()
- _Lynching :: Prism' Stage ()
- _NecromancersTurn :: Prism' Stage ()
- _OraclesTurn :: Prism' Stage ()
- _OrphansTurn :: Prism' Stage ()
- _ProtectorsTurn :: Prism' Stage ()
- _ScapegoatsTurn :: Prism' Stage ()
- _SeersTurn :: Prism' Stage ()
- _Sunrise :: Prism' Stage ()
- _Sunset :: Prism' Stage ()
- _VillageDrunksTurn :: Prism' Stage ()
- _VillagesTurn :: Prism' Stage ()
- _WerewolvesTurn :: Prism' Stage ()
- _WitchsTurn :: Prism' Stage ()
- activity :: (Functor f, Contravariant f) => (Activity -> f Activity) -> Stage -> f Stage
- allStages :: [Stage]
- stageCycle :: [Stage]
- stageAvailable :: Game -> Stage -> Bool
- newGame :: Variant -> [Player] -> Game
- votee :: Fold Game Player
- allowedVoters :: Fold Game Player
- pendingVoters :: Fold Game Player
- firstRound :: Prism' Game Game
- secondRound :: Prism' Game Game
- thirdRound :: Prism' Game Game
- getMarks :: Game -> [Player]
- hasAnyoneWon :: Game -> Bool
- hasDullahanWon :: Game -> Bool
- hasFallenAngelWon :: Game -> Bool
- hasNecromancerWon :: Game -> Bool
- hasVillagersWon :: Game -> Bool
- hasWerewolvesWon :: Game -> Bool
- hasEveryoneLost :: Game -> Bool

# Game

data Game Source #

There are a few key pieces of information that a game always needs to hold. These are:

- the `stage`,
- the `round` number and
- the `players`.

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 Orphan's `roleModel`).

Instances

Eq Game Source # |
Methods (==) :: Game -> Game -> Bool # (/=) :: Game -> Game -> Bool #
Read Game Source # |
Methods readsPrec :: Int -> ReadS Game # readList :: ReadS [Game] # readPrec :: ReadPrec Game # readListPrec :: ReadPrec [Game] #
Show Game Source # |
Methods showsPrec :: Int -> Game -> ShowS # show :: Game -> String # showList :: [Game] -> ShowS #

variant :: Lens' Game Variant Source #

stage :: Lens' Game Stage Source #

round :: Lens' Game Int Source #

players :: Lens' Game [Player] Source #

boots :: Lens' Game (Map Text [Text]) Source #

chosenVoters :: Lens' Game [Text] Source #

deadRaised :: Lens' Game Bool Source #

divine :: Lens' Game (Maybe Text) Source #

fallenAngelLynched :: Lens' Game Bool Source #

healUsed :: Lens' Game Bool Source #

hunterRetaliated :: Lens' Game Bool Source #

jesterRevealed :: Lens' Game Bool Source #

marks :: Lens' Game [Text] Source #

passed :: Lens' Game Bool Source #

poison :: Lens' Game (Maybe Text) Source #

poisonUsed :: Lens' Game Bool Source #

priorProtect :: Lens' Game (Maybe Text) Source #

protect :: Lens' Game (Maybe Text) Source #

roleModel :: Lens' Game (Maybe Text) Source #

scapegoatBlamed :: Lens' Game Bool Source #

see :: Lens' Game (Maybe Text) Source #

votes :: Lens' Game (Map Text Text) Source #

data Stage Source #

Most of these are fairly self-explainable (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.

Constructors

DruidsTurn |
GameOver |
HuntersTurn1 |
HuntersTurn2 |
Lynching |
NecromancersTurn |
OraclesTurn |
OrphansTurn |
ProtectorsTurn |
ScapegoatsTurn |
SeersTurn |
Sunrise |
Sunset |
VillageDrunksTurn |
VillagesTurn |
WerewolvesTurn |
WitchsTurn |

Instances

Eq Stage Source # |
Methods (==) :: Stage -> Stage -> Bool # (/=) :: Stage -> Stage -> Bool #
Read Stage Source # |
Methods readsPrec :: Int -> ReadS Stage # readList :: ReadS [Stage] # readPrec :: ReadPrec Stage # readListPrec :: ReadPrec [Stage] #
Show Stage Source # |
Methods showsPrec :: Int -> Stage -> ShowS # show :: Stage -> String # showList :: [Stage] -> ShowS #
Humanise Stage Source # |
Methods humanise :: Stage -> Text Source #

_DruidsTurn :: Prism' Stage () Source #

_GameOver :: Prism' Stage () Source #

_HuntersTurn1 :: Prism' Stage () Source #

_HuntersTurn2 :: Prism' Stage () Source #

_Lynching :: Prism' Stage () Source #

_NecromancersTurn :: Prism' Stage () Source #

_OraclesTurn :: Prism' Stage () Source #

_OrphansTurn :: Prism' Stage () Source #

_ProtectorsTurn :: Prism' Stage () Source #

_ScapegoatsTurn :: Prism' Stage () Source #

_SeersTurn :: Prism' Stage () Source #

_Sunrise :: Prism' Stage () Source #

_Sunset :: Prism' Stage () Source #

_VillageDrunksTurn :: Prism' Stage () Source #

_VillagesTurn :: Prism' Stage () Source #

_WerewolvesTurn :: Prism' Stage () Source #

_WitchsTurn :: Prism' Stage () Source #

activity :: (Functor f, Contravariant f) => (Activity -> f Activity) -> Stage -> f Stage Source #

allStages :: [Stage] Source #

All of the `Stage`s in the order that they should occur.

stageCycle :: [Stage] Source #

An infinite cycle of all `Stage`s in the order that they should occur.

stageAvailable :: Game -> Stage -> Bool Source #

Checks whether the stage is available for the given `Game`. Most often this just involves checking if there is an applicable role alive, but sometimes it is more complex.

One of the more complex checks here is for the `VillagesTurn`. If the Fallen Angel is in play, then the `VillagesTurn` is available on the first day rather than only after the first night.

newGame :: Variant -> [Player] -> Game Source #

Creates a new `Game` with the given players. No validations are performed here, those are left to the binary.

## Folds

votee :: Fold Game Player Source #

The traversal of the `votes` victim's name. This is the player, if they exist, that received the majority of the votes. This could be an empty list depending on whether the votes were in conflict.

allowedVoters :: Fold Game Player Source #

The traversal of the allowed voters during the `VillagesTurn` or `WerewolvesTurn`. In a standard game, this is all `Alive` players. However there are two scenarios for the `VillagesTurn` that may change this:

1) if the `scapegoat` has chosen some `chosenVoters`, it is these players. 2) if the `jester` has been revealed, he may not vote.

pendingVoters :: Fold Game Player Source #

The traversal of all `Alive` players that have yet to vote. This is synonymous to `voters - Map.keys votes`

## Prisms

firstRound :: Prism' Game Game Source #

The traversal of `Game`s on the first round.

secondRound :: Prism' Game Game Source #

The traversal of `Game`s on the second round.

thirdRound :: Prism' Game Game Source #

The traversal of `Game`s on the third round.

## Searches

getMarks :: Game -> [Player] Source #

Gets all the `marks` in a game (which is names only) and maps them to their player.

## Queries

hasAnyoneWon :: Game -> Bool Source #

Queries whether anyone has won.

hasDullahanWon :: Game -> Bool Source #

Queries whether the Dullahan has won. The Dullahan wins if they manage to eliminate all their marks.

hasFallenAngelWon :: Game -> Bool Source #

Queries whether the Fallen Angel has won. The Fallen Angel wins if they manage to get themselves lynched by the Villagers.

hasNecromancerWon :: Game -> Bool Source #

Queries whether the Necromancer has won. The `Necromancer` wins if they and their zombies are the only players surviving.

N.B., the Jester is not considered when determining whether the `Necromancer` has won.

hasVillagersWon :: Game -> Bool Source #

Queries whether the `Villagers` have won. The `Villagers` win if they are the only players surviving.

N.B., the Dullahan and Fallen Angel are not considered when determining whether the `Villagers` have won.

hasWerewolvesWon :: Game -> Bool Source #

Queries whether the `Werewolves` have won. The `Werewolves` win if they are the only players surviving.

hasEveryoneLost :: Game -> Bool Source #

Queries whether everyone has lost.