Fix bugs in constructors

This commit is contained in:
Thomas Forgione 2019-04-04 11:59:37 +02:00
parent e0ae750c92
commit 868e36e31e
No known key found for this signature in database
GPG Key ID: 203DAEA747F48F41
1 changed files with 56 additions and 14 deletions

View File

@ -7,27 +7,69 @@ def run_battle(ai1, ai2, width, height):
ai2_victories = 0 ai2_victories = 0
for (initial_position_one, initial_position_two) in positions(): for (initial_position_one, initial_position_two) in positions():
player_1 = None
player_2 = None
try:
player_1 = ai1.constructor()
except:
pass
try:
player_2 = ai2.constructor()
except:
pass
winner = None
if player_1 is not None and player_2 is not None:
game = Game(width, height, [ game = Game(width, height, [
PositionPlayer(1, ai1.constructor(), initial_position_one), PositionPlayer(1, player_1, initial_position_one),
PositionPlayer(2, ai2.constructor(), initial_position_two), PositionPlayer(2, player_2, initial_position_two),
]) ])
game.main_loop() game.main_loop()
winner = game.winner
elif player_1 is None and player_2 is not None:
# Player 2 wins because he was able to build an ai...
winner = 2
elif player_1 is not None and player_2 is None:
winner = 1
else:
pass
if game.winner == 1: if winner == 1:
ai1_victories += 1 ai1_victories += 1
elif game.winner == 2: elif winner == 2:
ai2_victories += 1 ai2_victories += 1
# Inverse positions and replay to be symmetrical # Inverse positions and replay to be symmetrical
try:
player_2 = ai2.constructor()
except:
pass
try:
player_1 = ai1.constructor()
except:
pass
winner = None
if player_1 is not None and player_2 is not None:
game = Game(width, height, [ game = Game(width, height, [
PositionPlayer(1, ai2.constructor(), initial_position_one), PositionPlayer(1, player_2, initial_position_one),
PositionPlayer(2, ai1.constructor(), initial_position_two), PositionPlayer(2, player_1, initial_position_two),
]) ])
game.main_loop() game.main_loop()
winner = game.winner
elif player_1 is None and player_2 is not None:
winner = 1
elif player_1 is not None and player_2 is None:
winner = 2
if game.winner == 1: if winner == 1:
ai2_victories += 1 ai2_victories += 1
elif game.winner == 2: elif winner == 2:
ai1_victories += 1 ai1_victories += 1
return (ai1_victories, ai2_victories, 2 * games - ai1_victories - ai2_victories) return (ai1_victories, ai2_victories, 2 * games - ai1_victories - ai2_victories)