Make tanks not award points with 0 players

This commit is contained in:
Neale Pickett 2010-03-03 22:48:45 -07:00
parent 43295d62cf
commit 2fd441b06f
2 changed files with 12 additions and 9 deletions

View File

@ -11,7 +11,7 @@ while true; do
# If enabled, run tanks
if ! [ -f var/disabled/tanks ]; then
sbin/run-tanks -1 var/tanks
sbin/run-tanks --no-barren-points --once var/tanks
fi
# Collect any new points
@ -21,6 +21,7 @@ while true; do
rm $fn
done
# Update the scoreboard
if [ -f $POINTS ]; then
sbin/scoreboard -t www/scoreboard.html -j www/myplot.js < $POINTS
fi

View File

@ -8,28 +8,27 @@ import time
from ctf import pointscli, teams, paths
from tanks import Pflanzarr
MAX_HIST = 30
HIST_STEP = 100
running = True
def run_tanks(basedir, turns):
def run_tanks(basedir, turns, barren_points=True):
try:
p = Pflanzarr.Pflanzarr(basedir)
p.run(turns)
winner = p.winner
winner = p.winner or teams.house
except Pflanzarr.NotEnoughPlayers:
if not barren_points:
return
winner = teams.house
pointscli.award('tanks', winner, 1)
winnerFile = open(os.path.join(basedir, 'winner'),'w')
winnerFile.write(winner or teams.house)
winnerFile.write(winner)
winnerFile.close()
# Fake being a flag, so the most recent winner shows up on the
# scoreboard.
try:
open(os.path.join(paths.VAR, 'flags', 'tanks'), 'w').write(winner or teams.house)
open(os.path.join(paths.VAR, 'flags', 'tanks'), 'w').write(winner)
except IOError:
pass
@ -39,6 +38,9 @@ def main():
parser.add_option('-1', '--once',
action='store_true', dest='once',
help='Run only once')
parser.add_option('-b', '--no-barren-points',
action='store_false', dest='barren', default=True,
help="Don't award points if there aren't enough players")
parser.add_option('-t', '--max-turns',
type='int', dest='turns', default=500,
help='Maximum number of turns per round')
@ -50,7 +52,7 @@ def main():
parser.error('Wrong number of arguments')
while running:
run_tanks(args[0], opts.turns)
run_tanks(args[0], opts.turns, opts.barren)
if opts.once:
break
time.sleep(opts.sleep)