games.mafia.models¶
Models for the Mafia game implementation.
- This module defines the core data models and enums used in the Mafia game, including:
Game phases (setup, night, day discussion, voting)
Player roles (villager, mafia, detective, doctor, narrator)
Action types (speak, vote, kill, investigate, save)
State tracking for players and game
Decision models for LLM output
Examples
>>> from mafia.models import PlayerRole, GamePhase, MafiaAction
>>>
>>> # Create a player action
>>> action = MafiaAction(
... player_id="Player_1",
... action_type="vote",
... phase=GamePhase.DAY_VOTING,
... round_number=1,
... target_id="Player_2"
... )
Classes¶
Action type enumeration for the Mafia game. |
|
Game phase enumeration for the Mafia game. |
|
An action taken by a player in the Mafia game. |
|
A decision made by a player in the Mafia game. |
|
Schema for LLM to output structured player decisions. |
|
An action taken by the narrator in the Mafia game. |
|
A decision made by the narrator in the Mafia game. |
|
Schema for LLM to output structured narrator decisions. |
|
Player role enumeration for the Mafia game. |
|
State information for a player in the Mafia game. |
Module Contents¶
- class games.mafia.models.ActionType¶
-
Action type enumeration for the Mafia game.
This enum defines all possible actions that players can take during the game, including both general and role-specific actions.
- SPEAK¶
Make a public statement during discussion
- VOTE¶
Vote to eliminate a player during day voting
- KILL¶
Mafia night action to eliminate a player
- INVESTIGATE¶
Detective night action to learn a player’s role
- SAVE¶
Doctor night action to protect a player
Initialize self. See help(type(self)) for accurate signature.
- class games.mafia.models.GamePhase¶
-
Game phase enumeration for the Mafia game.
This enum defines the possible phases of the game, which determine what actions players can take and how the game progresses.
- SETUP¶
Initial game setup phase
- NIGHT¶
Night phase where special roles act secretly
- DAY_DISCUSSION¶
Day phase for open discussion
- DAY_VOTING¶
Voting phase to eliminate a player
- GAME_OVER¶
Game has ended
Initialize self. See help(type(self)) for accurate signature.
- class games.mafia.models.MafiaAction(/, **data)¶
Bases:
pydantic.BaseModel
An action taken by a player in the Mafia game.
This model represents any action a player can take, including speaking, voting, and role-specific night actions.
- Parameters:
data (Any)
- action_type¶
Type of action being taken
- Type:
Examples
>>> action = MafiaAction( ... player_id="Player_1", ... action_type=ActionType.VOTE, ... phase=GamePhase.DAY_VOTING, ... round_number=1, ... target_id="Player_2" ... )
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- class games.mafia.models.MafiaPlayerDecision(/, **data)¶
Bases:
pydantic.BaseModel
A decision made by a player in the Mafia game.
This model represents the complete decision output from a player’s LLM, including both the action and reasoning.
- Parameters:
data (Any)
- action¶
The action the player will take
- Type:
Examples
>>> decision = MafiaPlayerDecision( ... action=MafiaAction(...), ... reasoning="Player seems suspicious based on voting pattern" ... )
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- class games.mafia.models.MafiaPlayerDecisionSchema(/, **data)¶
Bases:
pydantic.BaseModel
Schema for LLM to output structured player decisions.
This model provides a simplified schema for LLM output that can be converted into a full MafiaPlayerDecision.
- Parameters:
data (Any)
Examples
>>> schema = MafiaPlayerDecisionSchema( ... action_type="vote", ... target_id="Player_2", ... reasoning="Suspicious behavior during discussion" ... )
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- class games.mafia.models.NarratorAction(/, **data)¶
Bases:
pydantic.BaseModel
An action taken by the narrator in the Mafia game.
This model represents narrator actions that control game flow and provide information to players.
- Parameters:
data (Any)
Examples
>>> action = NarratorAction( ... announcement="Night falls on the village.", ... phase_transition=True, ... next_phase=GamePhase.NIGHT, ... round_number=1 ... )
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- class games.mafia.models.NarratorDecision(/, **data)¶
Bases:
pydantic.BaseModel
A decision made by the narrator in the Mafia game.
This model represents the complete decision output from the narrator’s LLM, including both the action and reasoning.
- Parameters:
data (Any)
- action¶
The action the narrator will take
- Type:
Examples
>>> decision = NarratorDecision( ... action=NarratorAction(...), ... reasoning="All players have completed their night actions" ... )
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- class games.mafia.models.NarratorDecisionSchema(/, **data)¶
Bases:
pydantic.BaseModel
Schema for LLM to output structured narrator decisions.
This model provides a simplified schema for LLM output that can be converted into a full NarratorDecision.
- Parameters:
data (Any)
Examples
>>> schema = NarratorDecisionSchema( ... announcement="The village falls quiet as night approaches.", ... phase_transition=True, ... reasoning="All players have completed their day actions." ... )
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- class games.mafia.models.PlayerRole¶
-
Player role enumeration for the Mafia game.
This enum defines the possible roles a player can have, each with unique abilities and win conditions.
- VILLAGER¶
Basic role with no special abilities
- MAFIA¶
Can kill one player each night
- DETECTIVE¶
Can investigate one player’s role each night
- DOCTOR¶
Can protect one player from death each night
- NARRATOR¶
Game master role that manages game flow
Initialize self. See help(type(self)) for accurate signature.
- class games.mafia.models.PlayerState(/, **data)¶
Bases:
pydantic.BaseModel
State information for a player in the Mafia game.
This model tracks all information about a player’s current state, including their role, alive status, and what they know about others.
- Parameters:
data (Any)
- role¶
The player’s assigned role
- Type:
- known_roles¶
Roles known to this player
- Type:
Dict[str, PlayerRole]
Examples
>>> state = PlayerState( ... player_id="Player_1", ... role=PlayerRole.DETECTIVE, ... known_roles={"Player_1": PlayerRole.DETECTIVE} ... )
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.