|
@@ -1,5 +1,6 @@
|
|
|
const Stack = require("./Stack");
|
|
|
const ComputerParameterMode = require("./ComputerParameterMode");
|
|
|
+const { DeepClone } = require("./common");
|
|
|
|
|
|
/**
|
|
|
* An Intcode Computer for the Advent of Code 2019 challenge
|
|
@@ -8,6 +9,7 @@ const ComputerParameterMode = require("./ComputerParameterMode");
|
|
|
*/
|
|
|
module.exports = class Computer {
|
|
|
constructor(stack) {
|
|
|
+ this._initialMemory = DeepClone(stack);
|
|
|
this.stack = new Stack(stack);
|
|
|
this.OPCODES = {
|
|
|
ADD: 1,
|
|
@@ -141,6 +143,15 @@ module.exports = class Computer {
|
|
|
DumpMemory() {
|
|
|
console.log(this.stack.Dump());
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Resets the computer's memory to the value it was created with
|
|
|
+ *
|
|
|
+ * @returns {void}
|
|
|
+ */
|
|
|
+ Reset() {
|
|
|
+ this.stack = new Stack(this._initialMemory);
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
/**
|