mirror of https://github.com/dirtbags/moth.git
Final (I hope tanks update).
This commit is contained in:
parent
41f077192d
commit
2034591fb6
|
@ -1,6 +1,7 @@
|
||||||
*~
|
*~
|
||||||
*.pyc
|
*.pyc
|
||||||
*.dat
|
*.dat
|
||||||
|
*.swp
|
||||||
passwd
|
passwd
|
||||||
target/
|
target/
|
||||||
puzzler/
|
puzzler/
|
||||||
|
|
|
@ -18,7 +18,6 @@ teams = {}
|
||||||
built = 0
|
built = 0
|
||||||
def build_teams():
|
def build_teams():
|
||||||
global teams, built
|
global teams, built
|
||||||
|
|
||||||
if not os.path.exists(passwdfn):
|
if not os.path.exists(passwdfn):
|
||||||
return
|
return
|
||||||
if os.path.getmtime(passwdfn) <= built:
|
if os.path.getmtime(passwdfn) <= built:
|
||||||
|
|
Binary file not shown.
|
@ -5,6 +5,8 @@ import random
|
||||||
import subprocess
|
import subprocess
|
||||||
import xml.sax.saxutils
|
import xml.sax.saxutils
|
||||||
|
|
||||||
|
from urllib import unquote, quote
|
||||||
|
|
||||||
from PIL import Image, ImageColor, ImageDraw
|
from PIL import Image, ImageColor, ImageDraw
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -14,6 +16,7 @@ except:
|
||||||
path = '/home/pflarr/repos/gctf/'
|
path = '/home/pflarr/repos/gctf/'
|
||||||
sys.path.append(path)
|
sys.path.append(path)
|
||||||
from ctf import teams
|
from ctf import teams
|
||||||
|
teams.build_teams()
|
||||||
|
|
||||||
import Tank
|
import Tank
|
||||||
|
|
||||||
|
@ -43,7 +46,7 @@ class Pflanzarr:
|
||||||
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 teams.teams:
|
||||||
players.append(p)
|
players.append(p)
|
||||||
|
|
||||||
|
@ -54,23 +57,27 @@ class Pflanzarr:
|
||||||
|
|
||||||
assert len(players) >= 1, "There must be at least one player."
|
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.
|
# The one is added to ensure that there is at least one #default bot.
|
||||||
size = math.sqrt(len(players) + 1)
|
cols = math.sqrt(len(players) + 1)
|
||||||
if int(size) != size:
|
if int(cols) != cols:
|
||||||
size = size + 1
|
cols = cols + 1
|
||||||
|
|
||||||
size = int(size)
|
cols = int(cols)
|
||||||
if size < 2:
|
if cols < 2:
|
||||||
size = 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')
|
players.append('#default')
|
||||||
|
|
||||||
self._tanks = []
|
self._tanks = []
|
||||||
for i in range(size):
|
for i in range(cols):
|
||||||
for j in range(size):
|
for j in range(rows):
|
||||||
startX = i*self.SPACING + self.SPACING/2
|
startX = i*self.SPACING + self.SPACING/2
|
||||||
startY = j*self.SPACING + self.SPACING/2
|
startY = j*self.SPACING + self.SPACING/2
|
||||||
player = random.choice(players)
|
player = random.choice(players)
|
||||||
|
@ -78,7 +85,7 @@ class Pflanzarr:
|
||||||
if player == '#default':
|
if player == '#default':
|
||||||
color = '#a0a0a0'
|
color = '#a0a0a0'
|
||||||
else:
|
else:
|
||||||
color = team.teams[player][1]
|
color = '#%s' % teams.teams[player][1]
|
||||||
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 == '#default':
|
||||||
|
@ -250,7 +257,7 @@ class Pflanzarr:
|
||||||
print tank.name, 'has errors'
|
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')
|
file = open(fileName, 'w')
|
||||||
for error in tank._program.errors:
|
for error in tank._program.errors:
|
||||||
file.write(error)
|
file.write(error)
|
||||||
|
@ -351,6 +358,7 @@ class Pflanzarr:
|
||||||
self._resultsDir = os.path.join(dir, 'results')
|
self._resultsDir = os.path.join(dir, 'results')
|
||||||
self._errorDir = os.path.join(dir, 'errors')
|
self._errorDir = os.path.join(dir, 'errors')
|
||||||
self._imageDir = os.path.join(dir, 'frames')
|
self._imageDir = os.path.join(dir, 'frames')
|
||||||
|
if not os.path.isdir(self._imageDir):
|
||||||
os.mkdir( self._imageDir )
|
os.mkdir( self._imageDir )
|
||||||
self._playerDir = os.path.join(dir, 'ai', 'players')
|
self._playerDir = os.path.join(dir, 'ai', 'players')
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
DATA_PATH = '/var/lib/tanks/'
|
|
@ -54,7 +54,7 @@ h1, h2, h3 {
|
||||||
letter-spacing: -0.05em;
|
letter-spacing: -0.05em;
|
||||||
}
|
}
|
||||||
|
|
||||||
code, pre, .readme {
|
code, pre, .readme, div.errors {
|
||||||
color: #fff;
|
color: #fff;
|
||||||
background-color: #555;
|
background-color: #555;
|
||||||
margin: 1em;
|
margin: 1em;
|
||||||
|
@ -97,3 +97,4 @@ dd {
|
||||||
fieldset * {
|
fieldset * {
|
||||||
margin: 3px;
|
margin: 3px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ except:
|
||||||
print open('head.html').read() % "Documentation"
|
print open('head.html').read() % "Documentation"
|
||||||
print '<BODY>'
|
print '<BODY>'
|
||||||
print '<H1>Pflanzarr Documentation</H1>'
|
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 Program.__doc__
|
||||||
|
|
||||||
print '<H3>Setup Actions:</H3>'
|
print '<H3>Setup Actions:</H3>'
|
||||||
|
|
|
@ -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()
|
|
@ -1,5 +1,5 @@
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<link href="ctf.css" rel="stylesheet" type="text/css">'
|
<link href="ctf.css" rel="stylesheet" type="text/css">
|
||||||
<title>%s</title>"
|
<title>%s</title>
|
||||||
</head>
|
</head>
|
||||||
|
|
|
@ -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>
|
|
@ -3,15 +3,17 @@
|
||||||
import cgitb; cgitb.enable()
|
import cgitb; cgitb.enable()
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
import Config
|
||||||
|
|
||||||
print """Content-Type: text/html\n\n"""
|
print """Content-Type: text/html\n\n"""
|
||||||
print """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">\n\n"""
|
print """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">\n\n"""
|
||||||
head = open('head.html').read() % "Pflanzarr Results"
|
head = open('head.html').read() % "Pflanzarr Results"
|
||||||
print head
|
print head
|
||||||
print "<H1>Results</H1>"
|
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:
|
try:
|
||||||
winner = open(os.path.join('data', 'winner')).read()
|
winner = open(os.path.join(Config.DATA_PATH, 'winner')).read()
|
||||||
except:
|
except:
|
||||||
winner = "No winner yet."
|
winner = "No winner yet."
|
||||||
|
|
||||||
|
@ -19,9 +21,9 @@ print "<H3>Last Winner: ", winner, '<H3>'
|
||||||
print "<H2>Results so far:</H2>"
|
print "<H2>Results so far:</H2>"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
games = os.listdir(os.path.join('data', 'results'))
|
games = os.listdir(os.path.join('results'))
|
||||||
except:
|
except:
|
||||||
print '<p>The data directory does not exist.'
|
print '<p>The results directory does not exist.'
|
||||||
games = []
|
games = []
|
||||||
|
|
||||||
if not games:
|
if not games:
|
||||||
|
@ -30,7 +32,7 @@ gameNums = []
|
||||||
for game in games:
|
for game in games:
|
||||||
try:
|
try:
|
||||||
num = int(game)
|
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 ):
|
if os.path.exists( path ):
|
||||||
gameNums.append( int(num) )
|
gameNums.append( int(num) )
|
||||||
else:
|
else:
|
||||||
|
@ -43,5 +45,5 @@ gameNums.sort(reverse=True)
|
||||||
|
|
||||||
for num in gameNums:
|
for num in gameNums:
|
||||||
print '<p>%d - ' % num,
|
print '<p>%d - ' % num,
|
||||||
print '<a href="data/results/%d/game.avi">v</a>' % num,
|
print '<a href="results/%d/game.avi">v</a>' % num,
|
||||||
print '<a href="data/results/%d/results.html">r</a>' % num
|
print '<a href="results/%d/results.html">r</a>' % num
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
|
@ -4,6 +4,8 @@ import cgi
|
||||||
import cgitb; cgitb.enable()
|
import cgitb; cgitb.enable()
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
import Config
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from urllib.parse import quote
|
from urllib.parse import quote
|
||||||
except:
|
except:
|
||||||
|
@ -16,13 +18,14 @@ except:
|
||||||
path = '/home/pflarr/repos/gctf/'
|
path = '/home/pflarr/repos/gctf/'
|
||||||
sys.path.append(path)
|
sys.path.append(path)
|
||||||
from ctf import teams
|
from ctf import teams
|
||||||
|
teams.build_teams()
|
||||||
|
|
||||||
print """Content-Type: text/html\n\n"""
|
print """Content-Type: text/html\n\n"""
|
||||||
print """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN">\n\n"""
|
print """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN">\n\n"""
|
||||||
head = open('head.html').read() % "Submission Results"
|
head = open('head.html').read() % "Submission Results"
|
||||||
print head
|
print head
|
||||||
print "<H1>Results</H1>"
|
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():
|
def done():
|
||||||
print '</body></html>'
|
print '</body></html>'
|
||||||
|
@ -45,7 +48,7 @@ if team not in teams.teams:
|
||||||
if passwd != teams.teams[team][0]:
|
if passwd != teams.teams[team][0]:
|
||||||
print '<p>Invalid password.'; done()
|
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 = open(path, 'w')
|
||||||
file.write(code)
|
file.write(code)
|
||||||
file.close()
|
file.close()
|
||||||
|
|
|
@ -6,8 +6,11 @@
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<H1>Program Submission</H1>
|
<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">
|
<form action="submit.cgi" method="post">
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>Your program:</legend>
|
<legend>Your program:</legend>
|
||||||
|
|
Loading…
Reference in New Issue