A Tic-tac-toe sandbox to experiment with Alex Wissner-Gross's causal-entropic intelligence equation.
In this application, the causal-entropy player treats each legal Tic-tac-toe move as a step into a future game tree.
As defined by
...Basicaly, the agent that avoids loosing, lives longer, than the agent that tries to win.
...There may be some philisophical value in that observation somewhere.
- ✅ Requirements
- ⚙️ Setup
▶️ Running- 🧩 Configuration
- 🧮 Mathematical Overview
- 🎮 Tic-tac-toe - Mathematical Definition
- 🗂️ Project Layout
⚠️ Experiment Limitations- 📜 License
- Python 3.12 or newer
- A UTF-8 terminal for Unicode boards; other encodings receive an ASCII fallback
Create a virtual environment, then install the dependencies.
python -m venv .venv
.\.venv\Scripts\python.exe -m pip install -r requirements.txtpython3 -m venv .venv
./.venv/bin/python -m pip install -r requirements.txtpy -3.12 -m venv .venv
./.venv/Scripts/python.exe -m pip install -r requirements.txtUse requirements-dev.txt only when you want the optional local test dependencies.
From the project directory, display the available command-line options:
-
Windows
.\run.bat --help
-
Linux
./run.sh --help
Run the example causal-entropy match:
-
Windows
.\run.bat config\example.yaml -
Linux
./run.sh config/example.yaml
Run a causal-entropy versus minimax experiment with candidate-score diagnostics:
-
Windows
.\run.bat config\experiments\causal-entropy-x-minimax-o.yaml
-
Linux
./run.sh config/experiments/causal-entropy-x-minimax-o.yaml
The selected YAML profiles determine whether a match is human-human, human-computer, or computer-computer. Human
turns accept coordinates from a1 through c3; malformed and occupied coordinates are explained and re-prompted.
Each YAML file defines an x.y version number, optional application settings, reusable player profiles, one selected
match, and presentation settings. An integer application.random_seed makes random strategy choices and random tie-breaks
repeatable; omit it or set it to null for fresh random initialization on each run.
| Match profiles | Play mode |
|---|---|
| Human + human | Human versus human |
| Human + computer | Human versus computer |
| Computer + computer | Computer versus computer |
Player 1 is always X and moves first. Computer profiles select one of these strategies:
| Strategy | Behavior |
|---|---|
random |
Uniform choice from legal actions |
tactical |
Win, block, center, corner, then edge |
minimax |
Complete optimal search using terminal utility |
causal_entropy |
Maximizes future-history entropy without utility or tactical bonuses |
The included files under config/ show the supported profile, match, and presentation settings.
Wissner-Gross's causal-entropic force,
says that a system is driven toward states with greater future path entropy. Tic-tac-toe is discrete, so the application replaces the smooth gradient with an action-wise finite difference over legal moves.
Let
For a configured horizon
The path entropy used by the application is the natural logarithm of that count:
Each candidate move is scored by the discrete analogue of
where temperature parameter. Since
The strategy intentionally does not add win/loss utility, tactical rules, or an opponent model. Wins, losses, and draws affect the score only by ending the future-history count. This makes the causal-entropy player a direct test of future optionality inside the Tic-tac-toe game defined below.
Tic-tac-toe is modeled as a finite, deterministic, two-player, turn-based, zero-sum game of perfect information:
where
Let the row and column sets be:
The set of board cells is:
The marks are:
The empty cell symbol is
The set of players is:
Each player is identified with their mark. Player
A board is a function:
The raw board space is:
Since
For a board
Because
or:
Equivalently:
The set of winning lines is:
For a player
A board is full if no cell is empty:
Equivalently:
A board is terminal if either player has won or the board is full:
The initial state
The legal state space is the smallest set
-
$s_0 \in S$ . - If
$s \in S$ ,$s$ is non-terminal, and$a \in A(s)$ , then$T(s,a) \in S$ . - If
$Z(s)$ , then$A(s) = \varnothing$ .
This recursive definition excludes boards that satisfy simple count constraints but could not arise during actual game play.
For non-terminal states, the player-to-move function is:
The function
An action is the selection of an empty board cell:
The legal action set is the set of empty cells:
For terminal states, no actions are legal:
For a state
The transition function is only defined when
The outcome function is:
with:
The utility functions are:
For player
For player
For terminal states, Tic-tac-toe is zero-sum:
A history is a finite legal action sequence:
The induced state
A pure strategy for player
where:
and:
For player
with:
for terminal states, and:
Similarly,
so optimal play results in a draw.
| Path | Responsibility |
|---|---|
domain/ |
Immutable board, state, outcomes, coordinates, and authoritative game rules |
players/ |
Human and computer player abstractions |
intelligence/ |
Interchangeable computer strategies |
presentation/ |
Terminal rendering and interaction |
config/ |
Example and experiment YAML configurations |
docs/ |
Architecture notes, experiment baseline, and mathematical models |
main.py |
Minimal executable entry point |
run.bat, run.sh |
Windows and Linux terminal launchers |
application.py |
Application composition and lifecycle |
configuration.py |
Typed YAML loading and aggregated validation |
errors.py |
Shared application exception types |
- Each example result is one seeded game, not a statistical comparison.
- In matches with random strategies or random tie-breakers, role assignment affects how the shared seeded random stream is consumed.
- Execution times are machine-specific and are not acceptance thresholds.
- The causal-entropy strategy intentionally ignores wins, losses, and opponent quality except through future path counts.
- Tic-tac-toe is a small demonstration domain; these results do not establish a general measure of intelligence.
Released under the MIT License — Copyright © 2022 Rohin Gosling.
