Beispiel #1
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)
Beispiel #2
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)