2009-10-07 21:22:16 -06:00
|
|
|
#! /usr/bin/python
|
|
|
|
|
|
|
|
import optparse
|
2009-10-08 09:04:07 -06:00
|
|
|
import shutil
|
|
|
|
import time
|
2009-10-06 14:14:16 -06:00
|
|
|
from tanks import Pflanzarr
|
|
|
|
|
|
|
|
T = 60*5
|
2009-10-08 09:04:07 -06:00
|
|
|
MAX_HIST = 30
|
|
|
|
HIST_STEP = 100
|
2009-10-06 14:14:16 -06:00
|
|
|
|
2009-10-07 21:22:16 -06:00
|
|
|
parser = optparse.OptionParser('DATA_DIR easy|medium|hard MAX_TURNS')
|
|
|
|
opts, args = parser.parse_args()
|
|
|
|
if (len(args) != 3) or (args[1] not in ('easy', 'medium', 'hard')):
|
|
|
|
parser.error('Wrong number of arguments')
|
2009-10-06 14:14:16 -06:00
|
|
|
try:
|
2009-10-07 21:22:16 -06:00
|
|
|
turns = int(args[2])
|
2009-10-06 14:14:16 -06:00
|
|
|
except:
|
2009-10-07 21:22:16 -06:00
|
|
|
parser.error('Invalid number of turns')
|
|
|
|
|
|
|
|
while True:
|
|
|
|
start = time.time()
|
|
|
|
p = Pflanzarr.Pflanzarr(args[0], args[1])
|
|
|
|
p.run(turns)
|
2009-10-06 14:14:16 -06:00
|
|
|
|
2009-10-08 09:04:07 -06:00
|
|
|
path = os.path.join(args[0], 'results')
|
|
|
|
files = os.listdir(path)
|
|
|
|
gameNums = []
|
|
|
|
for file in files:
|
|
|
|
try:
|
|
|
|
gameNums.append( int(file) )
|
|
|
|
except:
|
|
|
|
continue
|
|
|
|
|
|
|
|
gameNums.sort(reverse=True)
|
|
|
|
highest = gameNums[0]
|
|
|
|
for num in gameNums:
|
|
|
|
if highest - MAX_HIST > num and not (num % HIST_STEP == 0):
|
|
|
|
shutil.rmtree(os.path.join(path, num))
|
|
|
|
|
2009-10-07 21:22:16 -06:00
|
|
|
diff = time.time() - start
|
|
|
|
if diff - T > 0:
|
|
|
|
time.sleep( diff - T )
|