瀏覽代碼

Add ability to set computers memory to a new stack

Added the SetMemory function, which allows you to set the computer's
memory to an entirely new stack.
ApisNecros 1 年之前
父節點
當前提交
9896b63595
共有 1 個文件被更改,包括 13 次插入0 次删除
  1. 13 0
      IntComp/Computer.js

+ 13 - 0
IntComp/Computer.js

@@ -152,6 +152,19 @@ module.exports = class Computer {
     Reset() {
         this.stack = new Stack(this._initialMemory);
     }
+
+    /**
+     * Sets the computer's memory to a new stack
+     *
+     * Note: This resets the computer's initial memory, so `Reset` will use this value
+     *
+     * @param {number[]} stack The new memory stack for the computer
+     * @returns {void}
+     */
+    SetMemory(stack) {
+        this._initialMemory = DeepClone(stack);
+        this.stack = new Stack(stack);
+    }
 };
 
 /**