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