Agent learns to play Tic-Tac-Toe using Reinforcement-learning (Q-learning). The agent was trained by playing against itself. Human can also play against trained Agent.
Requirements:
python 3.5.2 and pygame
Run Play.py to play game.
py -3 Play.py
Run Train.py to train the agent.
py -3 Train.py
Training:
It took 200,000 iterations to master the game.
game = TicTacToe(True) #game instance, True means training
player1= Qlearning() #player1 learning agent
player2 =Qlearning() #player2 learning agent
game.startTraining(player1,player2) #start training
game.train(200000) #train for 200,000 iterations
game.saveStates() #save Qtable
Playing
Human player vs AI agent
game = TicTacToe() #game instance
player1=Humanplayer() #human player
player2=Qlearning() #agent
game.startGame(player1,player2)#player1 is X, player2 is 0
game.reset() #reset
game.render() # render display
Random player instead of AI agent
#change player1 or player2 to Randomplayer()
player2 =Randomplayer()