https://github.com/jdan/combinatorial-games
An exploration of evaluating the results of games without chance (Nim, Tic-Tac-Toe) under perfect play.
https://github.com/jdan/combinatorial-games
Last synced: 3 months ago
JSON representation
An exploration of evaluating the results of games without chance (Nim, Tic-Tac-Toe) under perfect play.
- Host: GitHub
- URL: https://github.com/jdan/combinatorial-games
- Owner: jdan
- Created: 2021-07-18T17:45:39.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2021-07-19T16:54:41.000Z (almost 5 years ago)
- Last Synced: 2025-01-01T02:41:37.677Z (over 1 year ago)
- Language: OCaml
- Homepage:
- Size: 15.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## combinatorial-games
An exploration of evaluating the results of [games without chance](https://en.wikipedia.org/wiki/Combinatorial_game_theory) under perfect play. [game.ml](/lib/game.ml) contains all the code.
Inspired by [Jordan Ellenberg's novel, Shape](https://amzn.to/3yKptm0) (Chapter 5: _"His Style Was Invincibility"_)
### example
```ocaml
let%test_module _ = (module struct
module M = CombinatorialGameEvaluator(TicTacToe)
let%test "An empty board is a Draw" =
Draw = M.eval { xs_turn = true;
board = (Empty, Empty, Empty,
Empty, Empty, Empty,
Empty, Empty, Empty)
}
let%test "O can force a draw even if X plays correctly" =
Draw = M.eval { xs_turn = false;
board = (X, Empty, Empty,
Empty, Empty, Empty,
Empty, Empty, Empty)
}
let%test "O playing top-right is a fatal error" =
Win = M.eval { xs_turn = true;
board = (X, Empty, O,
Empty, Empty, Empty,
Empty, Empty, Empty)
}
end)
```
### running
tests
```
$ dune runtest
```
main executable (show a game of [Hare and Hounds](https://en.wikipedia.org/wiki/Hare_games#Hare_and_Hounds))
```
$ dune exec bin/main.exe
```