summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2023-05-27 19:28:16 +0200
committerTor Andersson <tor@ccxvii.net>2023-07-07 18:39:23 +0200
commit495090873cf62a1ca698cee18a2d292fc30aa292 (patch)
tree7b179325adf10a13ab3827ddafe320249a2d3e06 /tools
parent069a9310cea47805d5b8d55d04961b9e5b3d9527 (diff)
downloadtime-of-crisis-495090873cf62a1ca698cee18a2d292fc30aa292.tar.gz
Stuff.
Diffstat (limited to 'tools')
-rw-r--r--tools/genmove.js115
-rw-r--r--tools/genpieces.js33
2 files changed, 148 insertions, 0 deletions
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")