Simple, fast console Tic Tac Toe in Python, with optional AI (random or perfect play) and a tiny Tkinter UI.
- Python 3.8+ (Windows/macOS/Linux)
- Tkinter (usually included with Python on Windows/macOS)
- Human vs Human:
python tic_tac_toe.py
- Human vs Computer (AI as O):
python tic_tac_toe.py --ai O
- Computer difficulty:
# random or minimax (perfect). Default: minimax python tic_tac_toe.py --ai O --ai-level random
Controls: enter moves as row,col
with values 1–3 (example: 2,3
). Type q
to quit.
Run a simple windowed version:
python ui_tk.py # Human vs Human
python ui_tk.py --ai O # Human (X) vs Computer (O)
python ui_tk.py --ai X # Computer (X) vs Human (O)
python ui_tk.py --ai O --ai-level random
Run unit tests with the standard library test runner:
python -m unittest -v
- Sample CSVs are in
samples/
(random and minimax batches). - Generate a chart (requires matplotlib):
pip install -r requirements.txt python analyze_results.py --input samples/autoplay_sample_random.csv --output samples/autoplay_sample_random.png
Sample chart:
Apache License 2.0 — see LICENSE.