def random_v_random(n=1): """ Plays two random players against each other """ p1_strategy = strategies.RandomStrategy() p2_strategy = strategies.RandomStrategy() p1 = player.Player('X', p1_strategy) p2 = player.Player('O', p2_strategy) board = tictactoe.Board() game = rl_game.Game(p1, p2, board) game.play_one()
def random_v_q(n=1000): """ Trains the RL agent against random """ for i in range(5): p1_strategy = strategies.RandomStrategy() p2_strategy = strategies.QStrategy('O') p1 = player.Player('X', p1_strategy) p2 = player.Player('O', p2_strategy) board = tictactoe.Board() game = rl_game.Game(p1, p2, board) game.play_many(n)
def q_v_q(): """ Plays two Q-strategy players against each other """ p1_strategy = strategies.QStrategy('X') p2_strategy = strategies.QStrategy('O') p1 = player.Player('X', p1_strategy) p2 = player.Player('O', p2_strategy) board = tictactoe.Board() game = rl_game.Game(p1, p2, board) game.play_one() p1.strategy.save_q() p2.strategy.save_q()
def train_q(n=1000): """ Trains the RL agent """ for i in range(50): p1_strategy = strategies.QStrategy('X') p2_strategy = strategies.QStrategy('O') p1 = player.Player('X', p1_strategy) p2 = player.Player('O', p2_strategy) board = tictactoe.Board() game = rl_game.Game(p1, p2, board) game.play_many(n) p1.strategy.save_q() p2.strategy.save_q()
def human_v_q(human_player=1): """ Allows human to play versus q-learning agent """ if human_player == 1: p1_strategy = strategies.Human() p2_strategy = strategies.QStrategy('O') else: human_player = 2 p1_strategy = strategies.QStrategy('X') p2_strategy = strategies.Human() p1 = player.Player('X', p1_strategy) p2 = player.Player('O', p2_strategy) board = tictactoe.Board() message = 'Welcome to tic tac toe!\n'+\ 'You are playing against a random opponent and you are player '+str(human_player)+'.\n'+\ 'To make a move, enter the number of the square which you would like to play, labelled as:\n'+\ '1, 2, 3\n4, 5, 6\n7, 8, 9\n\n' print(message) game = rl_game.Game(p1, p2, board) game.play_one()