Checkers with the events plugin
Alice and Bob share a checkers board. A confirmed move must survive a restart, but a hand cursor only matters while someone watches it. Turn notifications and animation cues help the other player follow the game. The board remains the authority when a player misses a cue.
This tutorial connects those behaviors in one program, with a version for each high-level binding. Each step adds a different event exchange to the same game. Start with the quickstart if you have not opened a database or run a stored mutation.
Read the Go example, Rust example, Clojure example, Odin example or Python example. The next step also has language and document-format selectors.
The board
Starting position
Squares are the 32 playable dark squares, numbered 0–31 from top to bottom and left to right. Red moves toward larger square numbers. Black moves toward smaller numbers. No piece is a king in this position.
The game data starts with this board:
{:#_table {:game "checkers"
:revision 0
:turn "red"
:pieces {:red7 {:color "red"
:square 11
:king false}
:red2 {:color "red"
:square 16
:king false}
:red3 {:color "red"
:square 8
:king false}
:black1 {:color "black"
:square 20
:king false}}}}Red plays 11 → 15. Black then jumps 20 → 13 → 4, capturing red2 on 16 and red3 on 8. Each turn advances the board revision once. Pieces are a map keyed by piece ID, while a jump path is an ordered sequence.
The checkers/board query reads the current board. Both mutations check the expected revision, turn and complete position before they write. A rejected or repeated turn leaves the board unchanged.
Load the plugins
Follow Use a release to configure your binding, library and license. Keep the extracted release directory layout.
Open the database with both events and sdk enabled:
async def open_checkers(path, sdk_directory):
return await sd.open(path, plugins={
"events": {},
"sdk": {
"python": {"dir": sdk_directory},
"debounce": timedelta(milliseconds=250),
"maxWait": timedelta(seconds=2),
},
})Pass the database path and a dedicated SDK output directory to this function.
A relative directory is relative to the process working directory.
The SDK plugin replaces the output directory's contents. Keep your application source and database elsewhere.
It writes typed APIs automatically at open and after stored queries, mutations or event schemas change.
The debounce setting groups changes after 250 milliseconds without another definition commit.
The maxWait setting limits this scheduling delay to two seconds after the first change.
See the SDK reference for generation status and package imports.
The release includes generated SDK sources for these stored definitions. Each example imports those sources and uses their typed publishing, subscription, caller and worker helpers. Its database and SDK output use temporary directories that it removes when it ends. For your application, choose persistent paths. Generate the SDK after installing your definitions, then import its package in your application.
Follow the game
| Step | Behavior | What stays in the database |
|---|---|---|
| Pub/sub | Share hand cursors and announce turns | No cursor or notification messages |
| Request | Submit one move and receive one result | The accepted move and new turn |
| Pull | Receive legal landings as a stream | No exchange messages |
| Push | Submit the ordered jumps of one turn | The complete accepted turn |
| Duplex | Exchange drag positions and move previews | No draft positions |
The example starts in the middle of a game and checks two specific turns. Its game data contains legal candidates and stored mutations for those positions. This keeps the code focused on event coordination. A complete game would replace those definitions with its checkers rules.
Alice, Bob and the rules worker run inside one process and share one open database. The program seeds the board and stores definitions before creating their owners. An owner groups temporary coordination resources for cleanup. The example alternates their operations so you can see both ends of each exchange. A browser client would need an application transport to reach this process.
Files in the release
After extracting the release, use these paths relative to its root:
- Program:
abi/examples/checkers/python/checkers.py - Generated SDK:
abi/examples/checkers/python/gen - Game data:
abi/examples/checkers/checkers.dust
The game data file supplies the starting board, legal-move candidates, stored queries, mutations, event schemas and expected final board. The program reads it to prepare and verify the example.
Run the example
Run from the extracted release root in a POSIX shell. These commands read the DUST game data included in the release. The page format selector changes the displayed values. The program checks each exchange and prints the final board in DUST.
python3 abi/examples/checkers/python/checkers.py abi/examples/checkers/checkers.dust dustShare hand cursors to begin the exchanges.