Skip to content

This project is a tic-tac-toe game with three modes: player vs player, player vs computer, and computer vs computer, where the computer can use reinforcement learning to improve its gameplay.

Notifications You must be signed in to change notification settings

cjcara036/Q_Learning_TicTacToe

Repository files navigation

Tic-Tac-Toe Game with Q-Learning AI

This project is a web-based Tic-Tac-Toe game with an option to play against a Q-Learning AI agent. The AI agent uses the Q-Learning algorithm to learn and improve its strategy as it plays the game.

Features

  • Play Tic-Tac-Toe against another player or against a Q-Learning AI agent
  • Train the AI agent by setting it to play against itself
  • Save and load the AI agent's learning progress

How to Play

  1. Open the index.html file in your web browser
  2. Select the game mode by clicking on the desired mode button (Player vs Player[PvP], Player vs AI[PvC], or AI vs AI[CvC])
  3. Click on the desired cell on the game board to make a move
  4. The game will automatically update the board and switch turns
  5. The game will declare a winner or a tie if the game has ended

How to Train the AI

  1. Set the game mode to AI vs AI[CvC]
  2. The AI will play against itself for the specified number of runs
  3. An alert will be posted once the AI training is done
  4. The AI's learning progress can be saved and loaded using the "Save State" and "Load State" buttons

Technologies Used

  • HTML/CSS/JavaScript for web development
  • Q-Learning algorithm for AI training

Notes

  • The AI agent's learning progress is stored in the QLearn_StateStore variable in the QLearning/script_QLearn.js file. This variable can be modified and saved using the provided "Save State" and "Load State" buttons.
  • The AI agent's training can be customized by modifying the constants in the TTT_processr/TTT_main.js file (e.g. number of runs per training session, feedback scores for different outcomes).

About the QLearn class

The QLearn class is a JavaScript implementation of the Q-Learning algorithm. It is used to train the AI agent in this Tic-Tac-Toe game project. The QLearn class has the following methods:

  • chooseState(SName, StateAction, addtoShiftChain=true): This method chooses an action from the StateAction list, given a state represented by SName. If addtoShiftChain is set to true, the chosen action will also be added to the QLearn object's state chain. The chosen action is selected based on the probabilities stored in the QLearn_StateStore global variable, which is a matrix of state-action pairs and their corresponding probabilities.
  • feedback(StateChain_Score): This method updates the probabilities in the QLearn_StateStore based on the feedback score provided in StateChain_Score. The feedback score is used to adjust the probabilities of the actions in the QLearn object's state chain in proportion to their relative distance from the end of the chain. The probabilities are also normalized after being updated.
  • addtoStateChain(stateName, ActList, ActionSelected): This method adds an entry to the QLearn object's state chain, consisting of the state represented by stateName and the action represented by ActionSelected. If the state represented by stateName does not exist in the QLearn_StateStore, it is added to the QLearn_StateStore with equal probabilities for all actions in ActList.
  • clearStateChain(): This method clears the QLearn object's state chain.

About

This project is a tic-tac-toe game with three modes: player vs player, player vs computer, and computer vs computer, where the computer can use reinforcement learning to improve its gameplay.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published