def beginTeaching(self, episodes):
     """ Loop through game iterations with a teaching agent. """
     teacher = Teacher()
     # Train for alotted number of episodes
     while self.games_played < episodes:
         game = Game(self.agent, teacher=teacher)
         game.start()
         self.games_played += 1
         # Monitor progress
         if self.games_played % 1000 == 0:
             print("Games played: %i" % self.games_played)
     # save final agent
     self.agent.save(self.path)
示例#2
0
    def beginTeaching(self, episodes):
        """ Loop through game iterations with a teaching agent. """
        teacher = Teacher()
        # Train for alotted number of episodes
        while self.games_played < episodes:
            game = Game(self.agent, teacher=teacher)
            game.start()
            self.games_played += 1
            # Monitor progress
            if self.games_played % 1000 == 0:
                print("Games played: %i" % self.games_played)

        plot_agent_reward(self.agent.rewards)
示例#3
0
    def beginTeaching(self, episodes):
        """ Loop through game iterations with a teaching agent. """
        teacher = Teacher()
        # Train for alotted number of episodes
        while self.games_played < episodes:
            game = Game(self.agent, teacher=teacher)
            game.start()
            self.games_played += 1
            # Monitor progress
            if self.games_played % 1000 == 0:
                print("Games played: %i" % self.games_played)

        plot_agent_reward(self.agent.rewards)

        if args.agent_type == "q":
            self.agent.save_agent(self.qlearner_agent_path)
        elif args.agent_type == "s":
            self.agent.save_agent(self.sarsa_agent_path)
示例#4
0
    def beginPlaying(self):
        """ Loop through game iterations with a human player. """
        print("Welcome to Tic-Tac-Toe. You are 'X' and the computer is 'O'.")

        def play_again():
            print("Games played: %i" % self.games_played)
            while True:
                play = input("Do you want to play again? [y/n]: ")
                if play == 'y' or play == 'yes':
                    return True
                elif play == 'n' or play == 'no':
                    return False
                else:
                    print("Invalid input. Please choose 'y' or 'n'.")

        while True:
            game = Game(self.agent)
            game.start()
            self.games_played += 1
            if not play_again():
                print("OK. Quitting.")
                break
示例#5
0
    def beginPlaying(self):
        """ Loop through game iterations with a human player. """
        print("Welcome to Tic-Tac-Toe. You are 'X' and the computer is 'O'.")

        def play_again():
            print("Games played: %i" % self.games_played)
            while True:
                play = input("Do you want to play again? [y/n]: ")
                if play == 'y' or play == 'yes':
                    return True
                elif play == 'n' or play == 'no':
                    return False
                else:
                    print("Invalid input. Please choose 'y' or 'n'.")

        while True:
            game = Game(self.agent)
            game.start()
            self.games_played += 1
            if not play_again():
                print("OK. Quitting.")
                break
示例#6
0
 def test_start_game_for_play_option(self):
     selected_options = [2, 6, 2, 3, 7, 9, 5, 1, 1]
     game = Game(lambda _: selected_options.pop(), self.print_function)
     game.start()
     self.assertTrue(game.is_won())
示例#7
0
 def test_start_game_for_exit_option(self):
     game = Game(lambda _: 2, self.print_function)
     game.start()
     self.assertFalse(game.is_won())
示例#8
0
from tictactoe.board import Board
from tictactoe.players import ConsolePlayer, AIPlayer
from tictactoe.outputs import ConsoleOutput
from tictactoe.game import Game

number_of_players = int(raw_input('How many players? '))
if number_of_players == 1:
    play_as_player = int(raw_input('Play as player? '))
else:
    play_as_player = None

player1 = AIPlayer(mark='x') if number_of_players == 0 or (
    number_of_players == 1 and play_as_player == 2) else ConsolePlayer(
        mark='x')
player2 = AIPlayer(mark='o') if number_of_players == 0 or (
    number_of_players == 1 and play_as_player == 1) else ConsolePlayer(
        mark='o')
board = Board(3)
game = Game(player1, player2, board)
output = ConsoleOutput()
game.observer = output
game.start()