BoardGameBot Engine
An engine for asynchronous, turn-based board games played through Discord.
It has no Django, Discord or web dependency.
Features
- A game contract for setup, actions, transitions, rendering, scoring and rules upgrades.
- Turn-based play with pending choices and out-of-turn reactions.
- Public, hidden and per-seat private state.
- Deterministic seeded replay.
- Cards, zones, counters and turn order.
- An abstract base game (
AbstractGame, RulesPack, deck/flow/prompt/reaction/view services) that provides the generic loops.
- Named handler registries and event dispatch for game-specific abilities.
- Grid boards, including hex and polygon cells with edge paths.
- Graph boards.
- Installable game plugins.
- Card, Grid and Graph reference games.
Install
pip install bgb-engine
Use
from bgb_engine import GameDefinition, RenderModel
The reference games live in bgb_engine.examples:
from bgb_engine.examples import (CardSampleGame, GraphSampleGame,
GridSampleGame)
They are also installed as plugins for BoardGameBot through the
boardgamebot.games entry-point group.
Handler registries
HandlerRegistry and EventDispatcher are optional building blocks for games
with named abilities or reactions:
from bgb_engine import EventDispatcher, HandlerRegistry
actions = HandlerRegistry('action')
actions.register('build', build_handler)
actions.register('trade', trade_handler)
reactions = HandlerRegistry('reaction')
reactions.register('counter', counter_handler, events=('attack',))
EventDispatcher(reactions).dispatch('attack', 'handle', game, context)
The engine does not define what a handler looks like; a game supplies its own
handler protocol and keeps the rule-specific behavior in the game package.
Write a game
Satisfy the GameDefinition protocol and declare an entry point in your
package:
[project.entry-points."boardgamebot.games"]
my-game = "my_game:MyGame"
The entry point may return a definition instance, a class with a zero-argument
constructor, or a zero-argument factory. The host validates the result and
refuses duplicate slugs.
A non-active seat may act only while it holds an open pending choice. Return
that seat's legal actions from legal_actions and open the choice with a
PendingSpec in a transition. While a choice is open, the host treats only its
seat as needed for board replacement, pings and private panels; otherwise the
active seat is needed.
Abstract base game
AbstractGame implements the contract and owns the generic loops, so a game
only supplies data and the rules that are genuinely its own. It is abstract:
build_setup is required, and the other hooks have defaults.
A game subclasses it, supplies a RulesPack (a data/ directory with a
rules.json manifest) or inline config, registers handler functions, and
overrides the hooks it needs (active_actions, apply_active, board_view,
seat_counters, status, is_over, scores):
from bgb_engine import AbstractGame
class MyGame(AbstractGame):
slug = 'my-game'
name = 'My Game'
phases = ('play', 'finished')
initial_phase_name = 'play'
def build_setup(self, options, seats, seed):
...
The framework provides DeckManager (seeded draw, reshuffle and hand limits),
FlowController (phases, seat rotation and the match_over outbox),
PromptManager (pending choices), ReactionEngine (reaction windows) and
ViewBuilder (seat, counter and pending views). The reference games are the
worked examples.
RulesPack is the default data loader: a data/ directory with a rules.json
manifest (players, phases, decks, abilities, board, scoring,
config). AbstractGame calls load_data() so a game can build typed objects
or registries from the pack; a game may also read files itself and ignore the
pack.
Reference games
CardSampleGame: card hands, hidden state, counters and pending choices.
GridSampleGame: a grid board with hidden cells and scoring.
GraphSampleGame: a graph board with paths, tokens and a finish condition.
The rules for the reference games are in the main project documentation. A
complete authoring guide is in the repository at docs/writing-a-game.md.
License
BoardGameBot Engine is released under the MIT License.