Exemple #1
0
 def testAgainstSecondMoveHeuristikAgentIn100Testgames(self):
     heuristicSearchAgentWins = 0
     tdqAgent1000Wins = 0
     for testGameCount in range(100):
         ttt = TicTacToe(4)
         tdqAgent1000 = TicTacToeTDQLearningAgent(
             TICTACTOE_4x4_TDQ_AGENT_1000_NAME, 4)
         while not ttt.is_terminal():
             action = tdqAgent1000.suggestAction(ttt)
             print action
             ttt.make_move(action)
             if not ttt.is_terminal():
                 HeuristicSearchAgentTicTacToe.processAction(ttt)
         print ttt.printable_game_matrix()
         if ttt.is_victory() and ttt.get_player_which_moved_last() == 'X':
             tdqAgent1000Wins += 1
         elif ttt.is_victory() and ttt.get_player_which_moved_last() == 'O':
             heuristicSearchAgentWins += 1
     print 'Second move heuristic search agent wins: ' + str(
         heuristicSearchAgentWins
     ) + ' games against TD-Q-Agent-1000 in 16 field Tic Tac Toe!'
     print 'First move TD-Q-Agent-1000 wins: ' + str(
         tdqAgent1000Wins
     ) + ' games against heuristic search agent in 16 field Tic Tac Toe!'
     self.assertTrue(tdqAgent1000Wins >= 50)
Exemple #2
0
 def testAgainstFirstMoveRandomAgentIn100Testgames(self):
     randomAgentWins = 0
     tdqAgent1000Wins = 0
     for testGameCount in range(100):
         ttt = TicTacToe(3)
         tdqAgent1000 = TicTacToeTDQLearningAgent(TICTACTOE_3x3_TDQ_AGENT_1000_NAME, 3)
         while not ttt.is_terminal():
             RandomAgent.processTicTacToeAction(ttt)
             if not ttt.is_terminal():
                 ttt.make_move(tdqAgent1000.suggestAction(ttt))
         print ttt.printable_game_matrix()
         if ttt.is_victory() and ttt.get_player_which_moved_last() == 'X':
             randomAgentWins += 1
         elif ttt.is_victory() and ttt.get_player_which_moved_last() == 'O':
             tdqAgent1000Wins += 1
     print 'First Move random agent wins: ' + str(
         randomAgentWins) + ' games against TD-Q-Agent-1000 in 9 field Tic Tac Toe!'
     print 'Second Move TD-Q-Agent-1000 wins: ' + str(
         tdqAgent1000Wins) + ' games against random agent in 9 field Tic Tac Toe!'
     self.assertTrue(tdqAgent1000Wins >= 50)
Exemple #3
0
    def learnTictactoe(self, gamesToPlay):
        """Represents the self play and learning mode of the TD-Q-Agent.

        Parameters
        ----------
        gamesToPlay : int
            The amount of training games to play against itself."""
        for gameCount in range(gamesToPlay):
            ttt = TicTacToe(self.__dimension)
            logging.info('Learning against itself game: ' + str(gameCount))
            while not ttt.is_terminal():
                suggestedAction = self.qLearnIteration(ttt, ttt.getReward(), 0.4, 1)
                ttt.make_move(suggestedAction)
            if ttt.is_terminal():
                self.qLearnIteration(ttt, ttt.getReward(), 0.4, 1)
            self.__s = None
            self.__a = None
            self.__r = None
            if gameCount % 100 == 0:
                self.__random_factor += 1
Exemple #4
0
 def testAgainstFirstMoveRandomAgentIn9FieldTicTacToe(self):
     randomAgentWins = 0
     heuristicSearchAgentWins = 0
     for testGameCount in range(100):
         ttt = TicTacToe(3)
         while not ttt.is_terminal():
             RandomAgent.processTicTacToeAction(ttt)
             if not ttt.is_terminal():
                 HeuristicSearchAgentTicTacToe.processAction(ttt)
         print ttt.printable_game_matrix()
         if ttt.is_victory() and ttt.get_player_which_moved_last() == 'X':
             randomAgentWins += 1
         elif ttt.is_victory() and ttt.get_player_which_moved_last() == 'O':
             heuristicSearchAgentWins += 1
     print 'First Move random agent wins: ' + str(
         randomAgentWins
     ) + ' games against heuristic search agent in 9 field Tic Tac Toe!'
     print 'Second Move heuristic search agent wins: ' + str(
         heuristicSearchAgentWins
     ) + ' games against random agent in 9 field Tic Tac Toe!'
     self.assertTrue(heuristicSearchAgentWins >= 60)