Pull apart run-tanks like it says in README

This commit is contained in:
Neale Pickett 2010-10-26 12:25:27 -06:00
parent 9d474c7c56
commit cc4b71863f
7 changed files with 2359 additions and 185 deletions

View File

@ -25,7 +25,7 @@ summary.html with summary.awk. This is the main interface that you want
to run from cron or whatever.
### run-tanks tank1 tank2 ...
### forftanks tank1 tank2 ...
A program to run a round of tanks and output a JSON description of the
game. This is what tanks.js uses to render a game graphically.
@ -48,7 +48,7 @@ the round to fd3.
### rank.awk
Processes the fd3 output of run-tanks to award points and output an
Processes the fd3 output of forftanks to award points and output an
HTML results table.

260
doc/standie.svg Normal file
View File

@ -0,0 +1,260 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="765"
height="990"
id="svg2"
sodipodi:version="0.32"
inkscape:version="0.46"
version="1.0"
sodipodi:docname="standie.svg"
inkscape:output_extension="org.inkscape.output.svg.inkscape">
<defs
id="defs4">
<inkscape:perspective
sodipodi:type="inkscape:persp3d"
inkscape:vp_x="0 : 526.18109 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_z="744.09448 : 526.18109 : 1"
inkscape:persp3d-origin="372.04724 : 350.78739 : 1"
id="perspective10" />
<inkscape:perspective
sodipodi:type="inkscape:persp3d"
inkscape:vp_x="0 : 526.18109 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_z="744.09448 : 526.18109 : 1"
inkscape:persp3d-origin="372.04724 : 350.78739 : 1"
id="perspective2447" />
<inkscape:perspective
id="perspective2547"
inkscape:persp3d-origin="372.04724 : 350.78739 : 1"
inkscape:vp_z="744.09448 : 526.18109 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_x="0 : 526.18109 : 1"
sodipodi:type="inkscape:persp3d" />
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
gridtolerance="10000"
guidetolerance="10"
objecttolerance="10"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="0.66"
inkscape:cx="545.71983"
inkscape:cy="606.66523"
inkscape:document-units="in"
inkscape:current-layer="layer1"
showgrid="true"
units="in"
inkscape:window-width="1276"
inkscape:window-height="1006"
inkscape:window-x="0"
inkscape:window-y="14"
inkscape:snap-global="false"
borderlayer="false" />
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1">
<g
id="layer4"
inkscape:label="dirtbags"
style="display:none"
transform="translate(-308.19052,44.944851)">
<text
xml:space="preserve"
style="font-size:48px;font-style:normal;font-variant:normal;font-weight:bold;font-stretch:condensed;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Nimbus Sans L;-inkscape-font-specification:Nimbus Sans L Bold Condensed"
x="527.22546"
y="731.11957"
id="text3300"
sodipodi:linespacing="125%"><tspan
sodipodi:role="line"
id="tspan3302"
x="527.22546"
y="731.11957">dirtbags</tspan></text>
</g>
<g
id="layer2"
inkscape:label="dirtbags.net"
style="display:none"
transform="translate(-308.19052,44.944851)">
<text
xml:space="preserve"
style="font-size:40px;font-style:normal;font-variant:normal;font-weight:bold;font-stretch:condensed;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Nimbus Sans L;-inkscape-font-specification:Nimbus Sans L Bold Condensed"
x="502.14645"
y="731.11957"
id="text3308"
sodipodi:linespacing="125%"><tspan
sodipodi:role="line"
id="tspan3310"
x="502.14645"
y="731.11957">dirtbags.net</tspan></text>
</g>
<text
sodipodi:linespacing="125%"
id="text3272"
y="894.32263"
x="-229.31424"
style="font-size:85.50655365px;font-style:normal;font-variant:normal;font-weight:bold;font-stretch:condensed;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Nimbus Sans L;-inkscape-font-specification:Nimbus Sans L Bold Condensed"
xml:space="preserve"><tspan
y="894.32263"
x="-229.31424"
id="tspan3274"
sodipodi:role="line" /></text>
<g
id="g2483"
transform="matrix(0,-0.9774231,0.9774231,0,5.9709151,978.27037)">
<path
style="fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:3.5999999;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="M 175.19167,183.03312 C 99.732022,183.03312 46.463603,265.66131 52.800357,320.35092 C 56.865847,355.43825 78.008194,360.81414 108.70365,417.08914 C 127.30007,451.18262 141.94307,497.65872 117.64249,511.72748 C 93.341942,525.79621 17.896271,564.16873 17.896269,564.16873 L 17.896269,750.91978 L 392.6186,750.91978 C 392.6186,750.91978 396.45354,739.40818 393.89557,715.10762 C 424.77669,716.7579 446.85739,717.6412 479.59505,712.52528 C 525.15994,694.07825 549.93255,679.66041 579.36966,665.22032 C 586.02066,657.5848 597.25139,603.81939 594.6934,580.79784 C 592.17395,558.1228 589.67671,519.32181 578.60346,487.60674 C 578.60523,486.65238 578.5653,485.68637 578.48995,484.71226 C 583.03605,468.05828 584.61872,460.10456 589.58549,443.96246 C 594.70139,427.33576 572.97676,427.32494 578.09266,414.53519 C 583.20858,401.74542 587.02555,410.70345 590.86247,374.89208 C 594.69938,339.08072 580.35658,335.54421 571.67941,322.45083 C 574.54639,311.52442 575.86661,304.97431 559.88904,292.04414 C 552.92295,286.40669 548.09722,283.23692 539.28179,282.73132 C 530.46634,282.22572 518.44848,282.02247 501.82178,280.74349 C 501.9203,280.60593 501.34649,295.16383 501.62962,295.38537 C 501.1379,295.38537 487.00022,274.21015 478.1259,282.12587 C 469.65353,289.68309 487.57316,316.17003 487.57314,315.57621 C 488.13876,315.72398 469.66967,313.89615 468.07386,322.45083 C 466.51084,330.82968 480.49172,333.77589 480.29557,333.97202 C 480.09941,333.38092 467.36345,331.92166 467.8047,342.01817 C 468.28027,352.90038 486.49802,353.60792 486.49804,353.94234 C 477.80286,375.68026 447.51329,446.91776 427.1538,495.09836 C 433.54868,509.16711 491.11623,514.3098 491.11623,514.3098 C 491.11623,514.3098 497.22176,550.95675 482.14901,565.44571 C 461.68536,568.61206 387.11856,559.84576 337.62337,534.76983 C 295.41712,525.81701 274.43981,533.20189 250.64693,528.35656 C 253.43342,502.78719 254.50625,488.71347 254.50625,488.71347 C 254.50625,488.71347 287.76445,483.59435 287.76445,436.27222 C 287.76445,388.95005 308.06176,384.92301 303.08819,359.53996 C 299.0538,338.95007 291.52311,325.95944 307.88395,308.0919 C 320.28738,288.85396 322.27084,259.76896 304.36519,239.30532 C 279.3244,210.68728 250.65133,183.03312 175.19167,183.03312 z M 508.59665,289.73179 C 508.36976,289.94299 516.73247,290.58463 526.13383,291.20742 C 527.15504,298.08777 538.00646,307.78883 544.52232,313.05793 C 543.96514,314.31291 543.39235,315.51947 542.81967,316.7186 L 509.36363,316.1227 C 509.53671,315.72022 508.17637,290.23076 508.59665,289.73179 z M 494.19558,356.2409 C 497.51201,357.87917 503.76241,358.7111 508.5399,359.994 C 502.33706,361.58094 496.89765,361.52792 496.25252,366.66347 C 495.34942,373.85254 510.37662,378.54561 523.65042,382.39909 C 520.09348,383.65623 513.58741,386.65836 513.3008,390.16719 C 512.41608,400.99858 534.84172,405.61532 554.77383,409.55616 C 557.35604,425.88768 560.88468,447.29929 563.79052,464.11035 C 512.71042,459.63287 481.41158,456.69828 449.60023,464.99004 C 463.08015,433.05142 479.50059,390.97818 494.19558,356.2409 z"
id="path3227"
sodipodi:nodetypes="csssccccccsccssscsscczczczcccccccsscscccccccccscscccc" />
<g
transform="matrix(2.1376639,0,0,2.1376639,-775.68918,-222.16264)"
style="display:inline"
inkscape:label="dirtbags rot"
id="layer3">
<text
transform="matrix(0.387016,-0.922073,0.922073,0.387016,0,0)"
sodipodi:linespacing="125%"
id="text3166"
y="615.24457"
x="-90.885483"
style="font-size:34.41987228px;font-style:normal;font-variant:normal;font-weight:bold;font-stretch:condensed;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;display:inline;font-family:Nimbus Sans L;-inkscape-font-specification:Nimbus Sans L Bold Condensed"
xml:space="preserve"><tspan
y="615.24457"
x="-90.885483"
id="tspan3168"
sodipodi:role="line">dirtbags</tspan></text>
</g>
<rect
transform="matrix(-0.7070466,-0.707167,0.707167,-0.7070466,0,0)"
y="373.30301"
x="-700.88867"
height="95.298477"
width="6.1200857"
id="rect3375"
style="fill:none;fill-opacity:1;fill-rule:nonzero;stroke:#ba2b2b;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
<path
transform="matrix(-0.8460474,-0.2204554,0.2204554,-0.8460474,1056.4658,666.60214)"
sodipodi:end="3.144758"
sodipodi:start="0"
d="M 522,526 A 140,140 0 1 1 242.0007,525.55685 L 382,526 z"
sodipodi:ry="140"
sodipodi:rx="140"
sodipodi:cy="526"
sodipodi:cx="382"
id="path2593"
style="fill:none;fill-opacity:1;fill-rule:nonzero;stroke:#2bb6ba;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
sodipodi:type="arc" />
<path
transform="matrix(-0.8460474,-0.2204554,0.2204554,-0.8460474,1056.4658,666.60214)"
sodipodi:type="arc"
style="fill:none;fill-opacity:1;fill-rule:nonzero;stroke:#2bb6ba;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path2595"
sodipodi:cx="382"
sodipodi:cy="526"
sodipodi:rx="149"
sodipodi:ry="149"
d="M 414.70023,380.63255 A 149,149 0 0 1 492.14396,425.65406 L 382,526 z"
sodipodi:start="4.9336547"
sodipodi:end="5.5443022" />
<path
transform="matrix(-0.8460474,-0.2204554,0.2204554,-0.8460474,1056.4658,666.60214)"
sodipodi:end="4.9362896"
sodipodi:start="4.1338205"
d="M 248.57447,321.7119 A 244,244 0 0 1 436.17643,288.09053 L 382,526 z"
sodipodi:ry="244"
sodipodi:rx="244"
sodipodi:cy="526"
sodipodi:cx="382"
id="path2597"
style="fill:none;fill-opacity:1;fill-rule:nonzero;stroke:#2bb6ba;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
sodipodi:type="arc" />
<path
transform="matrix(-0.8460474,-0.2204554,0.2204554,-0.8460474,1056.4658,666.60214)"
sodipodi:type="arc"
style="fill:none;fill-opacity:1;fill-rule:nonzero;stroke:#2bb6ba;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path2599"
sodipodi:cx="382"
sodipodi:cy="526"
sodipodi:rx="244"
sodipodi:ry="244"
d="M 562.30536,361.60421 A 244,244 0 0 1 625.94232,520.69476 L 382,526 z"
sodipodi:start="5.5439091"
sodipodi:end="6.2614408" />
<rect
transform="matrix(-0.9676424,-0.2523255,0.2523255,-0.9676424,0,0)"
y="57.387951"
x="-879.38464"
height="55.677361"
width="44.228729"
id="rect2383"
style="fill:#ffffff;fill-opacity:1;fill-rule:evenodd;stroke:#2bb6ba;stroke-width:0.96922117px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
<rect
transform="matrix(-0.9676424,-0.2523255,0.2523255,-0.9676424,0,0)"
y="40.170197"
x="-835.15601"
height="84.308083"
width="27.064905"
id="rect2385"
style="fill:#ffffff;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:0.96357071px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
<rect
transform="matrix(-0.9676424,-0.2523255,0.2523255,-0.9676424,0,0)"
style="fill:#ffffff;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:0.96357071px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
id="rect2387"
width="27.064905"
height="84.308083"
x="-906.44958"
y="40.170197" />
<rect
inkscape:transform-center-y="-20.587678"
inkscape:transform-center-x="-11.779977"
transform="matrix(-0.7129456,-0.7012194,0.7012194,-0.7129456,0,0)"
y="446.83466"
x="-708.03717"
height="57.243172"
width="11.448635"
id="rect3159"
style="fill:#ffffff;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
<path
transform="matrix(-0.8068409,-0.3367557,0.3367557,-0.8068409,964.03209,766.69774)"
d="M 475,391 L 480.97412,428.65667 L 518.98424,425.66578 L 493.26788,453.81509 L 519.30517,481.66781 L 481.26326,479.11275 L 475.72111,516.83541 L 454,485.5 L 421.05176,504.68667 L 432.00788,468.16711 L 396.46425,454.36983 L 431.84742,440.1661 L 420.47347,403.7745 L 453.63944,422.58229 L 475,391 z"
inkscape:randomized="0"
inkscape:rounded="0"
inkscape:flatsided="false"
sodipodi:arg2="-0.90332843"
sodipodi:arg1="-1.3521274"
sodipodi:r2="32.268406"
sodipodi:r1="64.536812"
sodipodi:cy="454"
sodipodi:cx="461"
sodipodi:sides="7"
id="path2591"
style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:#494b0e;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
sodipodi:type="star" />
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 14 KiB

1897
doc/token.svg Normal file

File diff suppressed because it is too large Load Diff

After

Width:  |  Height:  |  Size: 118 KiB

80
rank.awk Executable file
View File

@ -0,0 +1,80 @@
#! /usr/bin/awk -f
BEGIN {
FS = "\t";
}
function esc(s) {
gsub(/&/, "&amp;", s);
gsub(/</, "&lt;", s);
gsub(/>/, "&gt;", s);
return s;
}
{
id = $1;
ntanks += 1;
tanks[id] = id;
if ($4 == "(nil)") {
score[id] += 1;
} else {
reason[id] = $3;
killer[id] = $4;
kills[$4] += 1;
score[$4] += 1;
}
path[id] = $2;
if ($5) {
lasterr[id] = $6 " around char " $5;
} else {
lasterr[id] = $6;
}
if (1 == getline < (path[id] "/name")) {
name[id] = esc($0);
} else {
name[id] = "<i>Unnamed</i>";
}
getline < (path[id] "/color");
if (/^#[0-9A-Fa-f]+$/) {
color[id] = $0;
} else {
color[id] = "#c0c0c0";
}
}
END {
# Fill in who killed whom
for (id in tanks) {
if (score[id] > topscore) {
winner = id;
topscore = score[id];
}
if (killer[id]) {
reason[id] = reason[id] " (" name[killer[id]] ")";
}
}
# Output the table
print "<table id=\"results\">";
print "<tr><th>Name</th><th>Score</th><th>Cause of Death</th><th>Last Error</th></tr>";
for (i = ntanks; i >= 0; i -= 1) {
for (me in tanks) {
if (score[me] == i) {
if (me == winner) {
style = "style=\"font-weight: bold; background-color: #666666\"";
} else {
style = "";
}
printf("<tr " style ">");
printf("<td><span class=\"swatch\" style=\"background-color: " color[me] "\">#</span> " name[me] "</td>");
printf("<td>" score[me] "</td>");
printf("<td>" reason[me] "</td>");
printf("<td>" lasterr[me] "</td>");
printf("</tr>\n");
}
}
}
print "</table>";
}

188
run-tanks
View File

@ -4,193 +4,15 @@ if [ "$#" -gt 0 ]; then
tanks="$@"
else
echo "Usage: $0 tank1 tank2 [...]"
echo "Writes ./next-round and ./summary.html"
exit 1
fi
TANKS_GAME=${TANKS_GAME:-forftanks}
NAV_HTML_INC=${NAV_HTML_INC:-./nav.html.inc} export NAV_HTML_INC
rank () {
awk 'BEGIN {
FS = "\t";
}
function esc(s) {
gsub(/&/, "&amp;", s);
gsub(/</, "&lt;", s);
gsub(/>/, "&gt;", s);
return s;
}
{
id = $1;
ntanks += 1;
tanks[id] = id;
if ($4 == "(nil)") {
score[id] += 1;
} else {
reason[id] = $3;
killer[id] = $4;
kills[$4] += 1;
score[$4] += 1;
}
path[id] = $2;
if ($5) {
lasterr[id] = $6 " around char " $5;
} else {
lasterr[id] = $6;
}
if (1 == getline < (path[id] "/name")) {
name[id] = esc($0);
} else {
name[id] = "<i>Unnamed</i>";
}
getline < (path[id] "/color");
if (/^#[0-9A-Fa-f]+$/) {
color[id] = $0;
} else {
color[id] = "#c0c0c0";
}
}
END {
# Fill in who killed whom
for (id in tanks) {
if (score[id] > topscore) {
winner = id;
topscore = score[id];
}
if (killer[id]) {
reason[id] = reason[id] " (" name[killer[id]] ")";
}
print score[id] >> (path[id] "/points");
}
# Dole out points
# Output the table
print "<table id=\"results\">";
print "<tr><th>Name</th><th>Score</th><th>Cause of Death</th><th>Last Error</th></tr>";
for (i = ntanks; i >= 0; i -= 1) {
for (me in tanks) {
if (score[me] == i) {
if (me == winner) {
style = "style=\"font-weight: bold; background-color: #666666\"";
} else {
style = "";
}
printf("<tr " style ">");
printf("<td><span class=\"swatch\" style=\"background-color: " color[me] "\">#</span> " name[me] "</td>");
printf("<td>" score[me] "</td>");
printf("<td>" reason[me] "</td>");
printf("<td>" lasterr[me] "</td>");
printf("</tr>\n");
}
}
}
print "</table>";
}
' "$@"
}
summary () {
awk 'function esc(s) {
gsub(/&/, "&amp;", s);
gsub(/</, "&lt;", s);
gsub(/>/, "&gt;", s);
return s;
}
BEGIN {
ngames = 20;
print "<!DOCTYPE html>";
print "<html>";
print " <head>";
print " <title>Dirtbags Tanks</title>";
print " <link rel=\"stylesheet\" href=\"dirtbags.css\" type=\"text/css\">";
print " </head>";
print " <body>";
print " <h1>Dirtbags Tanks</h1>";
print " <p>New here? Read the <a href=\"intro.html\">introduction</a>.</p>";
print " <p>New round every minute.</p>";
print " <h2>Rankings</h2>";
print " <p>Over the last 20 games only.</p>";
print " <ol>";
for (i = 1; i < ARGC; i += 1) {
id = ARGV[i];
if (1 == getline < (id "/name")) {
names[id] = esc($0);
} else {
names[id] = "<i>Unnamed</i>";
}
getline < (id "/color");
if (/^#[0-9A-Fa-f]+$/) {
color[id] = $0;
} else {
color[id] = "#c0c0c0";
}
for (j = 0; 1 == getline < (id "/points"); j += 1) {
pts[id, j % ngames] = int($0);
}
total = 0;
for (j = 0; j < ngames; j += 1) {
total += pts[id, j];
}
scores[total] = total;
points[id] = total;
}
while (1) {
# Find highest score
maxscore = -1;
for (p in scores) {
if (int(p) > maxscore) {
maxscore = int(p);
}
}
if (maxscore == -1) {
break;
}
delete scores[maxscore];
for (id in points) {
if (points[id] == maxscore) {
printf("<li><span class=\"swatch\" style=\"background-color: %s;\">#</span> %s (%d points)</li>\n", color[id], names[id], points[id]);
}
}
}
print " </ol>";
print " <h2>Rounds</h2>";
print " <ul>";
getline rounds < "next-round";
for (i = rounds - 1; i >= 0; i -= 1) {
printf("<li><a href=\"round-%04d.html\">%04d</a></li>\n", i, i);
}
print " </ul>";
while (getline < ENVIRON["NAV_HTML_INC"]) {
print;
}
print " </body>";
print "</html>";
}
' "$@"
}
# Add wherever this lives to the search path
PATH=$PATH:$(dirname $0)
if [ -f next-round ]; then
next=$(cat next-round)
@ -229,7 +51,7 @@ window.onload = go;
<div id="game_box"><canvas id="battlefield"></canvas></div>
<p><span id="fps">0</span> fps</p>
EOF
rank $rfn >>$fn
rank.awk $rfn >>$fn
rm -f $rfn
cat $NAV_HTML_INC >>$fn
cat <<EOF >>$fn
@ -237,7 +59,7 @@ cat <<EOF >>$fn
</html>
EOF
summary $tanks > summary.html.$$
summary.awk $tanks > summary.html.$$
mv summary.html.$$ summary.html
echo "done."

89
summary.awk Executable file
View File

@ -0,0 +1,89 @@
#! /usr/bin/awk -f
function esc(s) {
gsub(/&/, "&amp;", s);
gsub(/</, "&lt;", s);
gsub(/>/, "&gt;", s);
return s;
}
BEGIN {
ngames = 20;
print "<!DOCTYPE html>";
print "<html>";
print " <head>";
print " <title>Dirtbags Tanks</title>";
print " <link rel=\"stylesheet\" href=\"dirtbags.css\" type=\"text/css\">";
print " </head>";
print " <body>";
print " <h1>Dirtbags Tanks</h1>";
print " <p>New here? Read the <a href=\"intro.html\">introduction</a>.</p>";
print " <p>New round every minute.</p>";
print " <h2>Rankings</h2>";
print " <p>Over the last 20 games only.</p>";
print " <ol>";
for (i = 1; i < ARGC; i += 1) {
id = ARGV[i];
if (1 == getline < (id "/name")) {
names[id] = esc($0);
} else {
names[id] = "<i>Unnamed</i>";
}
getline < (id "/color");
if (/^#[0-9A-Fa-f]+$/) {
color[id] = $0;
} else {
color[id] = "#c0c0c0";
}
for (j = 0; 1 == getline < (id "/points"); j += 1) {
pts[id, j % ngames] = int($0);
}
total = 0;
for (j = 0; j < ngames; j += 1) {
total += pts[id, j];
}
scores[total] = total;
points[id] = total;
}
while (1) {
# Find highest score
maxscore = -1;
for (p in scores) {
if (int(p) > maxscore) {
maxscore = int(p);
}
}
if (maxscore == -1) {
break;
}
delete scores[maxscore];
for (id in points) {
if (points[id] == maxscore) {
printf("<li><span class=\"swatch\" style=\"background-color: %s;\">#</span> %s (%d points)</li>\n", color[id], names[id], points[id]);
}
}
}
print " </ol>";
print " <h2>Rounds</h2>";
print " <ul>";
getline rounds < "next-round";
for (i = rounds - 1; i >= 0; i -= 1) {
printf("<li><a href=\"round-%04d.html\">%04d</a></li>\n", i, i);
}
print " </ul>";
while (getline < ENVIRON["NAV_HTML_INC"]) {
print;
}
print " </body>";
print "</html>";
}

26
winners.awk Normal file
View File

@ -0,0 +1,26 @@
#! /usr/bin/awk -f
BEGIN {
FS = "\t";
}
{
tanks[$1] = $1;
if ($4 == "(nil)") {
p = $1;
} else {
p = $4;
}
score[p] += 1;
if (score[p] > topscore) {
topscore = score[p];
}
}
END {
for (id in tanks) {
if (score[id] == topscore) {
print id;
}
}
}