You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
910 B
31 lines
910 B
//===== 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
|