diff options
author | Tor Andersson <tor@ccxvii.net> | 2023-05-27 19:28:16 +0200 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2023-07-07 18:39:23 +0200 |
commit | 495090873cf62a1ca698cee18a2d292fc30aa292 (patch) | |
tree | 7b179325adf10a13ab3827ddafe320249a2d3e06 /tools/genmove.js | |
parent | 069a9310cea47805d5b8d55d04961b9e5b3d9527 (diff) | |
download | time-of-crisis-495090873cf62a1ca698cee18a2d292fc30aa292.tar.gz |
Stuff.
Diffstat (limited to 'tools/genmove.js')
-rw-r--r-- | tools/genmove.js | 115 |
1 files changed, 115 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("]") |