Caution
This project is not activley maintained. Many libraries it uses are outdated.
Javascript MARS, Memory Array Redcode Simulator
Core War is a 1984 programming game created by D. G. Jones and A. K. Dewdney in which two or more battle programs (called "warriors") compete for control of a virtual computer. These battle programs are written in an abstract assembly language called Redcode. At the beginning of a game, each warrior is loaded into memory at a random location, after which each program executes one instruction in turn. The goal of the game is to cause the threads of opposing programs to terminate (which happens if they execute an invalid instruction), leaving the victorious program in sole possession of the core.
- Demo available at: https://gh.frazier.software/MARS.js/
- Compatible with node and browsers
- Unopinionated, fast, bare-bones ICWS'94 implementation.
- Includes support for the commonly used experimental opcodes
SEQ
,SNE
, andNOP
as well as A-field relative addressing modes\*
,{
, and}
. (aka EXT94) - Does not support P-Space extensions (
LDP
,STP
, andPIN
) or pMARS specific features such asFOR/ROF
or;assert
.
With npm installed, run
$ npm install --save git+https://github.com/chrisfrazier0/MARS.js.git#0.0.1
const mars = require('MARS.js')();
mars.load(/* ... */);
mars.stageAll();
mars.cycle();
console.log(mars.state);
Return a new MARS.js instance with the given opts
. Valid keys for opts
are:
- coreSize: [Number] size of the core available at
state.core
- minDistance [Number] minimum distance to separate warriors during staging
- instructionLimit [Number] maximum number of instructions per warrior
- threadLimit [Number] maximum number of allowed threads per warrior
Clears the current state and resets the array of loaded warriors.
Loads and compiles a warrior from a redcode source string.
- name: [String] name of the warrior, if not provided the name will be parsed
from the comments or default to
Nameless
- src: [String] redcode source of the warrior
Stages the specified warrior into the core at a given address. If no address is specified then the warrior is staged at a random location.
- warrior: [String/Number] name or id of the warrior to stage
- start: [Number] address to stage the warrior
Stage all of the currently loaded warriors.
Execute the next instruction and update the current mars.state
.
Finish the current instruction cycle and return the cycle count.
Clear the core, dirty set, and associated mars.state
data.
Randomize the execution order of the currently staged warriors.
- Fork it (https://github.com/chrisfrazier0/MARS.js/fork)
- Create your feature branch (
git checkout -b feature/fooBar
) - Commit your changes (
git commit -am 'Add some fooBar'
) - Push to the branch (
git push origin feature/fooBar
) - Create a new Pull Request
This project is licensed under the MIT License - see the LICENSE file for details