Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: about 10 hours 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 (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-11-26T20:33:27.000Z (27 days ago)
- Last Synced: 2024-11-26T21:24:57.181Z (27 days ago)
- Topics: lit, rxjs, xstate
- Language: JavaScript
- Homepage: https://customcommander.github.io/agricola/
- Size: 497 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/badges/StandWithUkraine.svg)](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 notesetup --> setup : SETUP_GAME
setup --> work : SETUP_DONEnote left of work
Keep working until we reach
the end of a stage (i.e. harvest time)
end notework --> after_work : WORK_DONE
after_work --> work : not_harvest
after_work --> harvestharvest --> 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/