Thursday, 9 December 2010

Corewar Programming Contest

The First International Corewar Programming Contest has just been announced, with a first prize of $50 sponsored by www.corewar.info.

The competition takes place in the unexplored area between '94nop and LP settings which has recently been investigated by Fizmo in Redcode Talk.

The exact settings are as follows:

Standard:CWS'94
Coresize:8000
Processes:200
Entry length:20
Points win:3
Points tie:1
Cycles:80000
Rounds:1000

The pMARS command line is pmars -p 200 -l 20 -r 1000. STP and LDP are forbidden, up to two entries are allowed and battles will take part in a round-robin tournament.

For more information, take a look at the announcement in rec.games.corewar.

Friday, 5 November 2010

Four Lines of Redcode

Sierpinski triangle

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:

        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

The magic incantation for pMARS is pmars -v 132. Alternatively set the width to 128 to view using CoreWin :-)

Sunday, 5 September 2010

Redcode Talk Issue 1

Redcode Talk
Christian Schmidt recently published the first issue of Redcode Talk. The issue contains a couple of articles by Fizmo:

  • The undiscovered area between LP & 94draft
  • Random Warrior Talk: One Man Army v1.0

Friday, 23 July 2010

Happy Numbers

Today's Programming Praxis 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 72=49, 42+92=97, 92+72=130, 12+32+02=10, 12+02=1.

Here's my solution in Redcode:

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

Sunday, 24 January 2010

Cross Simulator Core Graphics

One 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:

Simulator
Display Width
pMARS SDL mode 0
157
pMARS SDL mode 2
126
CoreWin
128
ARES
80
nMars
various

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 VERSION constant to determine the simulator:

Simulator
Version
pMARS SDL mode 0
92
pMARS SDL mode 2
92
CoreWin
230
ARES
0
nMars
93

Putting the two together we can write the following code which sets the correct width for pMARS SDL, CoreWin and ARES:

width equ ( (VERSION==92)*157 + (VERSION==230)*128 + (VERSION==0)*80 )

Thursday, 7 January 2010

Fractals in Corewar

Koch Curve in RedcodeIn 1997 Anton Marsden organised a Corewar tournament with a difference.  The three rounds challenged players to use Redcode to solve a variety of problems.

In the third round of Anton's Corewar Tournament the challenge was to write a Redcode program to draw a pretty picture.  First place was taken by Ilmari Karonen with a fractal fern.

Here's my own attempt at creating a pretty picture in the core view of pMARS. It's a fractal known as the Koch Curve.

Here's the program, just 18 instructions:

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

Have you tried to write a graphical display in Corewar?