Example kalah game implementation using Micronaut and virtual-thread actors.
- When the application receives a request to create a new game, it spawns a new
GameActor— a virtual thread draining a per-game mailbox. After that, each game-related action is routed to the correspondingGameActor. - There is no persistence. Unknown game ids return
404; a failed message returns its error to the caller without killing the actor or losing game state (per-message error isolation, replacing the old supervisor's restart-with-a-fresh-board behavior). - Game rules are implemented as a plain Java chain of responsibility under the
com.serdarormanli.kalah.rulespackage. - Default number of pits per player and number of stones per pit is configurable. They can be overridden in
application.yaml. - Rest api served at
localhost:8080/kalahby default. - Rest api has 3 resources.
/kalah POSTcreates new game returns board. TakesnumberOfPitsPerPlayerandnumberOfStonesPerPitas optional query parameters./kalah/{gameId} GETreturns latest snapshot of game./kalah/{gameId}/indexOfPit/{indexOfPit} POSTpicks stones and distributes. Returns latest snapshot of the game.- There is a basic frontend served at
localhost:8080by default. - Registered games are never evicted — each holds one parked virtual thread plus a small
Gameobject, which is cheap but unbounded; a long-running instance will accumulate memory for every game ever created.
- Java 25
- Virtual threads — actor-per-game with mailboxes
- Micronaut