'use strict'; const { Core } = require('./core.js'); const { DAT, MOV, ADD, SUB, CMP, SLT, JMP, JMZ, JMN, DJN, SPL, } = require('./instruction.js'); class Warrior { constructor(start) { this.queue = [start]; } isDead() { return (this.queue.length === 0); } append(heads) { this.queue.push(...heads); } next() { const pc = this.queue[0]; this.queue = this.queue.slice(1); return pc; } peek() { const pc = this.queue[0]; return pc; } }; class RedcodeVm { constructor(coresize, warriors) { this.core = new Core(coresize); this.warriors = this.core.initialize(warriors) .map(start => new Warrior(start)); } step() { let running = 0; for (let i=0; i warrior.isDead() ? count : count+1, 0 ); } run(maxSteps) { let steps = 0; while(this.warriorsAlive() > 1 && steps < maxSteps) { this.step(); steps += 1; } return this.warriors.map( (w, i) => ({ warrior: i, alive: !w.isDead() }) ); } }; exports.RedcodeVm = RedcodeVm;