From b3f341733595b3cfb876f46d3a8a1a312474499d Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Wed, 27 Mar 2019 14:40:18 +0100 Subject: [PATCH] Deterministic run --- pytron | 2 +- pytron_run/ai_manager/dummy2/ai.py | 8 ----- pytron_run/positions.py | 53 ++++++++++++++++++++++++++++++ pytron_run/run.py | 10 ++---- 4 files changed, 56 insertions(+), 17 deletions(-) delete mode 100644 pytron_run/ai_manager/dummy2/ai.py create mode 100644 pytron_run/positions.py diff --git a/pytron b/pytron index 5d1c964..b2504f4 160000 --- a/pytron +++ b/pytron @@ -1 +1 @@ -Subproject commit 5d1c96407b665e138784431cf0046537065bfaee +Subproject commit b2504f49f9e30e3ffa07ec3ab11d6b465829b593 diff --git a/pytron_run/ai_manager/dummy2/ai.py b/pytron_run/ai_manager/dummy2/ai.py deleted file mode 100644 index 60d20be..0000000 --- a/pytron_run/ai_manager/dummy2/ai.py +++ /dev/null @@ -1,8 +0,0 @@ -from tron.player import Player, Direction - -class Ai(Player): - def __init__(self): - super(Ai, self).__init__() - - def action(self, map, id): - return Direction.LEFT diff --git a/pytron_run/positions.py b/pytron_run/positions.py new file mode 100644 index 0000000..3b30c70 --- /dev/null +++ b/pytron_run/positions.py @@ -0,0 +1,53 @@ +def positions(): + return [ + [(4, 4), (5, 5)], + [(0, 0), (0, 9)], + [(0, 4), (0, 5)], + [(1, 2), (1, 7)], + [(7, 2), (2, 7)], + [(3, 2), (6, 7)], + [(9, 4), (0, 5)], + [(9, 0), (4, 9)], + [(7, 3), (0, 6)], + [(6, 7), (4, 8)], + [(8, 6), (9, 2)], + [(4, 3), (3, 1)], + [(1, 9), (0, 9)], + [(2, 9), (0, 9)], + [(9, 9), (3, 9)], + [(4, 2), (3, 2)], + [(3, 7), (7, 4)], + [(6, 6), (1, 4)], + [(4, 3), (0, 1)], + [(7, 3), (3, 8)], + [(3, 5), (5, 2)], + [(4, 2), (8, 5)], + [(2, 6), (3, 8)], + [(4, 0), (4, 9)], + [(9, 9), (2, 0)], + [(5, 1), (8, 1)], + [(5, 2), (2, 2)], + [(0, 7), (0, 8)], + [(6, 9), (9, 6)], + [(2, 9), (9, 4)], + [(0, 9), (4, 1)], + [(3, 5), (2, 7)], + [(6, 2), (7, 4)], + [(8, 7), (2, 3)], + [(9, 2), (1, 6)], + [(9, 4), (1, 1)], + [(2, 5), (3, 8)], + [(3, 1), (6, 8)], + [(7, 0), (1, 9)], + [(6, 3), (1, 6)], + [(4, 1), (5, 5)], + [(5, 9), (0, 6)], + [(9, 8), (0, 5)], + [(9, 1), (8, 0)], + [(7, 0), (1, 9)], + [(2, 1), (2, 5)], + [(7, 2), (4, 5)], + [(9, 2), (5, 6)], + [(8, 0), (0, 6)], + [(3, 1), (3, 9)], + ] diff --git a/pytron_run/run.py b/pytron_run/run.py index 431644f..5275b74 100755 --- a/pytron_run/run.py +++ b/pytron_run/run.py @@ -2,8 +2,6 @@ import sys import json -import random -random.seed() sys.path.append('../pytron') from tron.map import Map @@ -12,6 +10,7 @@ from tron.player import Direction, ConstantPlayer from importlib import import_module +import positions import ai_manager # Find all the AIs @@ -40,12 +39,7 @@ def run_battle(ai1, ai2): ai1_victories = 0 ai2_victories = 0 - for _ in range(games): - initial_position_one = [random.randint(0, width - 1), random.randint(0, height - 1)] - initial_position_two = [random.randint(0, width - 1), random.randint(0, height - 1)] - while initial_position_one[0] == initial_position_two[0] and initial_position_one[1] == initial_position_two[1]: - initial_position_two = [random.randint(0, width - 1), random.randint(0, height - 1)] - + for (initial_position_one, initial_position_two) in positions.positions(): game = Game(width, height, [ PositionPlayer(1, ai1.builder(), initial_position_one), PositionPlayer(2, ai2.builder(), initial_position_two),