This example models the tic tac toe game between two players. It demonstrates primarily various way of testing Either
-based state transitions. The Play
choice returns either a new Game
contract, or a Result
contract if the game is decided. The first script uses a naive testing approach, which results in a highly nested chain of case
statements. Subsequent scripts demonstrate how to simplify such kind of tests and make them more readable using binding functions.
- A player invites another player by creating a
GameInvite
. - Upon acceptance of the invite a
Game
contract is created. - Player 1 starts the game by exercising the
Play
choice, which recreates theGame
contract with the move added. - The players now take turns until the
Play
choice detects a final state (win or tie). - When the game is finished a
Result
contract is created containing the state and outcome of the game.
To compile the project:
daml build
To test all scripts:
daml test --color
To load the project into the sandbox and start navigator:
daml start