← All projects

Games

Tic-tac-toe

Rewrite of a game from my studies: tic-tac-toe against an unbeatable AI (minimax), in Python.

Done Sprint S22 · 3 points
In short, no jargon for non-developersRead the summaryClose
What it is
Tic-tac-toe against a computer that never loses, playable in the page.
What it is for
A game from my studies, rewritten from scratch with the methods of a professional project: automatic tests, versions for several systems.
What it shows
Programming in Python, and proof by tests that the computer cannot be beaten: every possible game was tried.
Source code

How the pieces fit together

Diagram: Rules → AI (legal moves) ; AI → Opening book (computed once) ; Opening book → Project page ; Terminal → AI ; Tests → AI (never loses). legal moves computed once never loses Rules board.py, positions AI negamax, the whole tree Opening book book.json Project page JavaScript, no Python Terminal typed Python Tests every game

Play against the AI

The AI plays the moves of the book computed by the project's Python program: the best moves of each of the 5,478 positions. At the unbeatable level, it never loses.

I play

Loading the move book…

With the keyboard: arrows move the active square, Enter or Space plays. Level and side apply to the next game.

Tech stack

  • Python
  • pytest
  • mypy

Who does what

Python
The game and the minimax AI that never loses; it also computes the move book the project page uses.
pytest
Proves the AI cannot be beaten by trying every possible game.
mypy
Checks the types in strict mode, on the code and the tests.

Definition of Done

  • Code reviewed, diff by diff
  • Unit and integration tests green
  • Green CI on Linux, Windows and macOS when compiled
  • README, REVIEW.md and DECISIONS.md up to date
  • Texts in French and English
  • Demo deployed and tested on mobile