tag:blogger.com,1999:blog-67225817405074719122024-02-19T07:15:08.211+00:00Thoughts on Corewar...John Metcalfhttp://www.blogger.com/profile/09108374348083307900noreply@blogger.comBlogger61125tag:blogger.com,1999:blog-6722581740507471912.post-92046999763113141312011-10-22T18:43:00.001+01:002011-10-22T18:45:09.422+01:00Koenigstuhl Top 20: Where Are They NowThis afternoon I stumbled across a status report from Koenigstuhl, 03 July 2001. Curious to see how the hill has changed over 10 years I compared the report to the current hill:<br />
<br />
<table style="background: white; border: black solid 1px"><tbody>
<tr><th align="left">2001 Rank</th><th align="left">Warrior</th><th align="left">Author</th><th align="left">2011 Rank</th></tr>
<tr><td>1</td><td>Pattel's Virus</td><td>Ben Ford</td><td>8</td></tr>
<tr><td>2</td><td>Recycled Bits</td><td>David Moore</td><td>12</td></tr>
<tr><td>3</td><td>Combatra</td><td>David Moore</td><td>4</td></tr>
<tr><td>4</td><td>Self-Modifying Code v0.11</td><td>Ben Ford</td><td>22</td></tr>
<tr><td>5</td><td>Self-Modifying Code v0.10</td><td>Ben Ford</td><td>25</td></tr>
<tr><td>6</td><td>Quicksilver</td><td>Michal Janeczek</td><td>76</td></tr>
<tr><td>7</td><td>Uninvited</td><td>John Metcalf</td><td>88</td></tr>
<tr><td>8</td><td>Recycled Bits--</td><td>David Moore</td><td>93</td></tr>
<tr><td>9</td><td>Tuesday Afternoon</td><td>John K W</td><td>139</td></tr>
<tr><td>10</td><td>Fire and Ice</td><td>David Moore</td><td>94</td></tr>
<tr><td>11</td><td>Recovery</td><td>Ian Oversby</td><td>97</td></tr>
<tr><td>12</td><td>Reindeer</td><td>Ian Oversby</td><td>141</td></tr>
<tr><td>13</td><td>Three Musketeers</td><td>Robert Macrae</td><td>157</td></tr>
<tr><td>14</td><td>The Stormbringer</td><td>Christian Schmidt</td><td>133</td></tr>
<tr><td>15</td><td>Am I alive?</td><td>Christian Schmidt</td><td>166</td></tr>
<tr><td>16</td><td>2 Crazy</td><td>Christian Schmidt</td><td>189</td></tr>
<tr><td>17</td><td>Digitalis 4</td><td>Christian Schmidt</td><td>198</td></tr>
<tr><td>18</td><td>Bigger Brother</td><td>Philip Kendall</td><td>58</td></tr>
<tr><td>19</td><td>Liquid Paper</td><td>Sean McDonald</td><td>109</td></tr>
<tr><td>20</td><td>Origami Harquebus</td><td>mjp</td><td>49</td></tr>
</tbody></table><br />
Only three warriors remain in the top 20 while the majority have fallen 50+ places. :-)John Metcalfhttp://www.blogger.com/profile/09108374348083307900noreply@blogger.com1tag:blogger.com,1999:blog-6722581740507471912.post-27210642241791116782011-09-27T19:31:00.000+01:002011-09-27T19:31:42.067+01:00Whirl: '88 qscan -> oneshotWhirl is a qscan -> oneshot which recently entered the <a href="http://www.koth.org/lcgi-bin/current.pl?hill">'88 hill</a>.
<pre>;redcode
;name Whirl
;author John Metcalf
;strategy qscan -> oneshot
;assert CORESIZE==8000
qfirst equ (qp2+2*qstep)
qdist equ qfirst+111
qstep equ
qi equ 7
qr equ 7
qbomb dat <qi/2-qi*qr, <qi*qr-qi/2
qa equ qstep*16
qb equ qstep*5+2
qc equ qstep*10
qd equ qstep*2
qe equ qstep*1
qgo cmp qdist+qc, qfirst+qc
jmp qfast, <qa
cmp qdist+qe+qd, qfirst+qe+qd
qp1 jmp <qfast, <qc
qp2 cmp qdist, qfirst
qp3 jmp qskip, <qe
cmp qdist+qb, qfirst+qb
q1 djn qfast, #qp1
cmp qdist+qd+qc, qfirst+qd+qc
jmp qslow, <qfirst+qd+qc+4
cmp qdist+qd+qb, qfirst+qd+qb
x1 jmp qslow, <q1
cmp qdist+qc+qc, qfirst+qc+qc
q2 djn qslow, #qp2
cmp qdist+qd, qfirst+qd
jmp qslow, <qfast
cmp qdist+qa, qfirst+qa
jmp q1, <q1
cmp qdist+qa+qd, qfirst+qa+qd
jmp x1, <q1
cmp qdist+qc+qb, qfirst+qc+qb
jmp q2, <q1
cmp qdist+qe+qd+qc,qfirst+qe+qd+qc
jmp qslower, <qfirst+qe+qd+qc+4
cmp qdist+qe+qd+qb,qfirst+qe+qd+qb
jmp qslower, <q1
cmp qdist+qe+qc+qc,qfirst+qe+qc+qc
jmp qslower, <q2
cmp qdist+qd+qd+qc,qfirst+qd+qd+qc
q3 djn qslower, #qp3
cmp qdist+qe+qc, qfirst+qe+qc
jmp <qfast, <q2
cmp qdist+qd+qd, qfirst+qd+qd
jmp <qfast, <q3
cmp qdist+qd+qd+qb,qfirst+qd+qd+qb
slt <q3, <q1
jmz pgo, qdist+qe+qd+qc+10
qslower add @q3, @qslow
qslow add @q2, qkil
qfast add @q1, @qslow
qskip cmp <qdist+qstep+50, @qkil
jmp qloop, <1234
add #qdist-qfirst, qkil
qloop mov qbomb, @qkil
qkil mov <qfirst+qstep+50, <qfirst
sub #qi, @qloop
djn qloop, #qr+2
pgo mov last, boot+10
c for 10
mov last-c, <pgo
rof
jmp boot+7
step equ -12
first equ (201*12-8)
boot equ (pgo-first-100)
dbmb dat <2667, <-10
clear spl 0, <dbmb-sptr-8
cloop mov @sloop, <sptr
mov @sloop, <sptr
bomb djn cloop, <dbmb-4
steps dat <step*3, <step*3+1
sloop add steps, @cloop
mov dbmb, <sptr
sptr cmp first+step*2, @first+1
jmp <sloop
last jmp sloop
end qgo
</pre>
John Metcalfhttp://www.blogger.com/profile/09108374348083307900noreply@blogger.com0tag:blogger.com,1999:blog-6722581740507471912.post-48689934023988180262011-08-11T19:09:00.002+01:002011-08-11T19:16:17.455+01:00The Second ICPCChristian Schmidt recently announced the <a href="http://www.corewar.info/tournament/icpc2">Second International Corewar Programming Contest</a> with a concept similar to the new <a href="http://dynahill.bplaced.net/dynahill">DynaHill</a>.<br />
<br />
The hill will be initialised with a pool of 3800 published warriors. Entries will compete against programs in their neighbourhood and move up or down depending on their score.<br />
<br />
An interesting twist is the chance to enter warriors in 8 different categories including '94, '88, <acronym title="limited process">LP</acronym> and nano. For full details of the rules see the <a href="http://www.corewar.info/tournament/icpc2">official tournament page</a>.<br />
<br />
The deadline is 15<sup>th</sup> September. Good luck :-)John Metcalfhttp://www.blogger.com/profile/09108374348083307900noreply@blogger.com0tag:blogger.com,1999:blog-6722581740507471912.post-35327999502922608422011-07-01T22:51:00.002+01:002012-07-06T21:12:57.489+01:00A Brief Introduction to Core War<h2>What is Corewar?</h2><br />
<strong>Corewar</strong> is a programming game in which the aim is to eliminate all opponents from the memory of a virtual computer. Players write short battle programs to compete against each other.<br />
<br />
Battle programs are written in Redcode, the assembly language of the MARS virtual processor. Redcode has 18 opcodes. Each Redcode instruction is made up of an opcode, a source pointer, a destination pointer, a source addressing mode and a destination addressing mode. For example, the mov instruction copies information from the source to the destination:<br />
<br />
<pre>mov 10, 20</pre><br />
In the example, the source is 10 and the destination is 20. When the instruction is executed, it take the information in the cell 10 locations after the mov and copies it to the cell 20 locations after.<br />
<br />
Here's another example, known as an imp:<br />
<br />
<pre>mov 0, 1</pre><br />
When this executes, it copies the information from 0 locations ahead (i.e. itself) to 1 location ahead:<br />
<br />
<pre>mov 0, 1
mov 0, 1 <--- the copy</pre><br />
Execution continues with the next instruction, so the program executes the copy it just made. Addresses in Corewar are relative to the cell they're stored in, so when the copy executes it makes a new copy one location ahead:<br />
<br />
<pre>mov 0, 1
mov 0, 1 <--- the copy
mov 0, 1 <--- the second copy</pre><br />
The addressing mode affects how the address is interpreted. If no addressing mode is specified, direct addressing is used as in the examples above. The alternatives are immediate and indirect addressing.<br />
<br />
Immediate addressing is indicated by an octothorpe (#). Instead of using data a number of cells away, it uses the data stored in the current instruction. For example:<br />
<br />
<pre>add #10, 20</pre><br />
The # shows the data to be used is 10, not the value from the cell 10 locations away. add #10, 20 adds 10 to the value in the cell 20 locations ahead.<br />
<br />
Indirect addressing is indicated by one of the following symbols, < @ > { * }. Instead of using data from a number of cells away, that data is used as a pointer to the actual data to be used. For example:<br />
<pre>add #10, @1
dat 0, 19</pre><br />
When the add instruction executes, it adds 10 to the cell 20 locations ahead. @1 tells the Redcode processor to use the destination of the cell 1 location away as a pointer. This contains 19, so the destination is 19 locations after the dat, or 20 after the add.<br />
<br />
Here's a quick run down of addressing modes. A-field is another name for the source pointer and b-field is for the destination pointer:<br />
<br />
<ul><li>< use the b-field as a pointer after subtracting 1 from it</li>
<li>@ use the b-field as a pointer</li>
<li>> use the b-field as a pointer and afterwards add 1 to it</li>
<li>{ use the a-field as a pointer after subtracting 1 from it</li>
<li>* use the a-field as a pointer</li>
<li>} use the a-field as a pointer and afterwards add 1 to it</li>
<li># use the data in the currently executing instruction</li>
</ul><br />
Here are the 18 opcodes supported by the Redcode processor:<br />
<br />
<ul><li>mov - copy data from source to destination</li>
<li>add - add value from source to destination</li>
<li>sub - subtract value at source from destination</li>
<li>div - divide destination by source</li>
<li>mod - destination = destination MODULO source</li>
<li>mul - multiply destination by source</li>
<li>seq - skip next instruction if source equal to destination</li>
<li>sne - skip next instruction if source not equal to destination</li>
<li>slt - skip next instruction if source less than destination</li>
<li>jmp - jump to a-field</li>
<li>jmn - jump to a-field if b-field non-zero</li>
<li>jmz - jump to a-field if b-field zero</li>
<li>djn - subtract 1 from b-field. if result non-zero, jump to a-field</li>
<li>spl - start a new thread at a-field</li>
<li>dat - destroy thread when executed</li>
<li>stp - store source to private memory</li>
<li>ldp - load private memory to destination</li>
<li>nop - no operation</li>
</ul><br />
<h2>Top Corewar Links</h2><br />
<ul><li><a href="http://vyznev.net/corewar/guide.html">Beginners' Guide to Redcode</a><br />
Ilmari's guide to Redcode provides a gentle introduction to the art of Corewar.</li>
<li><a href="http://corewar.co.uk/biblio.htm">Corewar Bibliography</a><br />
The Corewar Bibliography is a comprehensive index of Corewar articles and the ideal starting point to research any Corewar topic.</li>
<li><a href="http://koth.org/">Corewars - King of the Hill</a><br />
KOTH.org is the provider of several online hills. Submit your program by email to compete against others.</li>
<li><a href="http://sal.discontinuity.info">KOTH@SAL Corewar Hills</a><br />
The hills at SAL present some alternative settings, including the beginner hill and the popular nano hill.</li>
<li><a href="http://users.obs.carnegiescience.edu/birk/COREWAR/koenigstuhl.html">CoreWar "Koenigstuhl" Page</a><br />
Koenigstuhl is the Valhalla of Corewar! When an author publishes their battle programs, they're archived on the Koenigstuhl infinite hills.</li>
<li><a href="http://corewar.co.uk/">Programming in Corewar</a><br />
In Corewar a battle is played out between computer programs, which attempt to eliminate all opponents within the memory of the MARS virtual computer.</li>
<li><a href="http://www.corewar.info/">Fizmo's Corewar Info</a><br />
The ultimate source for any information regarding Corewar, a programming game where small programs fight each other.<br />
</li>
</ul>John Metcalfhttp://www.blogger.com/profile/09108374348083307900noreply@blogger.com0tag:blogger.com,1999:blog-6722581740507471912.post-74582307793737462792011-02-10T20:44:00.006+00:002011-02-10T20:50:04.347+00:00An Early Description of Core WarUntil I saw this description of Core War I assumed Dewdney and Jones were the first to use the term in the <a href="http://corewar.co.uk/cwg.txt">Core War Guidelines</a>. <br />
<br />
<div style="margin-left: 30px; margin-right: 30px; border: 1px solid silver"><blockquote>“<em>Core war</em> is a game surreptitiously played by systems programmers on large installations, where a player's goal in each fixed time slice of real time is to propagate his program elsewhere in memory, while doing as much “damage” (read: clearing to zero) as possible at random places in the hopes of causing the opponent's program to blow up. The game of <em>core war</em> is rarely mentioned with more than a whisper, and thus tends to be lost amid the din of easier and less abstract games such as <em>Star Trek</em>, <em>Adventure</em> or <em>Dungeons and Dragons</em>”</blockquote><div style="margin-right: 50px; text-align: right;">-- BYTE Magazine, July 1978, page 106-107</div><br />
</div><br />
This brief description was published 6 years before A. K. Dewdney's first Core War article in Scientific American (May 1984, page 14-22).<br />
<br />
Have you seen any other early mentions of Core War?John Metcalfhttp://www.blogger.com/profile/09108374348083307900noreply@blogger.com0tag:blogger.com,1999:blog-6722581740507471912.post-21609165871675529702011-01-17T14:11:00.002+00:002011-01-17T14:42:54.125+00:00Revisiting the Dragon CurveA few days ago I published code to draw the <a href="http://impomatic.blogspot.com/2011/01/dragon-curve-in-redcode.html">Heighway Dragon Curve</a>. Here's a variation that's 3 lines shorter and plots the curve in 655360 cycles. The pMARS command line is <code>pmarsv -s 90000 -c 1000000</code>.<br />
<br />
<pre>;redcode-fractal
;name Dragon Curve 2
;author John Metcalf
width equ 315
stack equ dragon+100
plot equ direct+width+1
first equ 80*width+50
mov #first, plot
dragon mov.ab count, <plot
test mov.b @plot, #0
add.ba @plot, direct
div #2, @plot
mod #2, test
jmz test, test
mod.a #4, direct
direct add.b 3, width+1
count sub.ba #65536, #1+1
jmp dragon, -width+1
</pre>John Metcalfhttp://www.blogger.com/profile/09108374348083307900noreply@blogger.com1tag:blogger.com,1999:blog-6722581740507471912.post-40297064494753468132011-01-09T19:59:00.000+00:002011-01-09T19:59:23.728+00:00Dragon Curve in Redcode<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgsv9qjxmqMIx7zHigtTjUZ-6aLNTnMMSm7d-EdAJaASGmNbIVNSVFAL2oRSKHYRmsb8rjQLSV0hx1nmkHrDTCqYRInJRsE_XObjGB7iiEKxK4nYoM8nQrwIJbM1Gqyoj4vQesQCFk0LUm7/s1600/dragon_curve3.png" imageanchor="1" style="margin-left:1em; margin-right:1em"><img border="0" height="400" width="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgsv9qjxmqMIx7zHigtTjUZ-6aLNTnMMSm7d-EdAJaASGmNbIVNSVFAL2oRSKHYRmsb8rjQLSV0hx1nmkHrDTCqYRInJRsE_XObjGB7iiEKxK4nYoM8nQrwIJbM1Gqyoj4vQesQCFk0LUm7/s400/dragon_curve3.png" alt="dragon curve in redcode" /></a></div><br />
The Heighway Dragon Curve is fractal line than goes through a series of 90° turns, creating a pattern which fills a 2 dimensional space. The program plots 32768 points in 458741 cycles. The pMARS command line is <code>pmarsv -s 90000 -c 500000</code>.<br />
<br />
<pre>;redcode-fractal
;name Dragon Curve
;author John Metcalf
width equ 315
stack equ dragon+100
dragon mov.x paira, <stack
recur djn dragon, #15
mod.a #4, direct
add.b *direct, plot
plot mov >recur, 80*width+110
mov.ba >stack, ret
ret jmp 0, }stack
turn add.a @stack, direct
mov.x pairb, <stack
jmp recur
direct dat 3, width
paira dat turn-ret, -1
dat 0, -width
pairb dat plot-ret, 1
</pre>John Metcalfhttp://www.blogger.com/profile/09108374348083307900noreply@blogger.com0tag:blogger.com,1999:blog-6722581740507471912.post-39895801043095073392010-12-09T22:12:00.003+00:002010-12-09T22:15:16.411+00:00Corewar Programming ContestThe <a href="http://www.corewar.info/tournament/icpc1">First International Corewar Programming Contest</a> has just been announced, with a first prize of $50 sponsored by <a href="http://www.corewar.info/">www.corewar.info</a>.<br />
<br />
The competition takes place in the unexplored area between '94nop and <acronym title="limited process">LP</acronym> settings which has recently been investigated by Fizmo in <a href="http://corewar.co.uk/redtalk">Redcode Talk</a>.<br />
<br />
The exact settings are as follows:<br />
<br />
<table style="border: 1px solid black; padding: 10px"><tbody>
<tr><td>Standard:</td><td><acronym title="Core War Standard 1994">CWS'94</acronym></td></tr>
<tr><td>Coresize:</td><td>8000</td></tr>
<tr><td>Processes:</td><td>200</td></tr>
<tr><td>Entry length:</td><td>20</td></tr>
<tr><td>Points win:</td><td>3</td></tr>
<tr><td>Points tie:</td><td>1</td></tr>
<tr><td>Cycles:</td><td>80000</td></tr>
<tr><td>Rounds:</td><td>1000</td></tr>
</tbody></table><br />
The pMARS command line is <code>pmars -p 200 -l 20 -r 1000</code>. <code>STP</code> and <code>LDP</code> are forbidden, up to two entries are allowed and battles will take part in a round-robin tournament.<br />
<br />
For more information, take a look at the <a href="http://groups.google.com/group/rec.games.corewar/browse_thread/thread/4be19d3fdfaf50ee#">announcement in rec.games.corewar</a>.John Metcalfhttp://www.blogger.com/profile/09108374348083307900noreply@blogger.com0tag:blogger.com,1999:blog-6722581740507471912.post-75706548641778742922010-11-05T23:07:00.006+00:002010-11-05T23:12:39.644+00:00Four Lines of Redcode<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijkYxRUgnhz698oR_ZdJN3HEGyxF62C16bqebN5RRPwY6Ta8budZWo9-qygT62hhonqduZp3Tx4An8WBn1eHKcfVv79MkOBwz6_rKVdW3L6jsW1fe-2uww9N3fmubx2BzQgIL6CJ8A_Hc6/s1600/sierpinski.png" imageanchor="1" style="margin-left:1em; margin-right:1em"><img border="0" height="400" width="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijkYxRUgnhz698oR_ZdJN3HEGyxF62C16bqebN5RRPwY6Ta8budZWo9-qygT62hhonqduZp3Tx4An8WBn1eHKcfVv79MkOBwz6_rKVdW3L6jsW1fe-2uww9N3fmubx2BzQgIL6CJ8A_Hc6/s400/sierpinski.png" alt="Sierpinski triangle"></a></div><br />
The Sierpinski triangle or gasket is a fractal named after the Polish mathematician Waclaw Sierpinski. Surprisingly the fractal can be generated with just 4 lines of Redcode:<br />
<br />
<pre> width equ 126
trail equ (sum-CORESIZE%width)
start equ (trail-width+1)
sum mov #3, @3
ptr mov.b trail, sum
add.b {ptr, sum
djn sum, #start
</pre><br />
The magic incantation for pMARS is <code>pmars -v 132</code>. Alternatively set the width to 128 to view using CoreWin :-)John Metcalfhttp://www.blogger.com/profile/09108374348083307900noreply@blogger.com0tag:blogger.com,1999:blog-6722581740507471912.post-7095427580710422592010-09-05T07:58:00.004+01:002010-09-05T08:01:06.850+01:00Redcode Talk Issue 1<div class="separator" style="clear: both; text-align: center;"><a href="http://www.corewar.info/corewarrior/redcodetalk/RedcodeTalk001.txt" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img alt="Redcode Talk" border="0" height="133" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXWzS54Ks0gJIony9L55O2V8R4iLQ6N3C_blVYhP61c4rvd-RVWhJyPxm14aoau0xfVkdIdwtnXvzCJCcxW29KU8yJH_Q_D7XnUNlCfjia7y2vCV-ESwkHIcGBkWunQLudcMDqFWaqqMmV/s200/redcode_talk.jpg" width="200" /></a></div>Christian Schmidt recently published the first issue of <a href="http://www.corewar.info/corewarrior/redcodetalk/RedcodeTalk001.txt">Redcode Talk</a>. The issue contains a couple of articles by Fizmo:<br />
<br />
<ul><li>The undiscovered area between <acronym title="limited process">LP</acronym> & 94draft<br />
</li>
<li>Random Warrior Talk: One Man Army v1.0<br />
</li>
</ul>John Metcalfhttp://www.blogger.com/profile/09108374348083307900noreply@blogger.com0tag:blogger.com,1999:blog-6722581740507471912.post-22703661236987653972010-07-23T23:54:00.025+01:002010-07-24T15:13:08.415+01:00Happy NumbersToday's <a href="http://programmingpraxis.com/2010/07/23/happy-numbers">Programming Praxis</a> challenges us to write a program to list the happy numbers up to a given limit. A number is happy if the sum of the square of it's digital eventually reaches 1. E.g. 7 is happy because 7<sup>2</sup>=49, 4<sup>2</sup>+9<sup>2</sup>=97, 9<sup>2</sup>+7<sup>2</sup>=130, 1<sup>2</sup>+3<sup>2</sup>+0<sup>2</sup>=10, 1<sup>2</sup>+0<sup>2</sup>=1.<br />
<br />
Here's my solution in Redcode:<br />
<br />
<pre>org newcand
base equ 10
limit equ 100
tries equ 50
stack dat 0
happy dat 1
cand dat 0
total dat 0
repeat dat 0
newcand mov.ba happy, cand
mov #tries, repeat
again mov #-1, total
digits mov.ab cand, cand
mod #base, cand
div.a #base, cand
mul.b cand, cand
add.b cand, total
jmn.a digits, cand
jmz found, total
mov.ba total, cand
add.a #1, cand
djn again, repeat
nexthap seq #limit, happy
jmp newcand, >happy
dat 0
found mov.b happy, <stack
writen mov.b @stack, <stack
div #10, >stack
mod #10, @stack
add #48, @stack
jmn writen, <stack
add #1, stack
wloop sts >stack, 0
jmn wloop, stack
sts.a #10, 0
jmp nexthap
</pre>John Metcalfhttp://www.blogger.com/profile/09108374348083307900noreply@blogger.com0tag:blogger.com,1999:blog-6722581740507471912.post-65193969778257379912010-01-24T19:11:00.003+00:002010-01-24T19:21:22.066+00:00Cross Simulator Core GraphicsOne difficulty when trying to write code to plot graphics in Redcode is the width of the core display. The four most popular simulators uses a variety of different widths:<br />
<br />
<table><tbody>
<tr><th>Simulator<br />
</th><th>Display Width<br />
</th></tr>
<tr><td>pMARS SDL mode 0<br />
</td><td>157<br />
</td></tr>
<tr><td>pMARS SDL mode 2<br />
</td><td>126<br />
</td></tr>
<tr><td>CoreWin<br />
</td><td>128<br />
</td></tr>
<tr><td>ARES<br />
</td><td>80<br />
</td></tr>
<tr><td>nMars<br />
</td><td>various<br />
</td></tr>
</tbody></table><br />
The simplest solution is to define a variable for the width which can be modified by the person running the program. Alternatively it's possible to use the the predefined <code>VERSION</code> constant to determine the simulator:<br />
<br />
<table><tbody>
<tr><th>Simulator<br />
</th><th>Version<br />
</th></tr>
<tr><td>pMARS SDL mode 0<br />
</td><td>92<br />
</td></tr>
<tr><td>pMARS SDL mode 2<br />
</td><td>92<br />
</td></tr>
<tr><td>CoreWin<br />
</td><td>230<br />
</td></tr>
<tr><td>ARES<br />
</td><td>0<br />
</td></tr>
<tr><td>nMars<br />
</td><td>93<br />
</td></tr>
</tbody></table><br />
Putting the two together we can write the following code which sets the correct width for pMARS SDL, CoreWin and ARES:<br />
<br />
<pre>width equ ( (VERSION==92)*157 + (VERSION==230)*128 + (VERSION==0)*80 )
</pre>John Metcalfhttp://www.blogger.com/profile/09108374348083307900noreply@blogger.com0tag:blogger.com,1999:blog-6722581740507471912.post-16053240698414260892010-01-07T20:49:00.004+00:002010-07-24T15:58:17.975+01:00Fractals in Corewar<span style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img alt="Koch Curve in Redcode" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3woHY9-74pwbAZIMNQ_g7k8se0mCXaLWrnLVKxUWpeOK4V1MwnhtT4n5P7zyQEOXnWY0MJty9NwN2rO77-WbAS9XYuAk_WdwjaPYqA9XqAZU8RqOYrdJv4r7pzXa5YLJKahE74qRPEhaR/s320/koch_curve.png" /></span>In 1997 Anton Marsden organised a Corewar tournament with a difference. The three rounds challenged players to use Redcode to solve a variety of problems.<br />
<br />
In the third round of <a href="http://corewar.co.uk/marsden/index.htm">Anton's Corewar Tournament</a> the challenge was to write a Redcode program to draw a pretty picture. First place was taken by Ilmari Karonen with a fractal fern.<br />
<br />
Here's my own attempt at creating a pretty picture in the core view of <a href="http://corewar.co.uk/pmars/">pMARS</a>. It's a fractal known as the Koch Curve.<br />
<br />
Here's the program, just 18 instructions:<br />
<br />
<pre>width equ 157
org koch
stack equ count+30
koch: mov #2-ptr, >stack
jmp count, }move
sub.a #2, move
mov #2-ptr, >stack
jmp count
jmp return, }move
count: djn koch, #11
mod.a #8, move
div.a #2, move
add.b *move, pos
mul.a #2, move
pos: add #1, koch+71*width/2+16
return: mov.ba <stack, ptr
ptr: jmp 0, >count
move: dat -1
dat -width
dat 1
dat width
</pre><br />
Have you tried to write a graphical display in Corewar?John Metcalfhttp://www.blogger.com/profile/09108374348083307900noreply@blogger.com0tag:blogger.com,1999:blog-6722581740507471912.post-28895824738284672392009-10-27T08:01:00.003+00:002012-07-06T21:15:31.594+01:00Tinywarrior Issue 4<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://corewar.co.uk/tw/tw04.txt"><img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 256px; height: 192px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVb0ctHXSq5oU9u-WG4CPaeJY3RMCUobLshqgumIjQFMtD021YbHDqlywgZ4dLwnsEa2pcVZCa0Eupn-7iWc25jJAcstl6NhyphenhyphenqgHFDAjdjHUWk4j1d5-p4_oNRyIrrbjcPYYDOPRwkN9Ot/s400/tinywarrior04.jpg" border="0" alt="Tinywarrior issue 4, corewar" id="BLOGGER_PHOTO_ID_5397187058357585586" /></a>The fourth issue of <a href="http://corewar.co.uk/tw">Tinywarrior</a> has just been published, the newsletter which reports the latest events and techniques for the <a href="http://sal.discontinuity.info/hill.php?key=tiny">tiny hill</a>. Here's what you can expect to find in this issue:<div><br />
</div><em>Flux and the SPL/DIV Clear</em> by John Metcalf examines a SPL/DIV clear inspired by G2.<br />
<br />
<em>Larger Than Infinity</em> by Zul Nadzri reveals the results of Zul's experiments with White Noise.<br />
<br />
Any feedback would be greatly appreciated.John Metcalfhttp://www.blogger.com/profile/09108374348083307900noreply@blogger.com0tag:blogger.com,1999:blog-6722581740507471912.post-74911053950646135702009-08-25T13:26:00.004+01:002012-07-06T21:17:22.804+01:00Maezumo, Evolving for the Corewar Tiny Hill with a Twist<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.corewar.info/maezumo/"><img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 300px; height: 220px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijii4EKm7JQCU5r_SNbhWqTs-7EjBTBz_tyFkmC3tn7seL2vcRDvN0_t5swCPk9zOI5HmYgNFFvsD9f03lQC2h2cI7Yd8ogOJK6IrTiXFtkIj2w-Yeob8xUu6t7C1BhE_T-4RULzK7IKc5/s400/maezumo.JPG" border="0" alt="Maezumo, the Evolver with a Twist" id="BLOGGER_PHOTO_ID_5373878727828667490" /></a>At the beginning of August, Christian Schmidt released version 1.04 of <a href="http://www.corewar.info/maezumo/">Maezumo</a>, his corewar evolver. If you're familiar with the old version the biggest difference you'll notice are the additions to the progress report.<div><br />
</div><div>Maezumo evolves warriors using traditional mutation, keeping a hill of the top warriors. Hill warriors are then injected back into the soup. Where Maezumo offers something innovative is in the hint modes.</div><div><br />
</div><div>If the hint modes are enabled, Maezumo generates warriors from inbuilt templates. These challenge the hill and if successful enter the soup for further enhancement by the mutation algorithm.</div><div><br />
</div><div>Maezumo is supplied with a Windows binary, Basic source code and all the necessary support files. To evolve for the tiny hill, I simply extracted the archived, changed the settings in maezumo.ini and double clicked maezumo.exe. I selected the scanner/paper hint mode to cover the two most successful tiny strategies.</div><div><br />
</div><div>After a 13 hour run, the top warrior on Maezumo's hill is an evolved style paper which scores 75 against <a href="http://sal.discontinuity.info/hill.php?key=tiny">SAL's tiny hill</a>. I think it would be realistic to expect a strong tiny warrior after a 3 or 4 day run.</div><div><br />
</div><div>Have you tried Maezumo yet? If so, let me know your thoughts :-)</div>John Metcalfhttp://www.blogger.com/profile/09108374348083307900noreply@blogger.com0tag:blogger.com,1999:blog-6722581740507471912.post-49609992200581876972009-07-09T06:54:00.005+01:002012-07-06T21:18:27.690+01:00TEV Hints and Another Evolved BomberRecently I've been experimenting with different hints in <a href="http://impomatic.blogspot.com/2009/06/corewar-tiny-evolver-tev-v0.html">TEV0</a> and <a href="http://impomatic.blogspot.com/2009/06/12k-tiny-corewar-evolver.html">TEV12</a> hoping to guide the evolution of Redcode programs. TEV is a small program written in Basic and uses the principles of random mutation and survival of the fittest to create a Redcode program over a number of generations.<div><br />
</div><div>Redcode is the language of Corewar, a game in which two or more programs battle to control the memory of a virtual computer. Here's a quick introduction to <a href="http://retroprogramming.com/2008/11/core-war-hostile-programming.html">Corewar</a>. Traditionally programs are coded by hand, but a number of players have risen to the challenge of writing a program to evolve good contenders.</div><div><br />
</div><div>The purpose of a hint is to control the direction of evolution by issuing a score penalty for certain types of code. Here are the hints I've been experimenting with:</div><div><br />
<ul><li>a penalty for three consecutive opcodes the same</li>
<li>a penalty for the first opcode being a SPL</li>
<li>a penalty for the a-mode of a SPL being #</li>
</ul><br />
</div><div>This produced some really weird programs to begin with, but after relaxing the penalties stronger programs emerged. Unfortunately TEV still hasn't produced a decent replicator so instead here's the code for the most successful bomber of the latest run, medusa's mirror:</div><div><br />
<pre>;redcode-nano
;name medusa's mirror
;author John Metcalf
;strategy evolved using TEV12 with hints
;assert CORESIZE==80
mov.i <46, $11
spl.i #-4, {56
mov.i <36, {79
mov.i {79, {54
djn.f $78, {59
end</pre><br />
Next I'm hoping to divide the pool into different regions and implement a different hint in each region. If you have any suggestions for hints, please let me know.</div>John Metcalfhttp://www.blogger.com/profile/09108374348083307900noreply@blogger.com0tag:blogger.com,1999:blog-6722581740507471912.post-27519233850797972162009-06-25T23:14:00.003+01:002009-06-25T23:24:10.464+01:001.2K Tiny Corewar EvolverHere's the latest version of the Tiny Corewar Evolver, a small (<1.2K) GWBasic program to evolve Redcode warriors against a benchmark. This version producted <a href="http://impomatic.blogspot.com/2009/06/results-from-even-simpler-corewar.html">Wrath of the Machines</a> after a 28 hour run.<br /><br />The two biggest differences from <a href="http://impomatic.blogspot.com/2009/06/corewar-tiny-evolver-tev-v0.html">TEV0</a> are as follows:<br /><ul><li>no longer aborts a bad benchmark early</li><li>replaces the lowest scoring warrior with the current warrior</li></ul><br />TEV12.BAT<br /><pre>@dir /b /o-d *.red >w.evo<br />@echo END >>w.evo<br />@gwbasic tev12<br />@erase ?.evo<br /></pre><br /><br />TEV12.BAS<br /><pre>10 P$="pmars -s 80 -p 80 -c 800 -l 5 -b -k -P":R=142:L=5:P=25:K=80<br />20 O$="mov.imov.ispl.bdjn.f;xxxx":M$="<@>{*}$#"<br />30 DIM W$(99),A$(L,P),B$(L,P),C(L,P),D$(L,P),E(L,P),S(P):RANDOMIZE TIMER<br />40 W=0:OPEN "w.evo" FOR INPUT AS #1:M=LEN(M$):q=0:h=1<br />50 INPUT #1,W$(W+1):IF W$(W+1)<>"END" THEN W=W+1:GOTO 50 ELSE CLOSE #1<br />60 q=(q mod p)+1:J=1:FOR I=2 TO P:IF S(I)<s(j) THEN j=i<br />70 NEXT i:FOR I=1 TO L:A$(I,J)=A$(I,q):B$(I,J)=B$(I,q):C(I,J)=C(I,q)<br />80 D$(I,J)=D$(I,q):E(I,J)=E(I,q):NEXT I:S(J)=s(q)<br />90 Z=S(Q)/H:FOR I=1 TO L:IF RND*Z<.3 THEN C(I,q)=INT(RND*K)<br />100 IF RND*Z<.3 THEN E(I,q)=INT(RND*K)<br />110 Z$=MID$(M$,INT(RND*M)+1,1):IF RND*Z<.3 THEN B$(I,q)=Z$<br />120 IF RND*Z<.3 THEN D$(I,q)=","+Z$<br />130 IF RND*Z<.1 THEN A$(I,q)=MID$(O$,INT(RND*LEN(O$)/5)*5+1,5)+" "<br />140 NEXT I:OPEN "w.evo" FOR OUTPUT AS #1:FOR I=1 TO L<br />150 PRINT #1,A$(I,q);B$(I,q);C(I,q);D$(I,q);E(I,q):NEXT I:CLOSE #1<br />160 s(q)=0:FOR I=1 TO W:SHELL P$+" w.evo "+W$(I)+" >s.evo"<br />170 OPEN "s.evo" FOR INPUT AS #1:INPUT #1,Z$:CLOSE #1:Z=1<br />180 IF MID$(Z$,Z,1)<>" " THEN Z=Z+1:GOTO 180<br />190 s(q)=s(q)+3*VAL(LEFT$(Z$,Z))+VAL(RIGHT$(Z$,LEN(Z$)-Z)):NEXT I<br />200 IF s(q)>H THEN H=s(q):SHELL "copy w.evo best.war"<br />210 goto 60<br /></pre>John Metcalfhttp://www.blogger.com/profile/09108374348083307900noreply@blogger.com0tag:blogger.com,1999:blog-6722581740507471912.post-87299678928974893892009-06-20T21:27:00.001+01:002012-07-06T21:44:38.352+01:00Results from an Even Simpler Corewar EvolverOver the last week I've been removing as much as possible from TEV, the <a href="http://impomatic.blogspot.com/2009/06/corewar-tiny-evolver-tev-v0.html">Tiny Corewar Evolver</a>. The latest version is down to 1.2K and produced a mad mad bomber which entered <a href="http://sal.discontinuity.info/hill.php?key=nano">SAL's nano hill</a> in 7th place:<br />
<br />
<pre>;redcode-nano
;name wrath of the machines
;author John Metcalf
;strategy evolved mad mad bomber
;strategy 28 hours with TEV 1.2K
;assert CORESIZE==80
spl.b #76, {32
mov.i >11, {49
mov.i }79, {76
mov.i <64, {29
djn.f $-3, {58
end</pre>John Metcalfhttp://www.blogger.com/profile/09108374348083307900noreply@blogger.com0tag:blogger.com,1999:blog-6722581740507471912.post-1604968990851122392009-06-10T21:32:00.008+01:002012-07-06T21:21:07.152+01:00Corewar Tiny Evolver TEV v0The Corewar Tiny Evolver is a small (< 1.5K) program written in GWBasic. After a couple of hours evolving, TEV is capable of producing programs able to compete with hand-written progams and enter the <a href="http://sal.discontinuity.info/hill.php?key=nano">Corewar nano hill</a>.<br />
<br />
<h3>Instructions</h3>Place TEV0.BAS, TEV0.BAT and a selection of benchmark warriors in the same directory. The parameters in line 10-20 are set up for the nano hill but can be adjusted if required.<br />
<br />
Run TEV0.BAT. Evolution will continue until you decide to terminate the program. Throughout the process, the best warrior can always be found in the file BEST.WAR.<br />
<br />
<h3>Program Layout</h3><ul><li>batch file: generate a list of benchmark warriors, run the evolver</li>
<li>10-20: set evolution parameters (see Parameters)</li>
<li>30-50: initialise the evolver</li>
<li>60-110: mutate current warrior based on how well it performs</li>
<li>120-130: write current warrior to file</li>
<li>140-180: benchmark current warrior, abort if poor performance</li>
<li>190: if benchmark warrior is best to date, save a copy</li>
<li>200-220: replace a lower scoring warrior with current warrior</li>
<li>230-250: if score below threshold, discard warrior and select another</li>
<li>repeat from 60</li>
</ul><br />
<h3>Parameters</h3>The evolution parameters are set in lines 10-20<br />
<ul><li>K: coresize</li>
<li>L: maximum warrior length</li>
<li>P: number of warriors in the evolution pool</li>
<li>R: number of rounds per benchmark battle</li>
<li>M$: addressing modes to be used</li>
<li>O$: opcode/modifier combinations to be used</li>
<li>P$: pMARS command line</li>
</ul><br />
TEV0.BAT<br />
<pre>@dir /b /o-d *.red >w.evo
@echo END >>w.evo
@gwbasic tev0
@erase ?.evo
</pre><br />
<br />
TEV0.BAS<br />
<pre>10 P$="pmars -s 80 -p 80 -c 800 -l 5 -b -k -P":R=142:L=5:P=20:K=80
20 O$="mov.ispl.bdjn.f;xxxx":M$="<@>{*}$#"
30 DIM W$(500),A$(L,P),B$(L,P),C(L,P),D$(L,P),E(L,P),S(P):RANDOMIZE TIMER
40 W=0:OPEN "w.evo" FOR INPUT AS #1:M=LEN(M$):H=80
50 INPUT #1,W$(W+1):IF W$(W+1)<>"END" THEN W=W+1:GOTO 50 ELSE CLOSE #1
60 FOR I=1 TO L:IF RND*S(1)/H<.6/L THEN C(I,1)=(C(I,1)+INT((RND-RND)*K))MOD K
70 IF RND*S(1)/H<.7/L THEN E(I,1)=(E(I,1)+INT((RND-RND)*K))MOD K
80 IF RND*S(1)/H<.3/L THEN B$(I,1)=MID$(M$,INT(RND*M)+1,1)
90 IF RND*S(1)/H<.4/L THEN D$(I,1)=MID$(M$,INT(RND*M)+1,1)
100 IF RND*S(1)/H<.3/L THEN A$(I,1)=MID$(O$,INT(RND*LEN(O$)/5)*5+1,5)
110 NEXT I
120 OPEN "w.evo" FOR OUTPUT AS #1:FOR I=1 TO L
130 PRINT #1,A$(I,1)+" "+B$(I,1);C(I,1);","+D$(I,1);E(I,1):NEXT I:CLOSE #1
140 S(1)=0:FOR I=1 TO W:SHELL P$+" w.evo "+W$(I)+" >s.evo"
150 OPEN "s.evo" FOR INPUT AS #1:INPUT #1,Z$:CLOSE #1:Z=1
160 IF MID$(Z$,Z,1)<>" " THEN Z=Z+1:GOTO 160
170 S(1)=S(1)+3*VAL(LEFT$(Z$,Z))+VAL(RIGHT$(Z$,LEN(Z$)-Z))
180 IF I>W/5 AND S(1)*150/H<I*R THEN 240 ELSE NEXT I
190 S(1)=100*S(1)/(W*R):IF S(1)>H THEN H=S(1):SHELL "copy w.evo best.war"
200 FOR J=2 TO P:IF S(J)>S(1) THEN NEXT J:GOTO 230
210 FOR I=1 TO L:A$(I,J)=A$(I,1):B$(I,J)=B$(I,1):C(I,J)=C(I,1)
220 D$(I,J)=D$(I,1):E(I,J)=E(I,1):NEXT I:S(J)=S(1)
230 IF S(1)>H*.9 THEN 60
240 Z=INT(RND*(P-1))+2:FOR I=1 TO L:A$(I,1)=A$(I,Z):B$(I,1)=B$(I,Z)
250 C(I,1)=C(I,Z):D$(I,1)=D$(I,Z):E(I,1)=E(I,Z):NEXT I:S(1)=S(Z):GOTO 60
</pre>John Metcalfhttp://www.blogger.com/profile/09108374348083307900noreply@blogger.com0tag:blogger.com,1999:blog-6722581740507471912.post-31069426820714372192009-05-27T13:07:00.009+01:002009-05-27T15:00:46.710+01:00The Incredible! Corewar SecretTowards the end of 2002 a five line warrior entered the KOTH.org '94 Draft hill in fifth place, later becoming King of the Hill. Although I've often been asked about Incredible, so far I've kept its secret quiet:<br /><pre>Program "Incredible!" (length 5) by "John Metcalf"<br />;strategy tweaked away one instruction<br /><br />Last battle concluded at : Sun Dec 1 17:26:58 EST 2002<br /><br /> # %W/ %L/ %T Name Author Score Age<br /> 1 40/ 42/ 18 Herbal Avenger Michal Janeczek 139 18<br /> 2 39/ 42/ 19 Combatra David Moore 136 7<br /> 3 24/ 11/ 65 Blowrag Metcalf/Schmidt 136 62<br /> 4 35/ 35/ 30 Mantrap Arcade Dave Hillis 136 2<br /> 5 24/ 13/ 64 Incredible! John Metcalf 135 1<br /> 6 28/ 22/ 51 Reepicheep Grabun/Metcalf 133 135<br /> 7 27/ 22/ 52 Son of Vain Oversby/Pihlaja 132 106<br /> 8 33/ 34/ 33 Cyanide Excuse Dave Hillis 131 8<br /> 9 25/ 22/ 53 Paperazor Christian Schmidt 129 79<br />10 28/ 27/ 45 Uninvited John Metcalf 129 125<br /></pre><br />Incredible is a standard paper/imp using an exploit to hide its true length from the KOTH script. The script has two sections. The front-end checks a warrior compiles correctly and extracts the name, author, strategy and length for the reports. The back-end runs the actual battle.<br /><br />Incredible takes advantage of the fact the front-end calls pMARS with a different number of rounds to the back-end. This is used to present different code to the front-end:<br /><pre>;redcode-94<br />;name length exploit<br />;author John Metcalf<br />;strategy demonstrate how to hide a program's true length<br />;assert CORESIZE == 8000<br /><br /> for ROUNDS < 5<br /> ;the front-end sees this code<br /> for 5<br /> dat 0, 0<br /> rof<br /> rof<br /><br /> for ROUNDS > 4<br /> ;the back-end sees this code<br /> ;insert warrior code here<br /> rof<br />end<br /></pre><br />I couldn't reveal the secret earlier because the KOTH script crashes if the code for the back-end contains errors. The script also crashes if the exploit is used to send '94 code to the '88 hill or p-space code to the no p-space hill. Unfortunately KOTH.org will be closing in a few days so it should be safe to share this now.John Metcalfhttp://www.blogger.com/profile/09108374348083307900noreply@blogger.com0tag:blogger.com,1999:blog-6722581740507471912.post-74827507166403618442009-05-25T22:15:00.003+01:002012-07-06T21:46:03.123+01:00First Results from a New Corewar EvolverOver the last few days I've been working on a short program written in GWBasic to evolve Corewar programs. After a test run earlier today, plateau entered SAL's <a href="http://sal.discontinuity.info/hill.php?key=nano">nano hill</a>:<br />
<pre>;redcode-nano
;name plateau
;author John Metcalf
;strategy evolved mad mad bomber
;strategy hit a plateau after 4 hours
;assert CORESIZE==80
spl.b #16, <28
mov.i <-15, {-35
mov.i {-1, {-3
mov.i <-28, <25
djn.f $-3, <33
end
</pre>The evolver creates warriors through pure evolution. The soup is seeded with random instructions and evolution is guided only by performance against the 2007 Nano Benchmark. If a benchmark test is scoring below a certain threshold, the test breaks out early.<div><br />
</div><div>Evolution is by mutation only. Crossover, insertion and deletion are not implemented. The lower a warrior scores, the more it is changed by mutation. After each round, a high scoring program replaces a randomly chosen low scoring program.<div><br />
</div><div>Here are the plans for the next version:</div><div><ul><li>keep a checksum of warriors to prevent duplicates in the pool</li>
<li>add a hint mode, but to keep it pure it'll hint what we don't want</li>
<li>implement crossover</li>
<li>think of a decent name (I think revolver is already taken)</li>
</ul><div>Any suggestions would be greatly appreciated.</div></div></div>John Metcalfhttp://www.blogger.com/profile/09108374348083307900noreply@blogger.com2tag:blogger.com,1999:blog-6722581740507471912.post-83548313594132887212009-04-19T01:11:00.004+01:002009-04-20T08:32:47.443+01:00Redcode's OISC - the DJN ComputerAn <acronym title="One-Instruction Set Computer">OISC</acronym> is an abstract computer designed to be Turing complete with only one instruction. <acronym title="One-Instruction Set Computer">OISC</acronym> is short for One-Instruction Set Computer.<br /><br />The instruction used by most variants of <acronym title="One-Instruction Set Computer">OISC</acronym> subtracts and branches on certain conditions, for example the <a href="http://impomatic.blogspot.com/2009/01/redcode-interpretter-for-rssb-single.html">URISC / RSSB Single Instruction Computer</a>. It may come as a surprise that the Redcode instruction set contains a primative instuction suitable for building a One-Instruction Computer, <code><acronym title="Decrement and Jump if Non-zero">DJN</acronym></code>.<br /><br /><code>DJN X, Y</code> uses Y as a pointer into memory. 1 is subtracted from the value stored at location Y. If the result is non-zero, <code>DJN</code> jumps to X. Here's an example demonstrating how to copy A to B using <code>DJN</code>:<br /><br /><pre> DJN 0, TEMP<br /> DJN 0, B<br /> DJN 1, TEMP<br /> DJN -1, A<br /> DJN 1, A<br /> DJN 1, B<br /> DJN -2, TEMP<br /></pre><br /><br />Unfortunately, the performance is poor, 56000 cycles to execute a <code>MOV</code>!<br /><br />The following code proves <code>DJN</code> is Turing complete by equivalence to SUBLEQ A, B, C:<br /><br /><pre> DJN 0, TEMP<br /> DJN 1, TEMP<br /> DJN 10, B<br /> DJN 4, SCRATCH<br /> DJN 3, SCRATCH<br /> DJN 1, TEMP<br /> DJN 1, B<br /> DJN -2, A<br /> DJN 1, A<br /> DJN -1, TEMP<br /> DJN C, SCRATCH<br /> DJN C, SCRATCH<br /> DJN -11, A<br /> DJN 1, A<br /> DJN -1, TEMP<br /></pre><br /><br />So, who's volunteering to implement the first self-interpreter? ;-)John Metcalfhttp://www.blogger.com/profile/09108374348083307900noreply@blogger.com2tag:blogger.com,1999:blog-6722581740507471912.post-45595380072005604152009-03-02T10:55:00.001+00:002012-07-06T21:47:03.890+01:00Happy 25th Birthday Core WarWhen David Jones and A. K. Dewdney produced their <a href="http://corewar.co.uk/cwg.txt">Core War Guidelines</a> in March 1984, they could hardly have imagined the success it would achieve. Core War is still going strong 25 years later and I'd like to wish everyone in the Core War community a very happy birthday.<div><br />
</div><div><span class="Apple-style-span" style="font-size:large;">Core War, a Short History:</span><br />
<div><br />
</div><div>Shortly after the guidelines were complete, an article in Dewdney's Computer Recreations column in <i>Scientific American</i> introduce the world to Core War. The wheels on the Core War machine had been put in motion.</div><div><br />
</div><div>The following year the <acronym title="International Core Wars Society">ICWS</acronym> was formed to standardise and promote Core War, with Mark Clarkson as director. The <acronym title="International Core Wars Society">ICWS</acronym> published <i>The Core Wars Standard</i> and organised the <a href="http://corewar.co.uk/icwt1986/index.htm">First International Core War Tournament</a> at the Computer Museum in Boston, Mass.<br />
<br />
William R. Buckley began publication of <i>The Core War Newsletter</i> in early 1987, providing a forum for Core War players. Early issues covered what we now consider the basic techniques of Core War. Later issues discussed advance topics, for example the holy grail of Core War: self-repairing programs.</div><div><br />
</div><div><span class="Apple-style-span" style="font-size:large;">Core War, 25 Years On:</span><br />
<br />
</div><div>Fast forward to 2009. Dozens of players are competing on the <a href="http://corewar.co.uk/hills.htm">Core War hills</a> and the possibilities seem endless. I can't help wondering what a Core War player from 1984 would make of our battle programs, or if they ever imagined how we'd be creating them 25 years later. Computer optimized constants and evolved code are the order of the day.</div><div><br />
</div><div>The <acronym title="International Core Wars Society">ICWS</acronym> has fallen by the wayside, as has <acronym title="The Core War Newletter">TCWN</acronym>. However, a number of irregular Core War journals have florished and the online Core War community organise the occasional tournament as an alternative to competing on the hill.</div><div><br />
</div><div>Let's hope Core War is still going strong in 2034, to celebrate it's 50th birthday! :-)</div><div><br />
</div><div><span class="Apple-style-span" style="font-size:large;">More About Core War:</span><br />
<br />
</div><p>Here are the top resources to discover more about Core War:</p><br />
<ul><li><a href="http://vyznev.net/corewar/guide.html">Beginner's Guide to Redcode</a> covers the basics of Redcode, the language of Core War</li>
<li><a href="http://corewar.co.uk/pmars">pMARS</a> is a portable Core War virtual machine, implemented in C</li>
<li><a href="http://corewar.co.uk/biblio.htm">The Core War Bibliography</a> lists tutorials covering almost every aspect of Core War</li>
<li><a href="http://www.koth.org/">KOTH.org</a> and <a href="http://sal.discontinuity.info">KOTH@SAL</a> organise the King of the Hill tournaments, played by email</li>
<li><a href="http://users.obs.carnegiescience.edu/birk/COREWAR/koenigstuhl.html">Koenigstuhl</a> is a huge archive of published Core War battle programs</li>
<li><a href="irc://irc.freenode.net/#COREWARS">#corewars</a> is the Core War IRC channel, hosted on <a href="irc://irc.freenode.net/#COREWARS">irc.freenode.net</a></li>
</ul></div>John Metcalfhttp://www.blogger.com/profile/09108374348083307900noreply@blogger.com5tag:blogger.com,1999:blog-6722581740507471912.post-45051012759082510632009-02-24T17:28:00.008+00:002009-02-25T13:16:29.146+00:00Implementing Forth in RedcodeI'm currently working on a threaded Forth interpreter in Redcode. The first version should provide about 20 key Forth instructions in 50 lines of code.<br /><br /><div><span class="Apple-style-span" style="font-size: large;">Threading</span></div><div><br />The Forth program will be stored as a list of subroutine calls, for example:<br /><pre> dat lit ; push 1111<br /> dat 1111<br /> dat lit ; push 1234<br /> dat 1234<br /> dat plus ; add TOS to 2OS<br /> dat udot ; display TOS<br /></pre>A more compact representation would be to store addresses in both the a-field and b-field. Unfortunately this would be at the expense of more complex flow control:<br /><pre> dat lit, 1111<br /> dat lit, 1234<br /> dat plus, udot<br /></pre>I'm open to suggestions how the interpreter can use the compact representation without causing too many difficulties.<div><br /></div><div><span class="Apple-style-span" style="font-size: large;">Instruction Set</span></div><div><br /></div>I'm planning to support the following instructions in version 1. Have I missed anything important, or have I included something which can be left out:<br /><br /><table><tbody><tr><th align="left">Ins</th><th align="left">Description</th></tr><tr><td>-</td><td>subtract TOS from 2OS</td></tr><tr><td>+</td><td>add TOS to 2OS</td></tr><tr><td>*</td><td>multiply TOS by 2OS</td></tr><tr><td>U.</td><td>print TOS as an unsigned number</td></tr><tr><td>SPACE</td><td>print a space</td></tr><tr><td>DUP</td><td>copy TOS</td></tr><tr><td>DROP</td><td>remove TOS</td></tr><tr><td>ABS</td><td>replace TOS with its absolute value</td></tr><tr><td>NEGATE</td><td>replace TOS with -TOS</td></tr><tr><td>!</td><td>2OS is stored at the address in TOS</td></tr><tr><td>+!</td><td>2OS is added to the address in TOS</td></tr><tr><td>@</td><td>fetch the value at the address in TOS</td></tr><tr><td>=</td><td>TRUE if TOS=2OS, else FALSE</td></tr><tr><td>SWAP</td><td>exchange TOS with 2OS</td></tr><tr><td>DEPTH</td><td>number of elements on stack</td></tr><tr><td>BEGIN</td><td>start of BEGIN .. UNTIL structure</td></tr><tr><td>UNTIL</td><td>if TRUE, return to matching BEGIN</td></tr><tr><td>DO</td><td>start of DO .. LOOP structure</td></tr><tr><td>LOOP</td><td>inc counter, jump to DO if below limit</td></tr></tbody></table><br /><div><span class="Apple-style-span" style="font-size: large;">Signed vs Unsigned</span></div><div><br /></div><div>Unfortunately numbers in Forth are signed and numbers in Redcode are unsigned. This affects a number of instructions, including division and comparison. Would it be worth the extra code to support unsigned numbers in Redcode Forth?</div><div><br /></div><div><span class="Apple-style-span" style="font-size: large;">Example Code</span></div><div><br /></div><div>The following example interprets +, U. and literals. New instructions can easily be added in Redcode. Support for calling new instuctions written in Forth needs to be added:</div></div><pre> org next<br /><br />stack dat 0, 0<br /><br />; LIT - place the next value on the stack<br /><br />lit mov.b }ip, <stack<br /> jmp next<br /><br />; + - remove 2OS and TOS and put their sum on stack<br /><br />plus add.b >stack, @stack<br /> jmp next<br /><br />; U. - remove and display TOS as an unsigned number<br /><br />udot mov.b @stack, <stack<br /> div #10, >stack<br /> mod #10, @stack<br /> add #48, @stack<br /> add #1, udcount<br /> jmn udot, <stack<br /> add #1, stack<br />udloop sts >stack, 0<br />udcount djn udloop, #0<br /> sts.a #32, 0<br /> jmp next<br /><br />; --------------------------------<br /><br />next<br />ip jmp @prog, }ip<br /><br />; --------------------------------<br /><br />prog<br /> dat lit ; push 1111<br /> dat 1111<br /> dat lit ; push 1234<br /> dat 1234<br /> dat plus ; add TOS to 2OS<br /> dat udot ; display TOS<br /><br /> end<br /></pre>John Metcalfhttp://www.blogger.com/profile/09108374348083307900noreply@blogger.com1tag:blogger.com,1999:blog-6722581740507471912.post-84548030661057776932009-02-16T13:32:00.000+00:002009-02-25T13:18:53.555+00:00Underload Interpreter in RedcodeUnderload is a stack-based esoteric programming language designed by ais523. A set of 8 single character instructions operate on a stack of variable length strings:<br /><br /><table><tbody><tr><th scope="col" align="left">Ins</th><th scope="col" align="left">Description</th></tr><tr><td>:</td><td>copy the top stack entry</td></tr><tr><td>!</td><td>drop the top stack entry</td></tr><tr><td>~</td><td>swap the top two stack entries</td></tr><tr><td>*</td><td>join the top two stack entries</td></tr><tr><td>S</td><td>display then drop the top stack entry</td></tr><tr><td>^</td><td>drop then run the top stack entry</td></tr><tr><td>a</td><td>enclose the top stack entry in parentheses</td></tr><tr><td>( )</td><td>add a new stack entry</td></tr></tbody></table><br />A combination of different factors make an interpreter for Underload an interesting project to tackle in Redcode:<div><ul><li>parsing single character instructions is easy, I don't like writing parsers</li><li>handling variable length data can be tricky</li><li>no operands / no side effects to worry about</li><li>only 8 instructions, the size of the interpreter should be reasonable</li><li>^ is the only means of flow control</li></ul><div>The final code weighs in at a mere 79 instructions. Here's the final version of the <a href="http://corewar.co.uk/assembly/underload.htm">Underload Interpreter</a>. If you have any improvements to suggest, please leave a comment below.</div></div>John Metcalfhttp://www.blogger.com/profile/09108374348083307900noreply@blogger.com0