from positions import positions from tron.game import Game, PositionPlayer def run_battle(ai1, ai2, width, height): games = 50 ai1_victories = 0 ai2_victories = 0 for (initial_position_one, initial_position_two) in positions(): game = Game(width, height, [ PositionPlayer(1, ai1.constructor(), initial_position_one), PositionPlayer(2, ai2.constructor(), initial_position_two), ]) game.main_loop() if game.winner == 1: ai1_victories += 1 elif game.winner == 2: ai2_victories += 1 # Inverse positions and replay to be symmetrical game = Game(width, height, [ PositionPlayer(1, ai2.constructor(), initial_position_one), PositionPlayer(2, ai1.constructor(), initial_position_two), ]) game.main_loop() if game.winner == 1: ai2_victories += 1 elif game.winner == 2: ai1_victories += 1 return (ai1_victories, ai2_victories, 2 * games - ai1_victories - ai2_victories)