From 495090873cf62a1ca698cee18a2d292fc30aa292 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Sat, 27 May 2023 19:28:16 +0200 Subject: Stuff. --- tools/genmove.js | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++++ tools/genpieces.js | 33 +++++++++++++++ 2 files changed, 148 insertions(+) create mode 100644 tools/genmove.js create mode 100644 tools/genpieces.js (limited to 'tools') diff --git a/tools/genmove.js b/tools/genmove.js new file mode 100644 index 0000000..a1dbc19 --- /dev/null +++ b/tools/genmove.js @@ -0,0 +1,115 @@ +"use strict" + +function array_insert(array, index, item) { + for (let i = array.length; i > index; --i) + array[i] = array[i - 1] + array[index] = item +} + +function set_add(set, item) { + let a = 0 + let b = set.length - 1 + while (a <= b) { + let m = (a + b) >> 1 + let x = set[m] + if (item < x) + b = m - 1 + else if (item > x) + a = m + 1 + else + return + } + array_insert(set, a, item) +} + +const ITALIA = 1 +const ASIA = 2 +const GALLIA = 3 +const MACEDONIA = 4 +const PANNONIA = 5 +const THRACIA = 6 + +const AEGYPTUS = 7 +const AFRICA = 8 +const HISPANIA = 9 + +const BRITANNIA = 10 +const GALATIA = 11 +const SYRIA = 12 + +const ALAMANNI_HOMELAND = 13 +const FRANKS_HOMELAND = 14 +const GOTHS_HOMELAND = 15 +const NOMADS_HOMELAND = 16 +const SASSANIDS_HOMELAND = 17 + +const MARE_OCCIDENTALE = 18 +const MARE_ORIENTALE = 19 +const OCEANUS_ATLANTICUS = 20 +const PONTUS_EUXINUS = 21 + +const names = [ + "null", + "ITALIA", + "ASIA", + "GALLIA", + "MACEDONIA", + "PANNONIA", + "THRACIA", + "AEGYPTUS", + "AFRICA", + "HISPANIA", + "BRITANNIA", + "GALATIA", + "SYRIA", + "ALAMANNI_HOMELAND", + "FRANKS_HOMELAND", + "GOTHS_HOMELAND", + "NOMADS_HOMELAND", + "SASSANIDS_HOMELAND", + "MARE_OCCIDENTALE", + "MARE_ORIENTALE", + "OCEANUS_ATLANTICUS", + "PONTUS_EUXINUS", +] + +const ADJACENT = [ [] ] + +for (let a = 1; a <= 21; ++a) + ADJACENT[a] = [] + +function adj(a, ...bs) { + for (let b of bs) { + set_add(ADJACENT[a], b) + set_add(ADJACENT[b], a) + } +} + +adj(ITALIA, GALLIA, PANNONIA, MARE_OCCIDENTALE) +adj(AEGYPTUS, AFRICA, SYRIA, NOMADS_HOMELAND, MARE_ORIENTALE) +adj(AFRICA, HISPANIA, AEGYPTUS, NOMADS_HOMELAND, MARE_OCCIDENTALE, MARE_ORIENTALE, OCEANUS_ATLANTICUS) +adj(ASIA, THRACIA, GALATIA, PONTUS_EUXINUS, MARE_ORIENTALE) +adj(BRITANNIA, OCEANUS_ATLANTICUS) +adj(GALATIA, ASIA, SYRIA, SASSANIDS_HOMELAND, PONTUS_EUXINUS, MARE_ORIENTALE) +adj(GALLIA, HISPANIA, ITALIA, PANNONIA, FRANKS_HOMELAND, OCEANUS_ATLANTICUS, MARE_OCCIDENTALE) +adj(HISPANIA, AFRICA, GALLIA, OCEANUS_ATLANTICUS, MARE_OCCIDENTALE) +adj(MACEDONIA, PANNONIA, THRACIA, MARE_OCCIDENTALE, MARE_ORIENTALE) +adj(PANNONIA, ITALIA, GALLIA, THRACIA, MACEDONIA, FRANKS_HOMELAND, ALAMANNI_HOMELAND, MARE_OCCIDENTALE) +adj(SYRIA, AEGYPTUS, GALATIA, SASSANIDS_HOMELAND, MARE_ORIENTALE) +adj(THRACIA, PANNONIA, MACEDONIA, ASIA, GOTHS_HOMELAND, PONTUS_EUXINUS, MARE_ORIENTALE) + +adj(ALAMANNI_HOMELAND, FRANKS_HOMELAND, PANNONIA, THRACIA, GOTHS_HOMELAND) +adj(FRANKS_HOMELAND, GALLIA, PANNONIA, ALAMANNI_HOMELAND) +adj(GOTHS_HOMELAND, ALAMANNI_HOMELAND, THRACIA, PONTUS_EUXINUS) +adj(NOMADS_HOMELAND, OCEANUS_ATLANTICUS, AFRICA, AEGYPTUS) +adj(SASSANIDS_HOMELAND, PONTUS_EUXINUS, GALATIA, SYRIA) + +adj(MARE_OCCIDENTALE, OCEANUS_ATLANTICUS, MARE_ORIENTALE) + +adj(ALAMANNI_HOMELAND) + +console.log("const ADJACENT = [") +for (let i = 0; i <= 21; ++i) { + console.log("\t/*", names[i], "*/ [", ADJACENT[i].map(i => names[i]).join(", "), "],") +} +console.log("]") diff --git a/tools/genpieces.js b/tools/genpieces.js new file mode 100644 index 0000000..01d7edb --- /dev/null +++ b/tools/genpieces.js @@ -0,0 +1,33 @@ +var ix = 0 + +function mk(name, n) { + var a = ix + var b = ix + n - 1 + console.log("const " + name + "_data = " + a) + ix = b + 1 +} + +function size(name) { + console.log("const " + name + "_size = " + (ix)) +} + +mk("province", 12) +mk("legion", 33) +mk("rival_emperor", 3) +mk("barbarian_leader", 3) +mk("alamanni", 10) +mk("franks", 10) +mk("goths", 10) +mk("red_governor", 6) +mk("red_general", 6) +mk("blue_governor", 6) +mk("blue_general", 6) +size("data_2p") +mk("nomads", 10) +mk("yellow_governor", 6) +mk("yellow_general", 6) +size("data_3p") +mk("sassanids", 10) +mk("green_governor", 6) +mk("green_general", 6) +size("data_4p") -- cgit v1.2.3