Two programs.
One memory.
The last one running wins.

Core War is a programming game from 1984. You write a tiny program, called a warrior, in an assembly language called Redcode. It shares memory with an enemy program, and each one tries to make the other crash. Your code is the only thing that decides who wins.

⚔️ Enter the arena Learn it in 10 minutes 🏆 Take a challenge

The arena

Pick two warriors or write your own, then press Fight. Each square is one memory cell. A pale square means a warrior wrote to that cell, a bright square means it ran code there. Hover over the board to read any cell.

Choose your fighters

Warrior 1
ready
—VS—
W1 ran code W1 wrote W2 ran code W2 wrote running processes
cycle 0hover over a cell
Keys: Space fight / pause · S step · N new battle · R random matchup
Warrior 2
ready

Challenges

Nine goals, from "don't lose" to "beat everything". Accept one, write Warrior 1, press Check. Built-in warriors don't count. Bring your own code.

Learn Core War

Eight short lessons. Each Load button puts that warrior in Warrior 1's slot. 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.

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.

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.

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.

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

Your turn

Load the template, 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.

Redcode reference

This follows the ICWS '94 draft standard, the rules most Core War competitions have used since 1994.

Instructions

DATdata; any process that runs it dies
MOVcopy A to B
ADD SUB MULB = B ± × A
DIV MODB = B ÷ 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
SPLstart a new process at A
NOPdo nothing

Modifiers

Each instruction has two fields, A and B. A modifier like MOV.AB says which fields are used. If you leave it out, a sensible default is picked.

.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

Rules and syntax

core8000 cells
time limit80,000 cycles, then it's a tie
processesat most 8000 per warrior
lengthat most 100 instructions
distancewarriors start at least 100 cells apart
labelloop MOV 0, 1, a name for an address
EQUstep EQU 4, a named constant
ORG / ENDwhere execution starts
;name ;authorcomments that name your warrior