https://github.com/customcommander/agricola
A recreational reactive programming project aiming at implementing the solo version of the popular board game. Work in progress...
https://github.com/customcommander/agricola
lit rxjs xstate
Last synced: 12 months ago
JSON representation
A recreational reactive programming project aiming at implementing the solo version of the popular board game. Work in progress...
- Host: GitHub
- URL: https://github.com/customcommander/agricola
- Owner: customcommander
- License: mit
- Created: 2022-06-25T13:19:39.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2025-01-16T22:49:05.000Z (over 1 year ago)
- Last Synced: 2025-06-30T11:06:01.626Z (12 months ago)
- Topics: lit, rxjs, xstate
- Language: JavaScript
- Homepage: https://customcommander.github.io/agricola/
- Size: 586 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://stand-with-ukraine.pp.ua)
# Agricola
A deep dive exploration of reactive programming combining state machines ([XState][]) and observables ([RxJS][]) with a web-component-based ([Lit][]) single page application. In the end I hope to build the solo version of the popular board game.
## Development
### Requirements
- Node.js v19+
### Tests
```
npm test
```
## Architecture
### Boundaries
The game engine is managed by a single state machine split into multiple services.
We can produce a diverse range of observables from the state machine. The user interface components subscribe to these observables.
Even though the user interface is not allowed to subscribe directly to the state machine, it can however trigger events that will ultimately lead to state changes and new data being emitted by the observables.
In all circumstances data flows in **one and only one** direction.
```mermaid
flowchart LR
GE(((Game Engine))) -- produces -->
O(((Observables))) -- feed -->
UI(((User Interface))) -- triggers --> GE
```
### States Machines
#### Overview
The main state machine is kept relatively simple (YMMV) as each state is expected to spawn one or more services.
```mermaid
stateDiagram-v2
state after_harvest <>
state after_work <>
[*] --> setup
note left of setup
All the things we need to do
before we can start the game.
end note
setup --> setup : SETUP_GAME
setup --> work : SETUP_DONE
note left of work
Keep working until we reach
the end of a stage (i.e. harvest time)
end note
work --> after_work : WORK_DONE
after_work --> work : not_harvest
after_work --> harvest
harvest --> after_harvest: HARVEST_DONE
after_harvest --> work : not_end_of_game
after_harvest --> end_of_game
end_of_game --> [*]
```
#### Work Service
The **Work Service** is given the number of workers for the active turn and remains active until all the workers are placed on the board.
```mermaid
stateDiagram-v2
state after_perform <>
[*] --> init
init --> select
select --> perform: TASK_SELECTED
perform --> select: TASK_CANCELLED
perform --> after_perform: TASK_DONE
after_perform --> select: workers_left
after_perform --> done
done --> [*]
```
#### Harvest Service
```mermaid
stateDiagram-v2
[*] --> init
init --> fields
fields --> feed: HARVEST_FIELDS_DONE
feed --> breed: HARVEST_FEED_DONE
breed --> done: HARVEST_BREED_DONE
done --> [*]
```
[XState]: https://xstate.js.org/
[RxJS]: https://rxjs.dev/
[Lit]: https://lit.dev/