Esempio n. 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)
Esempio n. 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)