Skip to content

Commit

Permalink
Added time checking. The bots are not stopped but if the answer goes …
Browse files Browse the repository at this point in the history
…over the time_limit (+ sigma) the referee tells incidates which bot exceeds in time
  • Loading branch information
mdelorme committed Mar 7, 2017
1 parent 5b1421b commit ff78e03
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion referee.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@
import multiprocessing as mp
import numpy as np
import random
import time
from copy import copy

seed_bank = []
debug = False

t_limit = 0.1
t_limit_large = 1.0
t_limit_sigma = 0.05 # Variation accepted on the max time, to make sure communication time is not impairing a bot

def log(p_from, p_to, msg):
print('{} to {} -- {}'.format(p_from, p_to, msg))

Expand Down Expand Up @@ -127,7 +132,7 @@ def __init__(self, param_file):
else:
self.score_log = None

self.runs = int(self.settings['Runs'])
self.runs = int(self.settings['Runs'])

if "Seed" in self.settings:
random.seed(self.settings['Seed'])
Expand Down Expand Up @@ -192,6 +197,7 @@ def run_game(self, run_info):

finished = False
cur_bot = 0
turn = 0
try:
while not finished:
# Getting the exec code from the eval code :
Expand All @@ -213,20 +219,36 @@ def run_game(self, run_info):
finished = True
elif exec_code > 0:
# Sending input to the bot
t_start = None
t_end = None
for i in range(exec_code):
line = game_proc.stdout.readline().strip()
if debug:
log('Engine', bots[cur_bot].name, line)

bots[cur_bot].stdin.write(line+'\n')
if i==0:
t_start = time.time()

# Reading output
line = bots[cur_bot].stdout.readline().strip()
t_end = time.time()

if turn < len(bots):
max_time = t_limit_large * (1.0 + t_limit_sigma)
else:
max_time = t_limit * (1.0 + t_limit_sigma)

if (t_end - t_start) > max_time:
print('Run {} : Bot {} exceeds allocated time !'.format(ite+1, bots[cur_bot].name))

if debug:
log(bots[cur_bot].name, 'Engine', line)
game_proc.stdin.write(line+'\n')

# Next bot
cur_bot = (cur_bot + 1) % len(bots)
turn += 1

# Once we have finished, we display the ranking

Expand Down

0 comments on commit ff78e03

Please sign in to comment.