Skip to content

jamiejamiebobamie/tictactoe_ai

Repository files navigation

Tic Tac Toe AI

This is an improved version of an earlier attempt at building a Tic-Tac-Toe A.I.

The A.I. is trained using Q reinforcement learning. The built model is a CSV file of states and actions.

Given the state of the board and the current person's turn, the model returns an array of scores associated with all of the possible actions for that state. The highest score is the ideal move.

The scores are built up slowly over many epochs of training where the AI is playing Tic-Tac-Toe against itself.

To improve my model, I made two simple adjustments while training:

  • The first move of every game was chosen at random.
  • By rotating the board 90 degrees 3 times, I updated the scores of 4 states instead of one.

Despite my improvements, my model performed about the same as it had previously, with a 97% win rate when going first and an 85% win rate when going second.

Getting Started

If you wish to play around with the model, you can clone the repo locally. In your terminal, navigate to the main folder of the cloned repo and type these commands to install the requirements and then play the game:

  • 'pip install -r requirements.txt'
  • 'python3 play.py'

Alternatively, you can visit my web app to play against the AI.

Prerequisites

You will need Python installed locally on your computer.

Authors

  • Jamie McCrory

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments

About

Q Reinforcement Learning applied to Tic Tac Toe.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages