mirror of https://github.com/dirtbags/tanks.git
Rework for github jekyll hosting
This commit is contained in:
parent
502e67df45
commit
73344df0e6
154
README.md
154
README.md
|
@ -1,151 +1,19 @@
|
||||||
CTanks
|
Tanks
|
||||||
======
|
======
|
||||||
|
|
||||||
This is a programming game, inspired by Crobots by Tom Poindexter
|
Dirtbags Tanks is a game in which you pit your coding abilities
|
||||||
(http://www.nyx.net/~tpoindex/crob.html). Players write programs for
|
against other hackers. You write a program for your tank, set it out
|
||||||
tanks, with the intent to seek out and destroy other tanks.
|
on the battlefield, and watch how your program fares against tanks
|
||||||
|
written by other players. Dirtbags Tanks is frequently a component of
|
||||||
Output is a JSON object, and some scripts are provided to wrap the
|
[Dirtbags Capture The Flag](/ctf/).
|
||||||
object up in a web page.
|
|
||||||
|
|
||||||
|
|
||||||
Included programs
|
Documentation
|
||||||
-----------------
|
-------------
|
||||||
|
|
||||||
I tried to stick with the Unix philosophy of one program per task. I
|
* [Homepage](https://dirtbags.github.io/tanks/)
|
||||||
also tried to avoid doing any string processing in C. The result is a
|
* [History](doc/history.md)
|
||||||
hodgepodge of C, Bourne shell, and awk, but at least each piece is
|
* [Running](doc/running.md)
|
||||||
fairly simple to audit.
|
|
||||||
|
|
||||||
|
|
||||||
### round.sh tank1 tank2 ...
|
|
||||||
|
|
||||||
Runs a single round, awards points with rank.awk, and creates a new
|
|
||||||
summary.html with summary.awk. This is the main interface that you want
|
|
||||||
to run from cron or whatever.
|
|
||||||
|
|
||||||
|
|
||||||
### 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.
|
|
||||||
The object printed contains:
|
|
||||||
|
|
||||||
[[game-width, game-height],
|
|
||||||
[[tank1-color,
|
|
||||||
[[sensor1range, sensor1angle, sensor1width, sensor1turret],
|
|
||||||
...]],
|
|
||||||
...],
|
|
||||||
[[
|
|
||||||
[tank1x, tank1y, tank1angle, tank1sensangle,
|
|
||||||
tank1flags, tank1sensors],
|
|
||||||
...],
|
|
||||||
...]]
|
|
||||||
|
|
||||||
If file descriptor 3 is open for writes, it also outputs the results of
|
|
||||||
the round to fd3.
|
|
||||||
|
|
||||||
|
|
||||||
### rank.awk
|
|
||||||
|
|
||||||
Processes the fd3 output of forftanks to award points and output an
|
|
||||||
HTML results table.
|
|
||||||
|
|
||||||
|
|
||||||
### summary.awk tank1 tank2
|
|
||||||
|
|
||||||
Creates summary.html, linking to all rounds and showing overall
|
|
||||||
standing.
|
|
||||||
|
|
||||||
|
|
||||||
### designer.cgi
|
|
||||||
|
|
||||||
Accepts form input and writes a tank.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Building from source
|
|
||||||
--------------------
|
|
||||||
|
|
||||||
You should be able to just run "make". The C is supposedly ANSI C, and
|
|
||||||
might even compile on Windows. I've built it on Linux, with glibc and
|
|
||||||
uClibc, big- and little-endian.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
History
|
|
||||||
-------
|
|
||||||
|
|
||||||
This is a port of the "Tanks" program written by Paul Ferrell
|
|
||||||
<pflarr@clanspum.net> in 2009-2010. Paul created the entire game based
|
|
||||||
off a brief description I provided him of Crobots and a vague desire to
|
|
||||||
"make something fun for high school kids to learn some programming." We
|
|
||||||
ran Paul's Tanks as part of a 100-attendee computer security contest in
|
|
||||||
February of 2010 and by all accounts it was a huge success. It even
|
|
||||||
made the nightly news.
|
|
||||||
|
|
||||||
Paul's version was written in Python and provided a custom language
|
|
||||||
called "Bullet", which looked like this:
|
|
||||||
|
|
||||||
>addsensor(50, 0, 5, 1); # 0
|
|
||||||
>addsensor(100, 90, 150, 1); # 1
|
|
||||||
>addsensor(100, 270, 150, 1); # 2
|
|
||||||
>addsensor(100, 0, 359, 0); # 3
|
|
||||||
|
|
||||||
# Default movement if nothing is detected
|
|
||||||
: move(70, 70) . turretccw();
|
|
||||||
random(2, 3): move(40, 70) . turretccw();
|
|
||||||
random(1, 3): move(70, 40) . turretccw();
|
|
||||||
|
|
||||||
# We found something!!
|
|
||||||
sense(3): move(0, 0);
|
|
||||||
sense(1): turretcw();
|
|
||||||
sense(2): turretccw();
|
|
||||||
sense(0): fire();
|
|
||||||
|
|
||||||
Nick Moffitt played with this original version and convinced me (Neale)
|
|
||||||
that something like Forth would be a better language. I added some code
|
|
||||||
to accept a scaled-down version of PostScript. The IRC channel we
|
|
||||||
frequent collectively agreed to give this new language the derisive name
|
|
||||||
"Forf", which should ideally be followed by punching someone after it is
|
|
||||||
spoken aloud. I wrote a Python implementation of Forf, which was slow,
|
|
||||||
and then Adam Glasgall wrote a C implementation, which was quick.
|
|
||||||
|
|
||||||
I decided to take Tanks to Def Con in July 2010, and just for bragging
|
|
||||||
rights, to have it run on an Asus WL-500gU. This is a $50 device with a
|
|
||||||
240 MHz MIPS CPU, 16MB RAM, and a 4MB flash disk, along with an
|
|
||||||
802.11b/g radio, 4-port 10/100 switch, and an additional 10/100 "uplink"
|
|
||||||
port; it's sold as a home wireless router. I had originally intended to
|
|
||||||
run it off a lantern battery just for fun, but eventually thought better
|
|
||||||
of it: doing so would be wasteful for no good reason.
|
|
||||||
|
|
||||||
Aaron McPhall <amcphall@mcphall.org>, my summer intern at the time, got
|
|
||||||
OpenWRT and Python onto the box and benchmarked it at about 60 seconds
|
|
||||||
for a 16-tank game, after he had profiled the code and optimized a lot
|
|
||||||
of the math. That wasn't bad, it meant we could run a reasonably-sized
|
|
||||||
game at one turn per minute, which we knew from past experience was
|
|
||||||
about the right rate. But it required a USB thumb drive to hold Python,
|
|
||||||
and when we used the Python Forf implementation, the run-time shot up to
|
|
||||||
several minutes. I began this C port while Adam Glasgall, another fool
|
|
||||||
on the previously-mentioned IRC channel, started work on a C version of
|
|
||||||
a Forf interpreter.
|
|
||||||
|
|
||||||
This C version with Forf runs about 6 times faster than the Python
|
|
||||||
version with Bullet, on the WL-500gU. A 1GHz Intel Atom runs a 16-tank
|
|
||||||
game in about 0.2 seconds.
|
|
||||||
|
|
||||||
|
|
||||||
What's so great about Forf?
|
|
||||||
---------------------------
|
|
||||||
|
|
||||||
Nothing's great about Forf. It's a crummy language that only does
|
|
||||||
integer math. For this application it's a good choice, for the
|
|
||||||
following reasons:
|
|
||||||
|
|
||||||
* No library dependencies, not even malloc
|
|
||||||
* Runs in fixed size memory
|
|
||||||
* Not Turing-complete, I think (impossible to make endless loops)
|
|
||||||
* Lends itself to genetic algorithms
|
|
||||||
|
|
||||||
|
|
||||||
Author
|
Author
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
History
|
History
|
||||||
=======
|
-------
|
||||||
|
|
||||||
This is a port of the "Tanks" program written by Paul Ferrell
|
This is a port of the "Tanks" program written by Paul Ferrell
|
||||||
<pflarr@clanspum.net> in 2009-2010. Paul created the entire game based
|
<pflarr@clanspum.net> in 2009-2010. Paul created the entire game based
|
||||||
off a brief description I provided him of Crobots and a vague desire to
|
off a brief description I provided him of
|
||||||
|
[Crobots](http://tpoindex.github.io/crobots)
|
||||||
|
and a vague desire to
|
||||||
"make something fun for high school kids to learn some programming." We
|
"make something fun for high school kids to learn some programming." We
|
||||||
ran Paul's Tanks as part of a 100-attendee computer security contest in
|
ran Paul's Tanks as part of a 100-attendee computer security contest in
|
||||||
February of 2010 and by all accounts it was a huge success. It even
|
February of 2010 and by all accounts it was a huge success. It even
|
||||||
|
@ -33,7 +35,8 @@ that something like Forth would be a better language. I added some code
|
||||||
to accept a scaled-down version of PostScript. The IRC channel we
|
to accept a scaled-down version of PostScript. The IRC channel we
|
||||||
frequent collectively agreed to give this new language the derisive name
|
frequent collectively agreed to give this new language the derisive name
|
||||||
"Forf", which should ideally be followed by punching someone after it is
|
"Forf", which should ideally be followed by punching someone after it is
|
||||||
spoken aloud.
|
spoken aloud. I wrote a Python implementation of Forf, which was slow,
|
||||||
|
and then Adam Glasgall wrote a C implementation, which was quick.
|
||||||
|
|
||||||
I decided to take Tanks to Def Con in July 2010, and just for bragging
|
I decided to take Tanks to Def Con in July 2010, and just for bragging
|
||||||
rights, to have it run on an Asus WL-500gU. This is a $50 device with a
|
rights, to have it run on an Asus WL-500gU. This is a $50 device with a
|
||||||
|
@ -70,4 +73,3 @@ following reasons:
|
||||||
* Runs in fixed size memory
|
* Runs in fixed size memory
|
||||||
* Not Turing-complete, I think (impossible to make endless loops)
|
* Not Turing-complete, I think (impossible to make endless loops)
|
||||||
* Lends itself to genetic algorithms
|
* Lends itself to genetic algorithms
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
---
|
||||||
|
title: Tanks
|
||||||
|
---
|
||||||
|
|
||||||
|
<table class="figure">
|
||||||
|
<caption>"Ant Lion" nails "Rabbit With Gun".</caption>
|
||||||
|
<tr><td>
|
||||||
|
<canvas id="antlion"></canvas>
|
||||||
|
<script type="application/javascript" src="tanks.js"></script>
|
||||||
|
<script type="application/javascript">
|
||||||
|
antlion = [[300, 150, 50],[["#808080",[[50, 0.00, 0.00, 1],[70, 0.00, 0.87, 0],]], ["#ff8844",[[50, 0.00, 0.09, 1],[100, 4.68, 3.09, 1],[100, 1.61, 3.11, 1],[60, 0.00, 2.09, 0],[60, 2.09, 2.09, 0],[60, 4.19, 2.09, 0],[100, 0.00, 0.09, 1],]],],[[[75,75,5.78,2.71,0,0], [225,75,3.28,1.95,0,0],], [[77,73,5.78,3.02,0,0], [225,75,3.28,2.06,0,0],], [[81,71,5.78,3.14,0,0], [225,75,3.28,2.16,0,0],], [[87,68,5.78,3.14,0,0], [225,75,3.28,2.25,0,0],], [[93,64,5.78,3.14,0,0], [225,75,3.28,2.34,0,0],], [[99,61,5.78,3.14,0,0], [225,75,3.28,2.44,0,0],], [[105,57,5.78,3.14,0,0], [225,75,3.28,2.53,0,0],], [[112,54,5.78,3.14,0,0], [225,75,3.28,2.62,0,0],], [[118,51,5.78,3.14,0,0], [225,75,3.28,2.71,0,0],], [[124,47,5.78,3.14,0,0], [225,75,3.28,2.79,0,2],], [[130,44,5.78,3.14,0,0], [225,75,3.28,2.48,0,2],], [[136,40,5.78,3.14,0,0], [225,75,3.28,2.16,0,2],], [[142,37,5.78,3.14,0,0], [225,75,3.28,1.85,0,2],], [[148,34,5.78,3.14,0,0], [225,75,3.28,1.54,0,2],], [[154,30,5.78,3.14,0,0], [225,75,3.28,1.22,0,2],], [[160,28,5.90,3.14,0,0], [225,75,3.28,0.91,0,2],], [[167,25,5.90,3.14,0,0], [225,75,3.28,0.59,0,70],], [[173,23,5.90,3.14,0,0], [225,75,3.28,0.28,0,4],], [[180,20,5.90,3.14,0,0], [225,75,3.28,0.59,0,68],], [[186,17,5.90,3.14,0,0], [225,75,3.28,0.28,0,4],], [[193,15,5.90,3.14,0,0], [225,75,3.28,0.59,0,4],], [[199,12,5.90,3.14,0,0], [225,75,3.28,0.91,0,92],], [[206,10,5.90,3.14,0,0], [222,74,3.24,0.59,0,20],], [[212,7,5.90,3.14,0,0], [218,74,3.15,0.91,0,20],], [[218,4,5.78,3.14,0,0], [212,75,2.96,1.22,0,4],], [[224,1,5.78,3.14,0,0], [208,77,2.77,1.54,0,2],], [[230,147,5.78,3.14,0,0], [207,78,2.65,1.22,0,2],], [[236,144,5.78,3.14,0,0], [207,78,2.65,0.91,0,2],], [[242,140,5.78,3.14,0,0], [207,78,2.65,0.59,0,2],], [[248,137,5.78,3.14,0,0], [207,78,2.65,0.28,0,2],], [[254,134,5.78,3.14,0,0], [207,78,2.65,-0.03,0,2],], [[260,130,5.78,3.14,0,0], [207,78,2.65,-0.35,0,2],], [[267,127,5.78,3.14,0,0], [207,78,2.65,-0.66,0,2],], [[273,123,5.78,3.14,0,0], [207,78,2.65,-0.98,0,2],], [[279,120,5.78,3.14,0,0], [207,78,2.65,-1.29,0,2],], [[285,117,5.78,3.14,0,0], [207,78,2.65,-1.61,0,2],], [[291,113,5.78,3.14,0,0], [207,78,2.65,-1.92,0,2],], [[297,110,5.78,3.14,0,0], [207,78,2.65,-2.23,0,66],], [[3,106,5.78,3.14,0,0], [207,78,2.65,-1.92,0,2],], [[9,103,5.78,3.14,0,0], [207,78,2.65,-2.23,0,2],], [[16,100,5.78,3.14,0,0], [207,78,2.65,-2.55,0,0],], [[22,96,5.78,3.14,0,0], [207,78,2.65,-2.44,0,0],], [[28,93,5.78,3.14,0,0], [207,78,2.65,-2.32,0,0],], [[34,90,5.78,3.14,0,0], [207,78,2.65,-2.20,0,0],], [[40,86,5.78,3.14,0,0], [207,78,2.65,-2.08,0,0],], [[46,84,5.90,3.14,0,0], [207,78,2.65,-1.95,0,0],], [[52,81,5.90,3.14,0,0], [207,78,2.65,-1.85,0,0],], [[59,79,5.90,3.14,0,0], [207,78,2.65,-1.75,0,0],], [[65,76,5.90,3.14,0,0], [207,78,2.65,-1.64,0,0],], [[72,73,5.90,3.14,0,0], [207,78,2.65,-1.54,0,0],], [[78,71,5.90,3.14,0,0], [207,78,2.65,-1.43,0,0],], [[85,68,5.90,3.14,0,0], [207,78,2.65,-1.33,0,0],], [[91,66,5.90,3.14,0,0], [207,78,2.65,-1.20,0,0],], [[98,63,5.90,3.14,0,0], [207,78,2.65,-1.08,0,0],], [[104,60,5.90,3.14,0,0], [207,78,2.65,-0.96,0,4],], [[111,58,5.90,3.14,0,0], [207,78,2.65,-0.65,0,4],], [[117,56,6.03,3.14,0,0], [207,78,2.65,-0.33,0,4],], [[124,54,6.03,3.14,0,0], [207,78,2.65,-0.02,0,4],], [[130,53,6.03,3.14,0,0], [207,78,2.65,0.30,0,4],], [[137,51,6.03,3.14,0,0], [207,78,2.65,0.61,0,4],], [[144,49,6.03,3.14,0,0], [207,78,2.65,0.93,0,70],], [[151,47,6.03,3.14,0,0], [207,78,2.65,0.61,0,28],], [[157,45,6.03,3.14,0,0], [205,79,2.65,0.93,0,28],], [0, [201,81,2.56,1.24,1,85],],]];
|
||||||
|
start("antlion", antlion);
|
||||||
|
</script>
|
||||||
|
</td></tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
Dirtbags Tanks is a game in which you pit your coding abilities
|
||||||
|
against other hackers. You write a program for your tank, set it out
|
||||||
|
on the battlefield, and watch how your program fares against tanks
|
||||||
|
written by other players. Dirtbags Tanks is frequently a component of
|
||||||
|
[Dirtbags Capture The Flag](/ctf/).
|
||||||
|
|
||||||
|
Each tank has a turret-mounted laser, two treads, up to ten sensors,
|
||||||
|
and a diagnostic LED. Sensors are used to detect when other tanks are
|
||||||
|
inside a given arc. In the examples on this page, "triggered" sensors
|
||||||
|
turn black. Most tanks will take some action if a sensor is
|
||||||
|
triggered, such as changing speed of the treads, turning the turret,
|
||||||
|
or firing.
|
||||||
|
|
||||||
|
Tanks are programmed in Forf, a stack-based language similar to
|
||||||
|
PostScript.
|
||||||
|
|
||||||
|
|
||||||
|
Other Versions
|
||||||
|
--------------
|
||||||
|
|
||||||
|
Everybody loves tanks!
|
||||||
|
If you've made a port or done something fun with it,
|
||||||
|
please let me know and I'll link it here!
|
||||||
|
|
||||||
|
* [Class Lab](https://github.com/Arctem/nmt_python_labs/tree/master/labs/project) at New Mexico Tech, by Russell White
|
||||||
|
|
||||||
|
|
||||||
|
Author
|
||||||
|
------
|
||||||
|
|
||||||
|
Neale Pickett <neale@woozle.org>
|
|
@ -0,0 +1,73 @@
|
||||||
|
---
|
||||||
|
title: Running Tanks
|
||||||
|
---
|
||||||
|
|
||||||
|
Unfortunately, it's kind of a mess right now.
|
||||||
|
I know there are a few forks of this code,
|
||||||
|
and I would love it if someone proposed a merge to clearly illustrate how to run tanks.
|
||||||
|
|
||||||
|
When I spin up a new tanks game,
|
||||||
|
typically I run something like:
|
||||||
|
|
||||||
|
while sleep 60; do ./round.sh */; done
|
||||||
|
|
||||||
|
This assumes all your tanks directories are in the same place as `round.sh`.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Included programs
|
||||||
|
-----------------
|
||||||
|
|
||||||
|
I tried to stick with the Unix philosophy of one program per task. I
|
||||||
|
also tried to avoid doing any string processing in C. The result is a
|
||||||
|
hodgepodge of C, Bourne shell, and awk, but at least each piece is
|
||||||
|
fairly simple to audit.
|
||||||
|
|
||||||
|
|
||||||
|
### round.sh tank1 tank2 ...
|
||||||
|
|
||||||
|
Runs a single round, awards points with rank.awk, and creates a new
|
||||||
|
summary.html with summary.awk. This is the main interface that you want
|
||||||
|
to run from cron or whatever.
|
||||||
|
|
||||||
|
|
||||||
|
### 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.
|
||||||
|
The object printed contains:
|
||||||
|
|
||||||
|
[[game-width, game-height],
|
||||||
|
[[tank1-color,
|
||||||
|
[[sensor1range, sensor1angle, sensor1width, sensor1turret],
|
||||||
|
...]],
|
||||||
|
...],
|
||||||
|
[[
|
||||||
|
[tank1x, tank1y, tank1angle, tank1sensangle,
|
||||||
|
tank1flags, tank1sensors],
|
||||||
|
...],
|
||||||
|
...]]
|
||||||
|
|
||||||
|
If file descriptor 3 is open for writes, it also outputs the results of
|
||||||
|
the round to fd3.
|
||||||
|
|
||||||
|
|
||||||
|
### rank.awk
|
||||||
|
|
||||||
|
Processes the fd3 output of forftanks to award points and output an
|
||||||
|
HTML results table.
|
||||||
|
|
||||||
|
|
||||||
|
### summary.awk tank1 tank2
|
||||||
|
|
||||||
|
Creates summary.html, linking to all rounds and showing overall
|
||||||
|
standing.
|
||||||
|
|
||||||
|
|
||||||
|
### designer.cgi
|
||||||
|
|
||||||
|
Accepts form input and writes a tank.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue