Neale Pickett
·
2024-12-05
history.md
1---
2title: History
3scripts:
4 - assets/js/tanks.js
5 - assets/js/figures.js
6---
7
8This is a port of the "Tanks" program written by Paul Ferrell
9<pflarr@clanspum.net> in 2009-2010. Paul created the entire game based
10off a brief description I provided him of
11[Crobots](http://tpoindex.github.io/crobots)
12and a vague desire to
13"make something fun for high school kids to learn some programming." We
14ran Paul's Tanks as part of a 100-attendee computer security contest in
15February of 2010 and by all accounts it was a huge success. It even
16made the nightly news.
17
18Paul's version was written in Python and provided a custom language
19called "Bullet", which looked like this:
20
21 >addsensor(50, 0, 5, 1); # 0
22 >addsensor(100, 90, 150, 1); # 1
23 >addsensor(100, 270, 150, 1); # 2
24 >addsensor(100, 0, 359, 0); # 3
25
26 # Default movement if nothing is detected
27 : move(70, 70) . turretccw();
28 random(2, 3): move(40, 70) . turretccw();
29 random(1, 3): move(70, 40) . turretccw();
30
31 # We found something!!
32 sense(3): move(0, 0);
33 sense(1): turretcw();
34 sense(2): turretccw();
35 sense(0): fire();
36
37<table class="figure">
38 <caption>"Chashtank" cleans up.</caption>
39 <tr>
40 <td>
41 <canvas id="shortround"></canvas>
42 <script type="application/javascript">
43 start("shortround", shortround);
44 </script>
45 </td>
46 </tr>
47</table>
48
49Nick Moffitt played with this original version and convinced me (Neale)
50that something like Forth would be a better language. I added some code
51to accept a scaled-down version of PostScript. The IRC channel we
52frequent collectively agreed to give this new language the derisive name
53"Forf", which should ideally be followed by punching someone after it is
54spoken aloud. I wrote a Python implementation of Forf, which was slow,
55and then Anna Glasgall wrote a C implementation, which was quick.
56
57I decided to take Tanks to Def Con in July 2010, and just for bragging
58rights, to have it run on an Asus WL-500gU. This is a $50 device with a
59240 MHz MIPS CPU, 16MB RAM, and a 4MB flash disk, along with an
60802.11b/g radio, 4-port 10/100 switch, and an additional 10/100 "uplink"
61port; it's sold as a home wireless router. I had originally intended to
62run it off a lantern battery just for fun, but eventually thought better
63of it: doing so would be wasteful for no good reason.
64
65Aaron McPhall <amcphall@mcphall.org>, my summer intern at the time, got
66OpenWRT and Python onto the box and benchmarked it at about 60 seconds
67for a 16-tank game, after he had profiled the code and optimized a lot
68of the math. That wasn't bad, it meant we could run a reasonably-sized
69game at one turn per minute, which we knew from past experience was
70about the right rate. But it required a USB thumb drive to hold Python,
71and when we used the Python Forf implementation, the run-time shot up to
72several minutes. I began this C port while Anna Glasgall, another fool
73on the previously-mentioned IRC channel, started work on a C version of
74a Forf interpreter.
75
76This C version with Forf runs about 6 times faster than the Python
77version with Bullet, on the WL-500gU. A 1GHz Intel Atom runs a 16-tank
78game in about 0.2 seconds.
79
80
81What's so great about Forf?
82---------------------------
83
84Nothing's great about Forf. It's a crummy language that only does
85integer math. For this application it's a good choice, for the
86following reasons:
87
88* No library dependencies, not even malloc
89* Runs in fixed size memory
90* Not Turing-complete, I think (impossible to make endless loops)
91* Lends itself to genetic algorithms