Final (I hope tanks update).

This commit is contained in:
Paul S. Ferrell 2009-10-06 12:47:36 -06:00
parent 41f077192d
commit 2034591fb6
14 changed files with 122 additions and 47 deletions

1
.gitignore vendored
View File

@ -1,6 +1,7 @@
*~
*.pyc
*.dat
*.swp
passwd
target/
puzzler/

View File

@ -18,7 +18,6 @@ teams = {}
built = 0
def build_teams():
global teams, built
if not os.path.exists(passwdfn):
return
if os.path.getmtime(passwdfn) <= built:

Binary file not shown.

View File

@ -5,6 +5,8 @@ import random
import subprocess
import xml.sax.saxutils
from urllib import unquote, quote
from PIL import Image, ImageColor, ImageDraw
try:
@ -14,6 +16,7 @@ except:
path = '/home/pflarr/repos/gctf/'
sys.path.append(path)
from ctf import teams
teams.build_teams()
import Tank
@ -43,7 +46,7 @@ class Pflanzarr:
players = []
for p in tmpPlayers:
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:
players.append(p)
@ -54,23 +57,27 @@ class Pflanzarr:
assert len(players) >= 1, "There must be at least one player."
# The one is added to ensure that there is at least one defaultAI bot.
size = math.sqrt(len(players) + 1)
if int(size) != size:
size = size + 1
# The one is added to ensure that there is at least one #default bot.
cols = math.sqrt(len(players) + 1)
if int(cols) != cols:
cols = cols + 1
size = int(size)
if size < 2:
size = 2
cols = int(cols)
if cols < 2:
cols = 2
self._board = (size*self.SPACING, size*self.SPACING)
rows = len(players)/cols
if len(players) % cols != 0:
rows = rows + 1
while len(players) < size**2:
self._board = (cols*self.SPACING, rows*self.SPACING)
while len(players) < cols*rows:
players.append('#default')
self._tanks = []
for i in range(size):
for j in range(size):
for i in range(cols):
for j in range(rows):
startX = i*self.SPACING + self.SPACING/2
startY = j*self.SPACING + self.SPACING/2
player = random.choice(players)
@ -78,7 +85,7 @@ class Pflanzarr:
if player == '#default':
color = '#a0a0a0'
else:
color = team.teams[player][1]
color = '#%s' % teams.teams[player][1]
tank = Tank.Tank( player, (startX, startY), color,
self._board, testMode=True)
if player == '#default':
@ -250,7 +257,7 @@ class Pflanzarr:
print tank.name, 'has errors'
fileName = os.path.join(self._errorDir, tank.name)
fileName = os.path.join(self._errorDir, quote(tank.name))
file = open(fileName, 'w')
for error in tank._program.errors:
file.write(error)
@ -351,6 +358,7 @@ class Pflanzarr:
self._resultsDir = os.path.join(dir, 'results')
self._errorDir = os.path.join(dir, 'errors')
self._imageDir = os.path.join(dir, 'frames')
if not os.path.isdir(self._imageDir):
os.mkdir( self._imageDir )
self._playerDir = os.path.join(dir, 'ai', 'players')

1
tanks/www/Config.py Normal file
View File

@ -0,0 +1 @@
DATA_PATH = '/var/lib/tanks/'

View File

@ -54,7 +54,7 @@ h1, h2, h3 {
letter-spacing: -0.05em;
}
code, pre, .readme {
code, pre, .readme, div.errors {
color: #fff;
background-color: #555;
margin: 1em;
@ -97,3 +97,4 @@ dd {
fieldset * {
margin: 3px;
}

View File

@ -18,7 +18,7 @@ except:
print open('head.html').read() % "Documentation"
print '<BODY>'
print '<H1>Pflanzarr Documentation</H1>'
print '<a href="submit.html">Submit</a> | <a href="results.cgi">Results</a> | <a href="docs.cgi">Documentation</a>'
print open('links.html').read()
print Program.__doc__
print '<H3>Setup Actions:</H3>'

69
tanks/www/errors.cgi Executable file
View File

@ -0,0 +1,69 @@
#!/usr/bin/python
print """Content-Type: text/html\n\n"""
print """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN">\n\n"""
import cgi
import cgitb; cgitb.enable()
import os
import Config
try:
from urllib.parse import quote
except:
from urllib import quote
try:
from ctf import teams
except:
import sys
path = '/home/pflarr/repos/gctf/'
sys.path.append(path)
from ctf import teams
teams.build_teams()
head = open('head.html').read() % "Error Report"
print head
print open('links.html').read()
def done():
print '</body></html>'
sys.exit(0)
fields = cgi.FieldStorage()
team = fields.getfirst('team', '').strip()
passwd = fields.getfirst('passwd', '').strip()
if team and passwd and \
team in teams.teams and passwd == teams.teams[team][0]:
path = os.path.join(Config.DATA_PATH, 'errors', quote(team))
if os.path.isfile(path):
errors = open(path).readlines()
print '<p>Your latest errors:'
print '<div class=errors>'
if errors:
print '<BR>\n'.join(errors)
else:
print 'There were no errors.'
print '</div>'
else:
print '<p>No error file found.'
done()
if team and team not in teams.teams:
print '<p>Invalid team.'
if team and team in teams.teams and passwd != teams.teams[team][0]:
print '<p>Invalid password.'
print '''
<form action="errors.cgi" method="get">
<fieldset>
<legend>Error report request:</legend>
Team: <input type="text" name="team"><BR>
Password: <input type="text" name="passwd"><BR>
<button type="get my errors">Submit</button>
</fieldset>
</form>'''
done()

View File

@ -1,5 +1,5 @@
<html>
<head>
<link href="ctf.css" rel="stylesheet" type="text/css">'
<title>%s</title>"
<link href="ctf.css" rel="stylesheet" type="text/css">
<title>%s</title>
</head>

4
tanks/www/links.html Normal file
View File

@ -0,0 +1,4 @@
<a href="docs.cgi">Documentation</a> |
<a href="results.cgi">Results</a> |
<a href="submit.html">Submit</a> |
<a href="errors.cgi">My Errors</a>

View File

@ -3,15 +3,17 @@
import cgitb; cgitb.enable()
import os
import Config
print """Content-Type: text/html\n\n"""
print """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">\n\n"""
head = open('head.html').read() % "Pflanzarr Results"
print head
print "<H1>Results</H1>"
print '<a href="submit.html">Submit</a> | <a href="results.cgi">Results</a> | <a href="docs.cgi">Documentation</a>'
print open('links.html').read()
try:
winner = open(os.path.join('data', 'winner')).read()
winner = open(os.path.join(Config.DATA_PATH, 'winner')).read()
except:
winner = "No winner yet."
@ -19,9 +21,9 @@ print "<H3>Last Winner: ", winner, '<H3>'
print "<H2>Results so far:</H2>"
try:
games = os.listdir(os.path.join('data', 'results'))
games = os.listdir(os.path.join('results'))
except:
print '<p>The data directory does not exist.'
print '<p>The results directory does not exist.'
games = []
if not games:
@ -30,7 +32,7 @@ gameNums = []
for game in games:
try:
num = int(game)
path = os.path.join( 'data', "results", game, 'results.html')
path = os.path.join( 'results', game, 'results.html')
if os.path.exists( path ):
gameNums.append( int(num) )
else:
@ -43,5 +45,5 @@ gameNums.sort(reverse=True)
for num in gameNums:
print '<p>%d - ' % num,
print '<a href="data/results/%d/game.avi">v</a>' % num,
print '<a href="data/results/%d/results.html">r</a>' % num
print '<a href="results/%d/game.avi">v</a>' % num,
print '<a href="results/%d/results.html">r</a>' % num

View File

@ -1,16 +0,0 @@
body { background-color : #000000;
color : #E0E0E0;
}
table {
border : 2px solid #00EE00;
border-collapse : collapse;
margin : 3px;
}
table td { border : 1px solid #00BB00;
padding-left: 3px;
padding-right: 3px;
text-align: left;
vertical-align: top;
}

View File

@ -4,6 +4,8 @@ import cgi
import cgitb; cgitb.enable()
import os
import Config
try:
from urllib.parse import quote
except:
@ -16,13 +18,14 @@ except:
path = '/home/pflarr/repos/gctf/'
sys.path.append(path)
from ctf import teams
teams.build_teams()
print """Content-Type: text/html\n\n"""
print """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN">\n\n"""
head = open('head.html').read() % "Submission Results"
print head
print "<H1>Results</H1>"
print '<a href="submit.html">Submit</a> | <a href="results.cgi">Results</a> | <a href="docs.cgi">Documentation</a>'
print open('links.html').read()
def done():
print '</body></html>'
@ -45,7 +48,7 @@ if team not in teams.teams:
if passwd != teams.teams[team][0]:
print '<p>Invalid password.'; done()
path = os.path.join('data/ai/players', encode(team) )
path = os.path.join(Config.DATA_PATH, 'ai/players', encode(team) )
file = open(path, 'w')
file.write(code)
file.close()

View File

@ -6,8 +6,11 @@
<body>
<H1>Program Submission</H1>
<p><a href="submit.html">Submit</a> | <a href="results.cgi">Results</a> | <a href="docs.cgi">Documentation</a>
<p>
<a href="docs.cgi">Documentation</a> |
<a href="results.cgi">Results</a> |
<a href="submit.html">Submit</a> |
<a href="errors.cgi">My Errors</a>
<form action="submit.cgi" method="post">
<fieldset>
<legend>Your program:</legend>