Merge cfl:/var/projects/gctf

This commit is contained in:
Neale Pickett 2009-10-07 13:29:13 -06:00
commit c2c763d2b3
2 changed files with 37 additions and 18 deletions

1
.gitignore vendored
View File

@ -3,6 +3,7 @@
*.dat
*.swp
passwd
fake
target/
puzzler/
ctf.tce

View File

@ -9,19 +9,12 @@ from urllib import unquote, quote
from PIL import Image, ImageColor, ImageDraw
try:
from ctf import teams
except:
import sys
path = '/home/pflarr/repos/gctf/'
sys.path.append(path)
from ctf import teams
teams.build_teams()
import Tank
class Pflanzarr:
TEAMS_FILE = '/var/lib/ctf/passwd'
FRAME_DELAY = 15
SPACING = 150
@ -42,12 +35,14 @@ class Pflanzarr:
if not os.path.exists(self._gameDir):
os.mkdir(self._gameDir)
colors = self._getColors()
tmpPlayers = os.listdir(self._playerDir)
players = []
for p in tmpPlayers:
p = unquote(p)
if not (p.startswith('.') or p.endswith('#') or p.endswith('~'))\
and p in teams.teams:
and p in colors:
players.append(p)
AIs = {}
@ -73,7 +68,7 @@ class Pflanzarr:
self._board = (cols*self.SPACING, rows*self.SPACING)
while len(players) < cols*rows:
players.append('#default')
players.append(None)
self._tanks = []
for i in range(cols):
@ -82,13 +77,13 @@ class Pflanzarr:
startY = j*self.SPACING + self.SPACING/2
player = random.choice(players)
players.remove(player)
if player == '#default':
if player == None:
color = '#a0a0a0'
else:
color = '#%s' % teams.teams[player][1]
color =
tank = Tank.Tank( player, (startX, startY), color,
self._board, testMode=True)
if player == '#default':
if player == None:
tank.program(random.choice(defaultAIs))
else:
tank.program(AIs[player])
@ -156,10 +151,12 @@ class Pflanzarr:
if tank in kills[tank]:
kills[tank].remove(tank)
self._saveResults(kills)
for tank in self._tanks:
self._outputErrors(tank)
self._makeMovie()
# This needs to go after _makeMovie; the web scripts look for these
# files to see if the game has completed.
self._saveResults(kills)
def _killTanks(self, tanks, reason):
for tank in tanks:
@ -219,7 +216,8 @@ class Pflanzarr:
html.append('</table><body></html>')
if winner.name != '#default':
# Write a blank file if the winner is a default tank..
if winner.name != None:
winnerFile.write(tanks[0].name)
winnerFile.close()
@ -250,7 +248,7 @@ class Pflanzarr:
def _outputErrors(self, tank):
"""Output errors for each team."""
if tank.name == '#default':
if tank.name == None:
return
if tank._program.errors:
@ -378,7 +376,27 @@ class Pflanzarr:
defaultAIs.append( file.read() )
return defaultAIs
def _getColors(self):
"""Get the team colors from the passwd file. The passwd file location
is set by self.TEAMS_FILE. Returns a dictionary of players->color"""
errorColor = '#ffffff'
try:
file = open(self.TEAMS_FILE)
except:
return {}.fromkeys(players, errorColor)
colors = {}
for line in file:
try:
team, passwd, color = map(unquote, line.split('\t'))
colors[team] = '#%s' % color
except:
colors[team] = errorColor
return teams
def _getGameNum(self):
"""Figure out what game number this is from the past games played."""