From 38ad46d7ce7cb965726d2af5dee8f90261b4a44a Mon Sep 17 00:00:00 2001 From: Peter Ward Date: Sat, 21 Jul 2012 11:27:35 +1000 Subject: Quick and dirty time limiting. --- snakegame/engines/base.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/snakegame/engines/base.py b/snakegame/engines/base.py index 74659c4..2797aa1 100644 --- a/snakegame/engines/base.py +++ b/snakegame/engines/base.py @@ -3,11 +3,15 @@ from copy import deepcopy from random import Random from string import ascii_lowercase as lowercase import sys +import time import traceback from snakegame.colour import hash_colour from snakegame import common +SOFT_TIME_LIMIT = 0.5 +HARD_TIME_LIMIT = 1.0 + class Engine(object): def __init__( self, @@ -118,6 +122,8 @@ class Engine(object): try: x, y = path[-1] + start = time.time() + if team is None: d = bot(board, (x, y)) else: @@ -131,6 +137,12 @@ class Engine(object): ) messages[letter] = message + end = time.time() + delta = end - start + assert delta < HARD_TIME_LIMIT, 'Exceeded hard time limit.' + if delta >= SOFT_TIME_LIMIT: + print 'Bot %s (%r) exceeded soft time limit.' % (letter.upper(), bot) + # Sanity checking... assert isinstance(d, basestring), \ "Return value should be a string." -- cgit v1.2.3