1
1
mirror of https://github.com/ProvableHQ/leo.git synced 2024-12-22 17:51:39 +03:00
leo/examples/tictactoe/README.md

83 lines
1.9 KiB
Markdown
Raw Normal View History

<!-- # ⭕ Tic-Tac-Toe -->
[//]: # (<img alt="workshop/tictactoe" width="1412" src="../.resources/tictactoe.png">)
2022-08-05 01:08:05 +03:00
A standard game of Tic-Tac-Toe in Leo.
⭕ ❕ ⭕ ❕ ❌
⭕ ❕ ⁣❌ ❕ ⭕
❌ ❕ ❌ ❕ ⭕
2022-08-05 01:08:05 +03:00
2022-09-20 21:52:21 +03:00
## Representing State
2022-09-30 20:37:29 +03:00
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 `Row`s.
2022-09-20 21:52:21 +03:00
An alternative representation would be to use an array, however, these are not yet supported in Leo.
## Language Features
2022-09-30 20:37:29 +03:00
- `struct` declarations
2022-09-20 21:52:21 +03:00
- 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.
Users may either specify input values via the command line or provide an input file in `inputs/`.
### Providing inputs via the command line.
1. Run
```bash
leo run <function_name> <input_1> <input_2> ...
```
See `./run.sh` for an example.
### Using an input file.
1. Modify `inputs/tictactoe.in` with the desired inputs.
2. Run
2022-08-05 01:08:05 +03:00
```bash
2022-09-20 21:52:21 +03:00
leo run <function_name>
2022-08-05 01:08:05 +03:00
```
## Executing the Program
```bash
leo execute <function_name> <input_1> <input_2> ...
```
## Playing the Game
### 1. Create a new game board
```bash
leo run new
```
| | | |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 0 | 0 |
| 0 | 0 | 0 |
### 2. Player 1 makes a move
```bash
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
```bash
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 |