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
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.
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.
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.
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.
Addressing modes
The symbol in front of a number says how to use it:
| #5 | the number 5 itself (immediate) |
| $5 | the cell 5 ahead (direct, the default) |
| @5 | go to cell 5, then follow its B-field |
| *5 | go to cell 5, then follow its A-field |
| <5 {5 | like @ and *, but subtract 1 first |
| >5 }5 | like @ and *, but add 1 afterwards |
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.
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.
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.
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
| DAT | data; any process that runs it dies |
| MOV | copy A to B |
| ADD SUB MUL | B = B ± × A |
| DIV MOD | B = B ÷ A; dividing by 0 kills the process |
| JMP | jump to A |
| JMZ / JMN | jump to A if B is zero / not zero |
| DJN | decrement B, jump to A if it's not zero |
| SEQ (CMP) | skip the next instruction if A equals B |
| SNE | skip the next instruction if A differs from B |
| SLT | skip the next instruction if A is less than B |
| SPL | start a new process at A |
| NOP | do 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.
| .A | A-field to A-field |
| .B | B-field to B-field |
| .AB | A-field to B-field |
| .BA | B-field to A-field |
| .F | both: A to A and B to B |
| .X | both, crossed: A to B and B to A |
| .I | the whole instruction |
Rules and syntax
| core | 8000 cells |
| time limit | 80,000 cycles, then it's a tie |
| processes | at most 8000 per warrior |
| length | at most 100 instructions |
| distance | warriors start at least 100 cells apart |
| label | loop MOV 0, 1, a name for an address |
| EQU | step EQU 4, a named constant |
| ORG / END | where execution starts |
| ;name ;author | comments that name your warrior |