tanks/run-tanks

72 lines
1.4 KiB
Plaintext
Raw Normal View History

2010-07-27 13:17:44 -06:00
#! /bin/sh
if [ "$#" -gt 0 ]; then
tanks="$@"
else
echo "Usage: $0 tank1 tank2 [...]"
echo "Writes ./next-round and ./summary.html"
2010-07-27 13:17:44 -06:00
exit 1
fi
2010-07-27 18:08:24 -06:00
TANKS_GAME=${TANKS_GAME:-forftanks}
2010-07-27 13:17:44 -06:00
NAV_HTML_INC=${NAV_HTML_INC:-./nav.html.inc} export NAV_HTML_INC
# Add wherever this lives to the search path
PATH=$PATH:$(dirname $0)
2010-07-27 13:17:44 -06:00
if [ -f next-round ]; then
next=$(cat next-round)
else
next=0
fi
expr $next + 1 > next-round
fn=$(printf "round-%04d.html" $next)
rfn=results$$.txt
2014-07-28 11:22:00 -06:00
# Clean up old games
2014-07-28 14:42:49 -06:00
ofn=$(printf "round-%04d.html" $(expr $next - 720))
2014-07-28 11:22:00 -06:00
echo "Removing $ofn"
rm -f $ofn
2010-07-27 13:17:44 -06:00
echo -n "Running round $next... "
cat <<EOF >$fn
<!DOCTYPE html>
<html>
<head>
<title>Tanks Round $next</title>
<script type="application/javascript" src="tanks.js"></script>
<link rel="stylesheet" href="style.css" type="text/css">
2010-07-27 13:17:44 -06:00
<script type="application/javascript">
function go() {
start("battlefield",
// Start JSON data
EOF
$TANKS_GAME $tanks >>$fn 3>$rfn
cat <<EOF >>$fn
// end JSON data
);
}
window.onload = go;
</script>
</head>
<body>
<h1>Tanks Round $next</h1>
<div id="game_box"><canvas id="battlefield"></canvas></div>
<p><span id="fps">0</span> fps</p>
EOF
rank.awk $rfn >>$fn
2010-07-27 13:17:44 -06:00
rm -f $rfn
cat $NAV_HTML_INC >>$fn
cat <<EOF >>$fn
</body>
</html>
EOF
summary.awk $tanks > summary.html.$$
2010-07-27 13:17:44 -06:00
mv summary.html.$$ summary.html
echo "done."