A python script to evaluate any position in Tic Tac Toe.
- Have a functioning Python 2.7+ version installed
- Clone this repository
- Open a terminal and cd into src
- Run python and import main (and optionally import positions)
- Run main.solve() on a position (either make your own or use one from positions.py)
Examples:
main.solve([['_', 'O', 'X'], ['_', 'X', '_'], ['O', '_', 'X']])
main.solve(positions.o_wins_1)
Use capital X, capital O, and underscores for X, O, and blanks respectively.
Always pass in a 3x3 list. X always goes first.
This code is meant to follow minimax strictly by building a full decision tree under the position.
The position is evaluated from the bottom up, assuming both X and O are perfect players.
The program deliberately does not take advantage of storing positions or checking for symmetry.
There is a performance hit as a result (opening position: ~15 seconds, 1 Move: ~2 seconds, 2+ Moves: Instant)