werewolf-0.4.6.1: A game engine for running werewolf in a chat client

Copyright(c) Henry J. Wylde, 2016
LicenseBSD3
Maintainerpublic@hjwylde.com
Safe HaskellNone
LanguageHaskell2010

Game.Werewolf.Game

Contents

Description

Game functions are defined in Game.Werewolf.Internal.Game. This module just re-exports the functions relevant to the public interface.

Synopsis

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,
  • 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:

  1. apply the Command.
  2. run checkStage.
  3. 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.

data Stage 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.

data Event Source

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.

Constructors

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

isSunrise :: Game -> Bool Source

isSunrise game = game ^. stage == Sunrise

isSunset :: Game -> Bool Source

isSunset game = game ^. stage == Sunset

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.