Skip to content

Commit 0c2aa4a

Browse files
Merge pull request #28 from open-mafia/docs/update-to-050
Made CLI and updated Docs & lots of smaller fixes
2 parents 947b2d1 + 4670e2a commit 0c2aa4a

31 files changed

+921
-501
lines changed

README.md

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Open Mafia Engine
22

3-
[![PyPI version](https://badge.fury.io/py/open-mafia-engine.svg)](https://badge.fury.io/py/open-mafia-engine) [![Test Python package "open_mafia_engine"](https://github.com/open-mafia/open_mafia_engine/actions/workflows/python-testing.yml/badge.svg)](https://github.com/open-mafia/open_mafia_engine/actions/workflows/python-testing.yml)
3+
[![PyPI version](https://badge.fury.io/py/open-mafia-engine.svg)](https://badge.fury.io/py/open-mafia-engine)
4+
[![Stable Release](https://img.shields.io/github/release/open-mafia/open_mafia_engine.svg)](https://github.com/open-mafia/open_mafia_engine/releases)
5+
[![Docs](https://readthedocs.org/projects/open-mafia-engine/badge/?version=latest)](https://open-mafia-engine.readthedocs.io/en/latest/)
6+
7+
[![Test Python package "open_mafia_engine"](https://github.com/open-mafia/open_mafia_engine/actions/workflows/python-testing.yml/badge.svg)](https://github.com/open-mafia/open_mafia_engine/actions/workflows/python-testing.yml)
48

59
The Open Mafia Engine is a flexible, open-source game engine for Mafia-like games.
610

@@ -17,15 +21,15 @@ from either "real-life" games or online forums such as
1721

1822
- Event-based architecture, which allows for very complex interactions.
1923
- Many built-in abilities, victory conditions, etc.
20-
(This is a lie, but we're working on it!)
24+
(Not "many" yet, but we're working on it!)
2125
- Games are defined declaratively or using an parametrized GameBuilder.
22-
- Open source & extensible, with a plugin system in the works.
26+
- Open source & extensible.
2327

2428
## Installing
2529

26-
Install the latest stable version via pip:
30+
Install the latest stable version, with recommended dependencies, via pip:
2731

28-
`pip install open_mafia_engine`
32+
`pip install open_mafia_engine[recommended]`
2933

3034
See the [dev docs](docs/development/installing_dev.md) to install for local
3135
development (using Poetry).
@@ -42,7 +46,16 @@ players = ['Alice', 'Bob', 'Charlie', 'Dave', 'Eddie']
4246
game = builder.build(players)
4347
```
4448

45-
Actually running commands in the engine is pretty complicated for now.
46-
We're working to improve the experience.
49+
## Example Application
50+
51+
This repository includes an example text-based Mafia app, runnable like:
52+
53+
```bash
54+
mafia-cli
55+
# or
56+
python -m open_mafia_engine.example.cli
57+
```
58+
59+
This is what the UI looks like:
4760

48-
See `playground.py` in the repository for an example game.
61+
![Example CLI Application](docs/examples/ExampleMafiaCLI.gif)

docs/about.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,10 @@ If you would like to help, please contant us directly on GitHub or at
1616
The [open_mafia_discord_bot](https://github.com/open-mafia/open_mafia_discord_bot)
1717
is a reference implementation of bot functionality for [Discord](https://discord.com/).
1818
Note that the library is currently private, until sufficiently developed.
19+
20+
The [Bay12 Mafia bot](https://github.com/open-mafia/bay12_mafia) is another
21+
project that runs the mafia via forum posts and private messages inside
22+
Bay12Forums (which runs as a Simple Machines Forum).
23+
24+
It is also being developed in private, mostly to avoid potential misuse of its
25+
posting/PM-sending capabilities.

docs/examples/ExampleMafiaCLI.gif

334 KB
Loading

docs/examples/index.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Examples
2+
3+
Developing from scratch is difficult, which is why `open_mafia_engine` has
4+
several built-in examples to help you get started and/or debug your custom
5+
game objects.
6+
7+
## Console Application
8+
9+
The Mafia Console App is a full-screen console application written using the
10+
`open_mafia_engine` and `prompt_toolkit`.
11+
12+
To be able to run it, make sure you installed `open_mafia_engine` with at least
13+
the `examples` extra:
14+
15+
```bash
16+
pip install open_mafia_engine[examples]
17+
# or, if developing locally:
18+
poetry install -E examples
19+
```
20+
21+
This is what it looks like:
22+
23+
![Example CLI Application](ExampleMafiaCLI.gif)
24+
25+
The left panel shows the current state, both when in a lobby and when in an
26+
actual game. The right panel shows the command history. The input is at the
27+
bottom, and it has some auto-completion and highlighting.
28+
29+
To get started, run the app:
30+
31+
```bash
32+
mafia-cli
33+
# or
34+
python -m open_mafia_engine.example.cli
35+
```
36+
37+
This will give you an empty prompt. To view some basic commands, enter `help`.
38+
The application runs like a command shell, using the syntax:
39+
40+
```bash
41+
USER COMMAND arguments
42+
```
43+
44+
The most useful commands are `NAME join`/`NAME in` (to add a player),
45+
`admin create-game test` to start a test game, `admin phase` to change the phase
46+
(note that the initial phase is always "startup" - make sure to phase to start
47+
the game in earnest), `NAME vote TARGET` to perform vote actions (during the day)
48+
and `NAME do ABILITY ARGS...` to activate abilities during the proper phase.
49+
50+
**TODO**: Explain how the application works.
51+
52+
The console app is useful not only for understanding how the Engine works, but it
53+
also lets you test your own custom roles in an interactive environment.
54+
55+
## Tests
56+
57+
Another good resource for learning how the Open Mafia Engine works are the
58+
[unit tests](https://github.com/open-mafia/open_mafia_engine/tree/master/open_mafia_engine/test),
59+
(especially the `test_scenarios.py`) which go through the lower-level events.
60+
61+
## Discord Bot
62+
63+
The [Open Mafia Discord Bot](https://github.com/open-mafia/open_mafia_discord_bot)
64+
is currently under development and will be released when it's up-to-date with
65+
this version of the library.

docs/getting_started/quickstart.md

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# Quickstart
2+
3+
## Installing
4+
5+
Install the Open Mafia Engine package from PyPI, with recommended extras:
6+
7+
```sh
8+
pip install open_mafia_engine[recommended]
9+
```
10+
11+
This gives you the ability to run everything, and even create your own
12+
abilities, factions, game types, etc.
13+
14+
## Running a simple game in the console
15+
16+
The Engine comes with a built-in "playground" where users can become familiar
17+
with how the Engine works. You can run it from the command line (it's a console
18+
application):
19+
20+
```sh
21+
mafia-cli
22+
```
23+
24+
You can enter `help` for a short introduction and command overview.
25+
26+
See the [Examples](../examples/index.md) or [Command Reference](../reference/commands.md)
27+
for more information on how this app works.
28+
29+
## Creating your own game
30+
31+
The most important part of the Open Mafia Engine is that you can create your own
32+
custom game, with different roles, factions, rule sets and so on.
33+
34+
To create a game with pre-existing roles, just make a
35+
[game builder function][open_mafia_engine.core.builder.game_builder]
36+
that takes player names (and maybe some other options).
37+
38+
```python
39+
import open_mafia_engine.api as mafia
40+
41+
@mafia.game_builder("my_example")
42+
def make_example_game(player_names: List[str]) -> mafia.Game:
43+
# Create the game object and some core helper objects
44+
game = mafia.Game()
45+
mafia.GameEnder(game)
46+
tally = mafia.LynchTally(game)
47+
48+
# Create the main factions
49+
t = mafia.Faction(game, "Town")
50+
mafia.OCLastFactionStanding(game, t)
51+
52+
m = mafia.Faction(game, "Mafia")
53+
mafia.OCLastFactionStanding(game, m)
54+
mafia.FactionChatCreatorAux(game, m)
55+
56+
57+
# Create the Town player
58+
a0 = mafia.Actor(game, player_names[0])
59+
t.add_actor(a0)
60+
# They can only vote
61+
vote = mafia.VoteAbility(game, a0, name="Vote", tally=tally)
62+
mafia.PhaseConstraint(game, vote, phase="day")
63+
64+
65+
# Create the Mafia player
66+
a1 = mafia.Actor(game, player_names[1])
67+
m.add_actor(a1)
68+
# They can vote...
69+
vote = mafia.VoteAbility(game, a1, name="Vote", tally=tally)
70+
mafia.PhaseConstraint(game, vote, phase="day")
71+
# ... and perform the Mafia kill (which has a lot of constraints)
72+
mk = mafia.KillAbility(
73+
game,
74+
a1,
75+
name="Mafia Kill",
76+
desc="Kill the target. Only 1 mafioso can use this.",
77+
)
78+
mafia.LimitPerPhaseActorConstraint(game, mk, limit=1)
79+
mafia.LimitPerPhaseKeyConstraint(game, mk, key="mafia_kill_limit")
80+
mafia.PhaseConstraint(game, mk, phase="night")
81+
mafia.ConstraintNoSelfFactionTarget(game, mk)
82+
83+
return game
84+
```
85+
86+
Then you can create the game object:
87+
88+
```python
89+
game = make_example_game(["Alice", "Bob"])
90+
```
91+
92+
Or, if saved in a model and imported:
93+
94+
```python
95+
builder = mafia.GameBuilder.load("my_example")
96+
game = builder.build(["Alice", "Bob"])
97+
```
98+
99+
Technically, you could do this outside a function, but functions are much
100+
more reusable. 😃
101+
102+
## Running your game in the console app
103+
104+
NOTE: This extra parameter doesn't work yet.
105+
106+
Assuming you have registered your function with the game builder, the Console
107+
Application can load your Python module:
108+
109+
```sh
110+
mafia-cli --import your_module.py
111+
```
112+
113+
And you can load it inside the console app by the name you gave it:
114+
115+
```sh
116+
admin create-game my_example
117+
```

docs/index.md

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Open Mafia Engine
22

3-
[![PyPI version](https://badge.fury.io/py/open-mafia-engine.svg)](https://badge.fury.io/py/open-mafia-engine) [![Test Python package "open_mafia_engine"](https://github.com/open-mafia/open_mafia_engine/actions/workflows/python-testing.yml/badge.svg)](https://github.com/open-mafia/open_mafia_engine/actions/workflows/python-testing.yml)
3+
[![PyPI version](https://badge.fury.io/py/open-mafia-engine.svg)](https://badge.fury.io/py/open-mafia-engine)
4+
[![Stable Release](https://img.shields.io/github/release/open-mafia/open_mafia_engine.svg)](https://github.com/open-mafia/open_mafia_engine/releases)
5+
[![Docs](https://readthedocs.org/projects/open-mafia-engine/badge/?version=latest)](https://open-mafia-engine.readthedocs.io/en/latest/)
6+
7+
[![Test Python package "open_mafia_engine"](https://github.com/open-mafia/open_mafia_engine/actions/workflows/python-testing.yml/badge.svg)](https://github.com/open-mafia/open_mafia_engine/actions/workflows/python-testing.yml)
48

59
The Open Mafia Engine is a flexible, open-source game engine for Mafia-like games.
610

@@ -17,15 +21,15 @@ from either "real-life" games or online forums such as
1721

1822
- Event-based architecture, which allows for very complex interactions.
1923
- Many built-in abilities, victory conditions, etc.
20-
(This is a lie, but we're working on it!)
24+
(Not "many" yet, but we're working on it!)
2125
- Games are defined declaratively or using an parametrized GameBuilder.
22-
- Open source & extensible, with a plugin system in the works.
26+
- Open source & extensible.
2327

2428
## Installing
2529

26-
Install the latest stable version via pip:
30+
Install the latest stable version, with recommended dependencies, via pip:
2731

28-
`pip install open_mafia_engine`
32+
`pip install open_mafia_engine[recommended]`
2933

3034
See the [dev docs](development/installing_dev.md) to install for local
3135
development (using Poetry).
@@ -42,7 +46,16 @@ players = ['Alice', 'Bob', 'Charlie', 'Dave', 'Eddie']
4246
game = builder.build(players)
4347
```
4448

45-
Actually running commands in the engine is pretty complicated for now.
46-
We're working to improve the experience.
49+
## Example Application
50+
51+
This repository includes an example text-based Mafia app, runnable like:
52+
53+
```bash
54+
mafia-cli
55+
# or
56+
python -m open_mafia_engine.example.cli
57+
```
58+
59+
This is what the UI looks like:
4760

48-
See `playground.py` in the repository for an example game.
61+
![Example CLI Application](examples/ExampleMafiaCLI.gif)

docs/reference/builders.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# Game Builders
22

3+
This is the code reference for the Game Builder API and classes.
4+
5+
::: open_mafia_engine.core.builder
6+
37
::: open_mafia_engine.builders.for_testing
4-
handler: python
5-
rendering:
6-
heading_level: 2
7-
show_source: false
8-
# show_root_heading: false

docs/reference/built_in.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Built-In Classes
2+
3+
This is the code reference for the built-in, but non-core classes.
4+
5+
::: open_mafia_engine.built_in.auxiliary
6+
7+
::: open_mafia_engine.built_in.constraints
8+
9+
::: open_mafia_engine.built_in.information
10+
11+
::: open_mafia_engine.built_in.kills
12+
13+
::: open_mafia_engine.built_in.lynch_tally
14+
15+
::: open_mafia_engine.built_in.notify
16+
17+
::: open_mafia_engine.built_in.outcome
18+
19+
::: open_mafia_engine.built_in.phases
20+
21+
::: open_mafia_engine.built_in.protect
22+
23+
::: open_mafia_engine.built_in.redirect
24+
25+
::: open_mafia_engine.built_in.roleblock
26+
27+
::: open_mafia_engine.built_in.startup
28+
29+
::: open_mafia_engine.built_in.triggers
30+
31+
::: open_mafia_engine.built_in.voting

docs/reference/builtin.md

Lines changed: 0 additions & 8 deletions
This file was deleted.

docs/reference/commands.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
# Command Interface
22

3+
This is the code reference for the Command system interface.
4+
5+
::: open_mafia_engine.commands.raw
6+
7+
::: open_mafia_engine.commands.lobby
8+
9+
::: open_mafia_engine.commands.parser
10+
311
::: open_mafia_engine.commands.runner
4-
handler: python
5-
rendering:
6-
heading_level: 2
7-
show_source: false
8-
# show_root_heading: false
12+
13+
<!-- ::: open_mafia_engine.commands.cli_lexer -->

0 commit comments

Comments
 (0)