Uniprocessor CoreWars (UCoreWars)
In the uniprocessor version, there is only a single RVM and all
programs compete for ownership of memory in its RAM. Each player
writes a single RedCode assembly language PROGRAM and uses the
ASSEMBLER to assemble it into a binary PROGRAM IMAGE. The RVM loads
the PROGRAM IMAGESs into its RAM, creates an initial PROCESS for each
PROGRAM, and assigns each to a PROCESS GROUP for the corresponding
player. The engine then waits for the user to start the game. When
the game is started, the RVM executes PROCESSEs from each PROCESS
GROUP in round-robin fashion (as specified below) until the game
ends.
Each memory cell in RAM is either unowned or owned by a single
PROCESS GROUP. Whenever a PROCESS writes to a memory cell, that cell
becomes owned by the corresponding PROCESS GROUP. If a PROCESS
attempts to execute an instruction from a cell owned by a different
PROCESS GROUP, it is considered to be an ILLEGAL OPERATION and the
executing PROCESS is HALTED.
The game runs until either the user stops the game, the time expires,
or only a single PROCESS GROUP contains any remaining running
PROCESSES. When the game ends, the last PROCESS GROUP left alive (and
the corresponding PLAYER) wins. If more than one PROCESS GROUP is
alive when the game ends, the PROCESS GROUP owning the greatest number
of memory cells wins.
- RVM Initialization
- At the start of a game, before loading any
PROGRAM IMAGEs, every cell in the RVM's RAM is initialized to UNOWNED
and containing the HLT instruction. One PROCESS GROUP is
created for each PLAYER, but no PROCESSES are created for any PLAYER
until a PROGRAM IMAGE is loaded for that PLAYER.
- PROGRAM IMAGE Loading
- Each binary program is initially loaded
into RAM beginning at a random location. The initial locations
are picked such that:
- A program MUST be loaded contiguously. That is, if a program
is of length
words and is loaded starting at cell
, then
after loading the program will occupy cells
,
,
,
...,
.
- No program may be loaded overlapping another program.
- No program may run off the end of memory. I.e., if the RAM of
the current RVM is
words and a program is of length
,
then the highest legal starting location for that program is
.
If a set of programs is too large to all fit into memory
simultaneously, the RVM engine MUST treat this as a RECOVERABLE
ERROR by reporting this condition to the user and allowing the
user to specify a new set of programs to load.
- Process Initialization
- When a PROCESS is created, its
instruction pointer is initialized to the beginning of the program
code (if the PROCESS was created at the start of the game) or with
the location specified by the frk instruction (if the
PROCESS was created by a fork from an existing process). All other
registers for the new PROCESS are initialized to 0.
- Round Robin Scheduling
- The RVM executes one instruction from
each RUNNABLE PROCESS GROUP in turn, returning to the first PROCESS
GROUP after the last has executed. Within each PROCESS GROUP, each
PROCESS is scheduled in turn until all PROCESSES have received one
cycle, and then execution returns to the first process.
Example: Suppose that there are currently two PROCESS GROUPs,
and
.
contains three PROCESSes,
,
,
and
, while
contains two PROCESSes,
and
. Then the scheduling order will be
- Scoring
- Each PROCESS GROUP has a score equal to the number of
memory cells that it owns. When the score of a PROCESS GROUP reaches
0, that PROCESS GROUP becomes non-RUNNABLE.
- End of Game
- The game ends when either:
- The user ends the game from the user interface.
- The specified duration (total number of clock cycles) is
exceeded.
- Only a single RUNNABLE PROCESS GROUP remains.
- Victory Conditions
- When the game ends, the winning PROCESS
GROUP (i.e., PLAYER) is:
- If just a single PROCESS GROUP remains RUNNABLE at the end of
the game, that PROCESS GROUP (and its PLAYER) wins.
- If more than one PROCESS GROUP remains RUNNABLE at the end
of the game, the PROCESS GROUP that owns the most memory wins.
- Instruction Set
- In the uniprocessor version, the RVM executes
all instructions except the open, rsw,
rfrk, and close instructions. Attempt to execute
those instructions in a uniprocessor game is an ILLEGAL OPERATION
by the executing PROCESS. A PROCESS MAY, however, execute a
distributed game system call (see Appendix A,
Table 2) in a uniprocessor game. In this case, the
system call simply has no effect.
Terran Lane
2004-03-29