Created
December 27, 2020 09:47
-
-
Save alirezamika/dd09befcbcc3e25aeac0d7e6712405f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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