leo/examples/tictactoe
Pranav Gaddamadugu f22177e2c5 Set defaults
2024-07-08 09:30:10 -07:00
..
build WIP 2024-05-18 16:43:53 -07:00
inputs Update examples 2024-01-15 15:45:09 -08:00
src fix: correct typos for win check 2024-03-31 21:47:58 +02:00
.env Set defaults 2024-07-08 09:30:10 -07:00
.gitignore [Feature] Implement leo execute (#2491) 2023-07-19 18:04:09 -07:00
leo.lock make example compatible w/ stubs 2023-12-11 13:19:42 -08:00
program.json [Feature] Implement leo execute (#2491) 2023-07-19 18:04:09 -07:00
README.md WIP removing input files from examples 2024-01-15 15:45:07 -08:00
run.sh Update leo examples (#2501) 2023-07-24 10:33:41 -07:00

A standard game of Tic-Tac-Toe in Leo.

Representing State

Leo allows users to define composite data types with the struct keyword. The game board is represented by a struct called Board, which contains three Rows. An alternative representation would be to use an array, however, these are not yet supported in Leo.

Language Features

  • struct declarations
  • conditional statements
  • early termination. Leo allows users to return from a function early using the return keyword.

Running the Program

Leo provides users with a command line interface for compiling and running Leo programs.

Providing inputs via the command line.

leo run <function_name> <input_1> <input_2> ...

See ./run.sh for an example.

Executing the Program

leo execute <function_name> <input_1> <input_2> ...

Playing the Game

1. Create a new game board

leo run new
0 0 0
0 0 0
0 0 0

2. Player 1 makes a move

leo run make_move 1u8 1u8 1u8 "{ r1: { c1: 0u8, c2: 0u8, c3: 0u8 }, r2: { c1: 0u8, c2: 0u8, c3: 0u8 }, r3: { c1: 0u8, c2: 0u8, c3: 0u8 } }"
1 0 0
0 0 0
0 0 0

3. Player 2 makes a move

leo run make_move 2u8 2u8 2u8 "{ r1: { c1: 1u8, c2: 0u8, c3: 0u8 }, r2: { c1: 0u8, c2: 0u8, c3: 0u8 }, r3: { c1: 0u8, c2: 0u8, c3: 0u8 } }"
1 0 0
0 2 0
0 0 0