pytron-web/pytron_run/run.py

51 lines
1.2 KiB
Python
Raw Permalink Normal View History

2019-03-19 16:44:34 +01:00
#!/usr/bin/env python3
import sys
2019-03-19 17:00:43 +01:00
import json
2019-03-28 10:56:22 +01:00
import pathlib
2019-03-26 15:39:43 +01:00
sys.path.append('../pytron')
2019-03-19 16:44:34 +01:00
from tron.map import Map
2019-03-19 17:00:43 +01:00
from tron.game import Game, PositionPlayer
2019-03-19 16:44:34 +01:00
from tron.player import Direction, ConstantPlayer
import ai_manager
2019-03-28 10:56:22 +01:00
from utils import run_battle
2019-03-19 16:44:34 +01:00
2019-03-28 10:56:22 +01:00
ASSETS_PATH = "assets/data.json"
LAST_REFRESH_PATH = "assets/refresh.dat"
2019-03-19 16:44:34 +01:00
2019-03-26 15:07:36 +01:00
width = 10
height = 10
2019-03-19 16:44:34 +01:00
def main():
2019-03-22 10:56:49 +01:00
print('Welcome to pytron run!')
2019-03-28 10:56:22 +01:00
dictionnary = {}
# Set last update time
pathlib.Path(LAST_REFRESH_PATH).touch()
2019-03-19 17:00:43 +01:00
2019-03-28 10:56:22 +01:00
for (id1, ai1) in enumerate(ai_manager.__all__):
for (id2, ai2) in enumerate(ai_manager.__all__):
2019-03-19 16:44:34 +01:00
if id1 >= id2:
continue
2019-03-28 10:56:22 +01:00
# Sort ais by name just to be sure
if ai1.name > ai2.name:
(sai2, sai1) = (ai1, ai2)
else:
(sai1, sai2) = (ai1, ai2)
print("Battling {} vs {}".format(sai1.name, sai2.name))
(score1, score2, nulls) = run_battle(sai1, sai2, width, height)
dictionnary[sai1.name + "/" + sai2.name] = [score1, score2, nulls]
2019-03-19 17:00:43 +01:00
with open("assets/data.json", "w") as f:
f.write(json.dumps(dictionnary))
2019-03-19 16:44:34 +01:00
2019-03-22 10:56:49 +01:00
print('Pytron run has finished')
2019-03-19 16:44:34 +01:00
if __name__ == '__main__':
main()