COREDUEL

REDCODE MANUAL

CoreDuel implements the ICWS'94 standard with the pMARS extensions (p-space, FOR/ROF, EQU expressions). If you know pMARS, everything here should look familiar.

0. What this game is

You write small programs, bots, and send them into the Arena to fight other bots. A bot is written in Redcode, an assembly-like language with 19 instructions. All bots of a match are loaded into one shared memory, the core: a ring of 8000 cells (the end wraps around to the start) inside a simple emulated computer called MARS. Nothing else exists in that computer: no screen, no files, only instructions in cells and a few processes that execute them.

Every bot starts with one process at a random position, at least 100 cells away from the others. The emulator gives the bots turns in rotation; on its turn a bot executes one instruction of one of its processes. A process dies when it executes a DAT instruction (or divides by zero); a bot dies when its last process is gone. Because all bots share the memory, the way to win is to overwrite the opponent's code with DAT bombs, scan the core for it, or flood the core with copies of yourself, while keeping your own code alive.

A round ends when only one bot is left or after 80000 cycles. A match is one or more rounds; the survivors of each round score points and the best total wins. That is the whole game: write a better program than the other player.

How to start:

1. The core

The core is a ring of 8000 cells. Each cell holds one instruction. Addresses wrap: cell 7999 + 1 = cell 0. There are no absolute addresses in Redcode; every address is relative to the instruction that uses it.

Before a round every cell is DAT.F $0, $0. Warriors are placed at random positions at least MINDISTANCE (100) cells apart. Each warrior starts with one process at its ORG.

Processes take turns: warrior A executes one instruction, then warrior B, and so on. A warrior with several processes runs them round-robin, one per turn.

A process dies when it executes DAT, or divides by zero. A warrior dies when its last process dies. The round ends when one warrior is left or after MAXCYCLES (80000) cycles.

2. Program layout

;redcode-94
;name Dwarf
;author A. K. Dewdney
;strategy Bombs every 4th cell.
;assert CORESIZE == 8000
        ORG     start
target  DAT.F   #0, #0
start   ADD.AB  #4, target
        MOV.AB  #0, @target
        JMP     start
        END

3. Instruction syntax

label   OPCODE.MOD   A-mode A-value, B-mode B-value   ; comment

Every instruction has an opcode, a modifier, an A operand and a B operand. Each operand is an addressing mode plus a value. Values are expressions (see 8) evaluated relative to the instruction's own address.

If you write only one operand, the assembler fills the other one:

4. Addressing modes

Every operand is resolved to a pointer (a cell address) before the opcode runs. Both operands are always evaluated, A first, even when the opcode ignores one of them. That is why pre/post-increment side effects happen even in JMP.

Note: in ICWS'94 the immediate operand still has a pointer, the instruction itself. MOV.I #0, 1 copies the whole instruction one cell forward. This is the classic Imp.

5. Modifiers

The modifier says which fields the opcode reads and writes. For an instruction with A-pointer a and B-pointer b:

Default modifier when you omit it:

6. Opcodes

All arithmetic is modulo CORESIZE. Numbers in the core are always 0..7999; -1 is stored as 7999.

7. Directives

        ORG     loop
loop    FOR     3
        MOV.I   #0, &loop
        ROF

8. Expressions

Operators, highest priority first: unary - + !, then * / % (integer, truncating), then + -, then comparisons == != < > <= >=, then && and ||. Parentheses are allowed. Comparisons yield 1 or 0.

Predefined constants: CORESIZE, MAXCYCLES, MAXPROCESSES, MAXLENGTH, MINDISTANCE, PSPACESIZE, ROUNDS, WARRIORS (2), VERSION (92), CURLINE (index of the current instruction).

A label used in an expression is its distance from the current instruction, so label+1 is the cell after label, and start-target is a plain number of cells.

9. P-space

Each warrior has a private array of PSPACESIZE (500) cells that survives between rounds of a match. Indices wrap. Cell 0 is special and always private: at the start of each round it holds the previous result, 0 if the warrior died, otherwise the number of surviving warriors (1 = win, 2 = tie). In the first round it holds CORESIZE-1.

LDP.AB #0, x loads that result into the B-field of x. STP.B x, #1 stores the B-field of x into cell 1. A warrior can use this to switch strategy after a loss.

10. Match rules

11. Common patterns