mirror of https://github.com/dirtbags/moth.git
Merge cfl:/var/projects/gctf
This commit is contained in:
commit
c2c763d2b3
|
@ -3,6 +3,7 @@
|
|||
*.dat
|
||||
*.swp
|
||||
passwd
|
||||
fake
|
||||
target/
|
||||
puzzler/
|
||||
ctf.tce
|
||||
|
|
|
@ -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:
|
||||
|
@ -379,6 +377,26 @@ class Pflanzarr:
|
|||
|
||||
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."""
|
||||
|
||||
|
|
Loading…
Reference in New Issue