Install the Open Mafia Engine package from PyPI, with recommended extras:
1
pip install open_mafia_engine[recommended]
This gives you the ability to run everything, and even create your own
abilities, factions, game types, etc.
Running a simple game in the console
The Engine comes with a built-in "playground" where users can become familiar
with how the Engine works. You can run it from the command line (it's a console
application):
1
mafia-cli
You can enter help for a short introduction and command overview.
importopen_mafia_engine.apiasmafia@mafia.game_builder("my_example")defmake_example_game(player_names:List[str])->mafia.Game:# Create the game object and some core helper objectsgame=mafia.Game()mafia.GameEnder(game)tally=mafia.LynchTally(game)# Create the main factionst=mafia.Faction(game,"Town")mafia.OCLastFactionStanding(game,t)m=mafia.Faction(game,"Mafia")mafia.OCLastFactionStanding(game,m)mafia.FactionChatCreatorAux(game,m)# Create the Town playera0=mafia.Actor(game,player_names[0])t.add_actor(a0)# They can only votevote=mafia.VoteAbility(game,a0,name="Vote",tally=tally)mafia.PhaseConstraint(game,vote,phase="day")# Create the Mafia playera1=mafia.Actor(game,player_names[1])m.add_actor(a1)# They can vote...vote=mafia.VoteAbility(game,a1,name="Vote",tally=tally)mafia.PhaseConstraint(game,vote,phase="day")# ... and perform the Mafia kill (which has a lot of constraints)mk=mafia.KillAbility(game,a1,name="Mafia Kill",desc="Kill the target. Only 1 mafioso can use this.",)mafia.LimitPerPhaseActorConstraint(game,mk,limit=1)mafia.LimitPerPhaseKeyConstraint(game,mk,key="mafia_kill_limit")mafia.PhaseConstraint(game,mk,phase="night")mafia.ConstraintNoSelfFactionTarget(game,mk)returngame