//===== Constructor const Stack = function() { // This is the heart of the robot movement architecture. // Its elements are of the form { robotId, i, j } this.moves = []; document.addEventListener('L-arrow', this.msgArrow.bind(this)); document.addEventListener('G-robots', this.msgRobots.bind(this)); }; Stack.prototype.msgRobots = function(evt) { this.moves = evt.detail.body.map(({ id, i, j }) => ({ id, i, j })); const evtStack = new CustomEvent('L-stack', { detail: this.moves }); document.dispatchEvent(evtStack); }; Stack.prototype.msgArrow = function(evt) { this.moves.push(evt.detail); const evtStack = new CustomEvent('L-stack', { detail: this.moves }); document.dispatchEvent(evtStack); }; // reset destroys stack // undo decrements from stack // store chops stack // moves is stack length // replay shares stack // starting spot is present in stack