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.Internal.Player

Contents

Description

Players are quite simple in themselves. They have a name, role and state. Any complex behaviour is handled in Game.Werewolf.Command and Game.Werewolf.Engine. This module provides utility functions for searching, filtering and querying lists of players based on these 3 attributes.

Synopsis

Player

data Player Source

A player has a name, role and state. Any stateful information needed for a player's role is held on the Game itself.

N.B., player equality is defined on just the name as a player's role may change throughout the game.

data State Source

Surprise surprise, players may be dead or alive.

Constructors

Alive 
Dead 

newPlayer :: Text -> Role -> Player Source

Creates a new Alive player.

Searches

findByName :: Text -> [Player] -> Maybe Player Source

Attempts to find the first player in the list with the given name.

findByName_ :: Text -> [Player] -> Player Source

Finds the first player in the list with the given name.

findByName_ name = fromJust . findByName name

findByRole :: Role -> [Player] -> Maybe Player Source

Attempts to find the first player in the list with the given role.

findByRole_ :: Role -> [Player] -> Player Source

Finds the first player in the list with the given role.

findByRole_ role = fromJust . findByRole role

Filters

filterByRole :: Role -> [Player] -> [Player] Source

Filters players by role.

filterWerewolves :: [Player] -> [Player] Source

Filters players by allegiance, not role. If you're after filtering by role, try filterByRole simpleWerewolfRole.

filterWerewolves = filter isWerewolf

filterAlive :: [Player] -> [Player] Source

filterAlive = filter isAlive

filterDead :: [Player] -> [Player] Source

filterDead = filter isDead

Queries

isAngel :: Player -> Bool Source

isAngel player = player ^. role == angelRole

isBearTamer :: Player -> Bool Source

isBearTamer player = player ^. role == bearTamerRole

isDefender :: Player -> Bool Source

isDefender player = player ^. role == defenderRole

isScapegoat :: Player -> Bool Source

isScapegoat player = player ^. role == scapegoatRole

isSeer :: Player -> Bool Source

isSeer player = player ^. role == seerRole

isSimpleVillager :: Player -> Bool Source

isSimpleVillager player = player ^. role == simpleVillagerRole

isSimpleWerewolf :: Player -> Bool Source

isSimpleWerewolf player = player ^. role == simpleWerewolfRole

isVillageIdiot :: Player -> Bool Source

isVillageIdiot player = player ^. role == villageIdiotRole

isVillagerVillager :: Player -> Bool Source

isVillagerVillager player = player ^. role == villagerVillagerRole

isWildChild :: Player -> Bool Source

isWildChild player = player ^. role == wildChildRole

isWitch :: Player -> Bool Source

isWitch player = player ^. role == witchRole

isWolfHound :: Player -> Bool Source

isWolfHound player = player ^. role == wolfHoundRole

isVillager :: Player -> Bool Source

Queries a player's allegiance, not role. If you're after querying their role, try isSimpleVillager.

isVillager player = player ^. role . allegiance == Villagers

isWerewolf :: Player -> Bool Source

Queries a player's allegiance, not role. If you're after querying their role, try isSimpleWerewolf.

isWerewolf player = player ^. role . allegiance == Werewolves

isAlive :: Player -> Bool Source

isAlive player = player ^. state == Alive

isDead :: Player -> Bool Source

isDead player = player ^. state == Dead