The root chit instance of the game. All chits in the game have this chit somewhere in its hierarchy
Generates a random number from 0 to 1. This number will persisted in state and will be consistent if the turn needs to be re-run. Drawing a random number prevents normal resets.
If the player can perform a reset, this will confirm with them first.
A number from 0-1
Generates a series of random numbers from 0 to 1. This is a helper method to help batch up a lot of random draws since each rng() call must be awaited.
A parameterless function that will return the next random number in the list. If you try to select too many random numbers, that method will throw.
Add a game log message to the last flush step
Append a game log message to the last flush step that has a game log message
Scan all of the chits managed by this turn. If any of them have changed, group them together into a "ClockStep". If any new chits appear, then add them to our lookup. If any chits are deleted (orphaned), then we have to identify those as well.
Creates a sub-turn. This is useful for a few reasons:
It takes an async function which it will execute. For simplicity, the result of that function will be the result of this function.
It is okay to have multiple turns going at once, but there are some rules:
The chits to lock. These are the only chits that will be allowed to be modified by this turn. If there are never any concurrent turns, this can safely be the root chit (although there maybe minor performance implications)
The player who will be prompted for choices during this turn.
The async function that will be the logic of this turn. The function takes a new turn instance
Whatever the final result of cb() is
If a player has gotten themselves into a corner - i.e. no valid moves - this prompt will simply inform them of that and allow them to undo.
Optionalmessage: stringOptionalhelp: stringMore complex selection prompt. Useful in Typescript when you want to handle a response to multiple types of chits. This will allow a different typed callback per set of chits. This also allows the insertion of "buttons"
A
Turnis the heart of pretty-chitty. It represents multiple actions or sequences of events from a single player (or possibly not player).The core of a
Turnis the asyncfnprovided. Thisfnwill run all of this logic for that turn, prompt the user for actions, take random number draws and possibly create one or more sub-turns.The general pattern will look something like this:
There are a couple of VERY important details here: