Added 'fake' to .gitignore.

Removed ctf.teams dependency from Pflanzarr
This commit is contained in:
Paul S. Ferrell 2009-10-07 13:18:30 -06:00
parent db646f244e
commit 3343f62208
2 changed files with 37 additions and 18 deletions

1
.gitignore vendored
View File

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

View File

@ -9,19 +9,12 @@ from urllib import unquote, quote
from PIL import Image, ImageColor, ImageDraw 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 import Tank
class Pflanzarr: class Pflanzarr:
TEAMS_FILE = '/var/lib/ctf/passwd'
FRAME_DELAY = 15 FRAME_DELAY = 15
SPACING = 150 SPACING = 150
@ -42,12 +35,14 @@ class Pflanzarr:
if not os.path.exists(self._gameDir): if not os.path.exists(self._gameDir):
os.mkdir(self._gameDir) os.mkdir(self._gameDir)
colors = self._getColors()
tmpPlayers = os.listdir(self._playerDir) tmpPlayers = os.listdir(self._playerDir)
players = [] players = []
for p in tmpPlayers: for p in tmpPlayers:
p = unquote(p) p = unquote(p)
if not (p.startswith('.') or p.endswith('#') or p.endswith('~'))\ if not (p.startswith('.') or p.endswith('#') or p.endswith('~'))\
and p in teams.teams: and p in colors:
players.append(p) players.append(p)
AIs = {} AIs = {}
@ -73,7 +68,7 @@ class Pflanzarr:
self._board = (cols*self.SPACING, rows*self.SPACING) self._board = (cols*self.SPACING, rows*self.SPACING)
while len(players) < cols*rows: while len(players) < cols*rows:
players.append('#default') players.append(None)
self._tanks = [] self._tanks = []
for i in range(cols): for i in range(cols):
@ -82,13 +77,13 @@ class Pflanzarr:
startY = j*self.SPACING + self.SPACING/2 startY = j*self.SPACING + self.SPACING/2
player = random.choice(players) player = random.choice(players)
players.remove(player) players.remove(player)
if player == '#default': if player == None:
color = '#a0a0a0' color = '#a0a0a0'
else: else:
color = '#%s' % teams.teams[player][1] color =
tank = Tank.Tank( player, (startX, startY), color, tank = Tank.Tank( player, (startX, startY), color,
self._board, testMode=True) self._board, testMode=True)
if player == '#default': if player == None:
tank.program(random.choice(defaultAIs)) tank.program(random.choice(defaultAIs))
else: else:
tank.program(AIs[player]) tank.program(AIs[player])
@ -156,10 +151,12 @@ class Pflanzarr:
if tank in kills[tank]: if tank in kills[tank]:
kills[tank].remove(tank) kills[tank].remove(tank)
self._saveResults(kills)
for tank in self._tanks: for tank in self._tanks:
self._outputErrors(tank) self._outputErrors(tank)
self._makeMovie() 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): def _killTanks(self, tanks, reason):
for tank in tanks: for tank in tanks:
@ -219,7 +216,8 @@ class Pflanzarr:
html.append('</table><body></html>') 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.write(tanks[0].name)
winnerFile.close() winnerFile.close()
@ -250,7 +248,7 @@ class Pflanzarr:
def _outputErrors(self, tank): def _outputErrors(self, tank):
"""Output errors for each team.""" """Output errors for each team."""
if tank.name == '#default': if tank.name == None:
return return
if tank._program.errors: if tank._program.errors:
@ -378,7 +376,27 @@ class Pflanzarr:
defaultAIs.append( file.read() ) defaultAIs.append( file.read() )
return defaultAIs 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): def _getGameNum(self):
"""Figure out what game number this is from the past games played.""" """Figure out what game number this is from the past games played."""