Play a game of tic-tac-toe against an AI that never loses.
Heroku puts apps to sleep if they haven't been used in a while, so it might take longer than usual to load.
I started this project for a job application. Originally it started with a CLI but when the requirements changed I converted it to a Django application. Now I'm just working on it for fun. I'm sharing it because I wanted a public code sample that's more recent than some of my other ones.
The AI will never lose. This is achieved with the following algorithm. The strategy looks at all of the boards that could result from its next move and chooses one that is acceptable. A board is acceptable if any of the following hold:
-
The strategy wins or ties on that board.
-
It's the opponent's turn and any play the opponent can make leads to an acceptable board.
-
It's the strategy's turn and the play made by it leads to an acceptable board.
I plan on adding at least one additional AI strategy and tracking win/loss/tie statistics for the various AI strategies.
-
Clone the repo
-
setup and activate a virtual environment
-
pip install -r requirements.txt
-
export SECRET_KEY="somestring"
-
touch local_settings.py
-
In local_settings.py set the variables DEBUG and TEMPLATE_DEBUG to True
-
python manage.py runserver