Learn Core War.
Twelve lessons, zero install.

From "what's a core?" to traps and Nano warriors. Every example runs in the arena with one click, and the full Redcode reference is at the bottom.

๐Ÿ“š Start the lessons ๐Ÿ“– Redcode reference ๐Ÿ† Challenges

Lessons

Read them in order. Each "Try it" button opens the arena with that warrior loaded. Then press Fight.

1

Memory is a ring of cells

The battlefield is called the core: 8000 cells in the standard game. Every cell holds one instruction, and the end wraps around to the start, so cell 8000 is cell 0 again.

Addresses are relative: 0 means this cell, 1 the next one, -1 the previous one. Neither warrior knows where it was loaded.

Empty cells hold DAT 0, 0. A program that executes a DAT dies. Make every enemy process hit a DAT and you win. If nobody dies within 80,000 cycles, it's a tie.

2

Your first warrior: the Imp


      

This program copies itself into the next cell. The next cell is exactly where it runs next, so it crawls through memory forever.

The Imp almost never wins, but it is very hard to kill. It mostly ends in ties.

โš”๏ธ Try it in the arena
3

Bombing: the Dwarf


      

bomb is a DAT whose B-field works as a target pointer. Each loop adds 4 to the target, then copies the bomb to wherever the pointer says (that's what @ means).

It covers every 4th cell. The Dwarf itself is 4 cells long, so its own bombs miss it.

โš”๏ธ Try it in the arena
4

Addressing modes

The symbol in front of a number says how to use it:

#5the number 5 itself (immediate)
$5the cell 5 ahead (direct, the default)
@5go to cell 5, then follow its B-field
*5go to cell 5, then follow its A-field
<5  {5like @ and *, but subtract 1 first
>5  }5like @ and *, but add 1 afterwards
5

More processes: SPL


      

SPL starts a new process. A warrior gets one instruction per turn however many processes it has, so more processes doesn't mean more speed. It means the warrior is harder to kill.

A replicator like this one copies itself across the core faster than most bombers can hit it.

โš”๏ธ Try it in the arena
6

Look before you shoot: scanners


      

SNE compares two cells. If they differ, one of them isn't empty memory, so something is there. The scanner bombs both cells and keeps looking.

When the scan finishes, it wipes every cell of the core except its own.

โš”๏ธ Try it in the arena
7

Rock, paper, scissors

Most warriors are one of three kinds:

Stones (bombers like the Dwarf) are small and fast. Papers (replicators) make copies faster than stones can bomb them. Scissors (scanners) find papers and cut them down, but stones are too small for them to find in time.

Paper beats stone, scissors beat paper, stone beats scissors, roughly. Good warriors mix two kinds.

8

Safety in numbers: imp rings


      

Three imps, spaced (CORESIZE+1)/3 cells apart, take turns: each one copies itself onto the spot the next one is about to run. Together they advance one cell per round, like a single fat imp.

SPL 1 followed by MOV -1, 0 is a classic trick for getting exactly three processes. Bombers struggle to kill all three in time.

โš”๏ธ Try it in the arena
9

Clearing the core


      

SPL #0 creates an endless stream of processes, and each one wipes one cell and moves the pointer on. Eventually every cell gets a DAT, including the ones the enemy is hiding in.

The trick: when the pointer wraps all the way around and hits itself, the bomb that lands there resets it to 4, so the Broom never sweeps away its own code. It's one of the few things that reliably kills an Imp.

โš”๏ธ Broom vs Imp
10

Traps: make them work for you


      

A DAT bomb kills one process. Against a replicator running thousands of them, that's hopeless. So instead of killing, trap: plant a JMP on the enemy that leads into an SPL 0 loop.

Trapped processes multiply uselessly instead of copying or bombing, and a final DAT clear wipes them all out. That's how Mousetrap beats Mice nine times out of ten.

โš”๏ธ Mousetrap vs Mice
11

Small cores: Tiny and Nano

Same game, less room. Tiny has 800 cells and allows 20 instructions. Nano has 80 cells and only 5 instructions. Warriors start just a few cells apart and battles are over in a blink.

Long, clever warriors don't fit, so there are fewer tricks to learn. A beginner, an evolutionary algorithm or an AI has a real chance against experienced players here. Write numbers in terms of CORESIZE and the same warrior works on all three.

โš›๏ธ Try a Nano fight
12

Your turn

Open the template in the arena, change something, and press Test Warrior 1 against every built-in. Or go straight for the challenges. Your score is points per 100 rounds: 3 for a win, 1 for a tie, so the maximum is 300.

Getting above 150 takes some real thought. Getting above 200 means you've found something clever.

โœ๏ธ Open the template

Redcode reference

Everything the simulator on this site understands. It follows the ICWS '94 draft, the standard used by Core War competitions since 1994.

Rule sets

StandardTinyNano
core size800080080
cycles before a tie80,0008,000800
max processes800080080
max length100205
min distance100205

Scoring: 3 points per win, 1 per tie, 0 per loss.

Instructions

DATdata; any process that runs it dies
MOVcopy A to B
ADD SUB MULB = B + A, B โˆ’ A, B ร— A
DIV MODB = B รท A, B mod A; dividing by 0 kills the process
JMPjump to A
JMZ / JMNjump to A if B is zero / not zero
DJNdecrement B, jump to A if it's not zero
SEQ (CMP)skip the next instruction if A equals B
SNEskip the next instruction if A differs from B
SLTskip the next instruction if A is less than B
SPLqueue the next instruction, then a new process at A
NOPdo nothing

Addressing modes

#immediate: the number itself, pointing at this instruction
$direct: the cell that many steps away (default)
@B-indirect: go there, then follow its B-field
*A-indirect: go there, then follow its A-field
<like @, but decrement that B-field first
{like *, but decrement that A-field first
>like @, but increment that B-field afterwards
}like *, but increment that A-field afterwards

All addresses are relative to the instruction being executed, and wrap around the core.

Modifiers

A modifier like MOV.AB says which fields the instruction reads and writes.

.AA-field to A-field
.BB-field to B-field
.ABA-field to B-field
.BAB-field to A-field
.Fboth: A to A and B to B
.Xboth, crossed: A to B and B to A
.Ithe whole instruction (MOV, SEQ, SNE; arithmetic and SLT treat it as .F)

Default modifiers

Leave the modifier out and it's chosen from the instruction and the modes:

DAT NOP.F
MOV SEQ SNE.AB if A is #, else .B if B is #, else .I
ADD SUB MUL DIV MOD.AB if A is #, else .B if B is #, else .F
SLT.AB if A is #, else .B
JMP JMZ JMN DJN SPL.B

Syntax

labelloop MOV 0, 1 names an address; a trailing colon is allowed
EQUstep EQU 4 defines a constant
ORGORG start sets where execution begins
ENDends the warrior; END start also sets the start
FOR / ROFi FOR 3 โ€ฆ ROF repeats lines; &i becomes 01, 02, 03
expressions+ - * / %, parentheses, comparisons, && ||
one operandDAT x means DAT 0, x; JMP x means JMP x, 0
;name ;authorcomments that name your warrior

Predefined constants

CORESIZEcells in the core
MAXCYCLEScycles before a tie
MAXPROCESSESprocess limit per warrior
MAXLENGTHmaximum instructions
MINDISTANCEminimum gap between warriors
WARRIORSnumber of warriors (2)

Use them to write warriors that work under every rule set, e.g. step EQU (CORESIZE+1)/3.

How a cycle runs

  1. Each warrior has a queue of processes. It starts with one, at its start address.
  2. Warriors take turns. On its turn, a warrior takes the first process off its queue and runs one instruction.
  3. That process goes back on the end of the queue at its next address, unless it ran a DAT or divided by zero.
  4. SPL queues the next instruction first, then the new process (if the queue isn't full).
  5. A warrior with an empty queue is dead. The last one alive wins. If time runs out, it's a tie.

Warriors are loaded at random positions at least MINDISTANCE apart, so every round is different. That's why scores are averaged over many rounds.

Not supported (yet)

P-space (LDP, STP, PIN), battles between more than two warriors, and read/write distance limits. Standard '94 warriors that don't use these run unchanged.