Skip to content

Instantly share code, notes, and snippets.

@alirezamika
Created December 27, 2020 09:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alirezamika/dd09befcbcc3e25aeac0d7e6712405f8 to your computer and use it in GitHub Desktop.
Save alirezamika/dd09befcbcc3e25aeac0d7e6712405f8 to your computer and use it in GitHub Desktop.
from agent import Agent
from tictactoe import TicTacToe
def play(agent):
game = TicTacToe()
while True:
action = agent.qlearner.get_best_action(game.get_state())
winner = game.play(*action)
if winner:
print("**** you lost ****")
return
if game.is_ended():
print("**** draw ****")
return
x, y = input("input x and y: ").split()
winner = game.play(int(x), int(y))
if winner:
print("**** you won ****")
return
if game.is_ended():
print("**** draw ****")
return
q_agent = Agent()
print("learning...")
q_agent.learn()
print("done")
while True:
print("\nlet's play\n")
play(q_agent)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment