/Tic-Tac-Toe-with-Q-Learning

Training an agent to learn play Tic-Tac-Toe using Q-Learning

Primary LanguagePython

Tic-Tac-Toe-with-Q-Learning

Training an agent to learn play Tic-Tac-Toe using Q-Learning

Losing is just not an option for the Tic-Tac-Toe master

Requirements

  • torch -'1.5.0+cu101'
  • numpy -1.19.0
  • matplotlib-3.1.1
  • tqdm

How to Train the QLearning Agents

python main.py

This results in 2 QTables namely QLearningAgent_0_QTable and QLearningAgent_X_QTable being saved in the root directory.

How to run Tensorboard for Visualization

tensorboard --logdir <summary_directory_path> --port=<port_number>

or

tensorboard --logdir summary

because we have set the summary_directory_path as "summary" in config.py
NOTE: The default port for tensorboard is 6006

How to Play TicTocToe Against a QLearning Agent

python play.py

This essentially uses the QTables which were saved as a result of running main.py
But you do not necessarily need to run main.py for playing the game against the QLearningAgent because I have already put the QTables in this repository.

Result

Reward plots for both the QLearningAgents over the course of 100,000 episodes.

Losing is just not an option for the Tic-Tac-Toe master