summaryrefslogtreecommitdiff
path: root/run_game.js
diff options
context:
space:
mode:
Diffstat (limited to 'run_game.js')
-rwxr-xr-xrun_game.js140
1 files changed, 140 insertions, 0 deletions
diff --git a/run_game.js b/run_game.js
new file mode 100755
index 0000000..20fd8c0
--- /dev/null
+++ b/run_game.js
@@ -0,0 +1,140 @@
+#!/usr/bin/env node
+
+if (process.argv.length != 4) {
+ console.log("Usage: ./run_game.js <seed> <num_turns>");
+ console.log("Seed needs to be a 32-digit hex number");
+ process.exit(1);
+}
+
+process.__state = {};
+process.__state.seed = process.argv[2];
+process.__state.num_turns = +process.argv[3];
+
+// -------------------- SHIMS --------------------
+
+window = {};
+localStorage = (function() {
+ const backing = new Map();
+
+ const getItem = function(key) {
+ if (backing.has(key)) return backing.get(key);
+ else return null;
+ };
+ const setItem = function(key, value) {
+ backing.set(key, value + "");
+ };
+ const removeItem = function(key) {
+ backing.delete(key);
+ };
+ const clear = function() {
+ backing.clear();
+ };
+
+ const proxy = new Proxy(backing, {
+ get: function(obj, prop) {
+ if (prop == "length") return backing.size;
+ if (prop == "key") throw new Error("localStorage.key() not supported");
+ if (prop == "getItem") return getItem;
+ if (prop == "setItem") return setItem;
+ if (prop == "removeItem") return removeItem;
+ if (prop == "clear") return clear;
+
+ return getItem(prop);
+ },
+ set: function(obj, prop, value) {
+ setItem(prop, value);
+ return true;
+ }
+ });
+
+ return proxy;
+})();
+
+window.localStorage = localStorage;
+
+document = {
+ addEventListener: function(evname) {
+ if (evname == "DOMContentLoaded") {}
+ else {
+ console.log("Foreign addEventListener call!");
+ process.exit(1);
+ }
+ },
+ getElementById: function(id) {
+ // console.log("gEBI(" + id + ")");
+ if (id == "gameInput") return {value: process.__state.num_turns};
+ if (id == "fpsInput") return {value: Infinity};
+ return {};
+ }
+};
+
+
+// -------------------- MAKE MATH.RANDOM REPEATABLE --------------------
+
+Math.random = (function() {
+ const xorshift128plus = require("xorshift128plus");
+ const rng = xorshift128plus.fromHex(process.__state.seed);
+
+ return function() {
+ return rng.next();
+ };
+})();
+
+
+// -------------------- LOAD BASE CONTROLLER --------------------
+
+for (const file of [
+ "./beta-decay.github.io/art_attack/botData.js",
+ "./beta-decay.github.io/art_attack/controller.js"]) {
+ eval(require("fs").readFileSync(file).toString());
+}
+
+
+// -------------------- REMOVE ANNOYING ENTRIES --------------------
+
+for (let i = 0; i < botData.length; i++) {
+ if (botData[i].name == "Muncher") {
+ botData.splice(i, 1);
+ i--;
+ }
+}
+
+
+// -------------------- PATCH UP THINGS --------------------
+
+updateBoard = function() {
+ console.log("-- TURN: " + turnNumber + " --");
+};
+drawGrid = function() {};
+drawBots = function() {};
+colourGrid = function() {};
+findWinner = function() {
+ const arr = findArea();
+ for (let i = 0; i < arr.length; i++) {
+ if (arr[i] === undefined) arr[i] = 0;
+ }
+
+ /* const winners = [];
+ const maxScore = Math.max.apply(Math, arr);
+
+ for (let i = 0; i < arr.length; i++) {
+ if (arr[i] == maxScore && !botData[i].eliminated) {
+ winners.push(botData[i].name);
+ }
+ }
+
+ console.log(arr);
+ console.log(JSON.stringify(winners)); */
+
+ for (let i = 0; i < arr.length; i++) {
+ arr[i] = [botData[i].name, arr[i]];
+ }
+
+ console.log(JSON.stringify(arr));
+};
+
+
+// -------------------- RUN THE GAME --------------------
+
+initialise();
+runGame();