| Copyright | (c) Henry J. Wylde, 2016 |
|---|---|
| License | BSD3 |
| Maintainer | public@hjwylde.com |
| Safe Haskell | None |
| Language | Haskell2010 |
Game.Werewolf.Internal.Player
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.
- data Player
- name :: Lens' Player Text
- role :: Lens' Player Role
- state :: Lens' Player State
- data State
- newPlayer :: Text -> Role -> Player
- findByName :: Text -> [Player] -> Maybe Player
- findByName_ :: Text -> [Player] -> Player
- findByRole :: Role -> [Player] -> Maybe Player
- findByRole_ :: Role -> [Player] -> Player
- filterByRole :: Role -> [Player] -> [Player]
- filterWerewolves :: [Player] -> [Player]
- filterAlive :: [Player] -> [Player]
- filterDead :: [Player] -> [Player]
- isAngel :: Player -> Bool
- isBearTamer :: Player -> Bool
- isDefender :: Player -> Bool
- isScapegoat :: Player -> Bool
- isSeer :: Player -> Bool
- isSimpleVillager :: Player -> Bool
- isSimpleWerewolf :: Player -> Bool
- isVillageIdiot :: Player -> Bool
- isVillagerVillager :: Player -> Bool
- isWildChild :: Player -> Bool
- isWitch :: Player -> Bool
- isWolfHound :: Player -> Bool
- isVillager :: Player -> Bool
- isWerewolf :: Player -> Bool
- isAlive :: Player -> Bool
- isDead :: Player -> Bool
Player
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.
Surprise surprise, players may be dead or alive.
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
isBearTamer :: Player -> Bool Source
isBearTamer player = player ^. role == bearTamerRoleisDefender :: Player -> Bool Source
isDefender player = player ^. role == defenderRoleisScapegoat :: Player -> Bool Source
isScapegoat player = player ^. role == scapegoatRoleisSimpleVillager :: Player -> Bool Source
isSimpleVillager player = player ^. role == simpleVillagerRoleisSimpleWerewolf :: Player -> Bool Source
isSimpleWerewolf player = player ^. role == simpleWerewolfRoleisVillageIdiot :: Player -> Bool Source
isVillageIdiot player = player ^. role == villageIdiotRoleisVillagerVillager :: Player -> Bool Source
isVillagerVillager player = player ^. role == villagerVillagerRoleisWildChild :: Player -> Bool Source
isWildChild player = player ^. role == wildChildRoleisWolfHound :: Player -> Bool Source
isWolfHound player = player ^. role == wolfHoundRoleisVillager :: 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