summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2024-05-01 14:06:10 +0200
committerTor Andersson <tor@ccxvii.net>2024-05-01 17:28:58 +0200
commit687e35cda69c6db8454ad4860cdc9e1df7b39d75 (patch)
tree8c7bb7eae75eb6af28c605e1357acf42731d7982
parent39354efa24e130116930e168850c018f7ed9650a (diff)
downloadplantagenet-687e35cda69c6db8454ad4860cdc9e1df7b39d75.tar.gz
calculate engagements with ravine
-rw-r--r--rules.ts32
-rw-r--r--tools/engage.js167
2 files changed, 198 insertions, 1 deletions
diff --git a/rules.ts b/rules.ts
index 7bce062..23297fc 100644
--- a/rules.ts
+++ b/rules.ts
@@ -5601,6 +5601,11 @@ states.exile_spoils = {
*/
+// See tools/engage.js for generating this table
+const ENGAGEMENTS = [null,null,null,null,null,null,null,null,null,[[2,5]],[[2,4]],[[2,4,5]],[[2,3]],[[2,3,5]],[[2,3,4]],[[2,3,4,5]],null,[[5,1]],[[1,4]],[[1,4,5]],[[3,1]],[[3,1,5]],[[1,3,4]],[[1,3,4,5]],null,[[1,2,5]],[[1,2,4]],[[1,4],[2,5]],[[1,2,3]],[[2,5],[3,1]],[[1,2,3,4]],[[1,3,4],[2,5]],null,[[0,5]],[[0,4]],[[0,4,5]],[[0,3]],[[0,3,5]],[[0,3,4]],[[0,3,4,5]],null,[[0,2,5]],[[0,2,4]],[[2,5],[0,4]],[[0,2,3]],[[0,3],[2,5]],[[0,3],[2,4]],null,null,[[0,1,5]],[[0,1,4]],[[0,1,4,5]],[[0,1,3]],[[0,3],[5,1]],[[0,3],[1,4]],[[0,3],[1,4,5]],null,[[0,1,2,5]],[[0,1,2,4]],[[0,1,4],[2,5]],[[0,1,2,3]],null,[[0,3],[1,2,4]],[[0,3],[1,4],[2,5]]]
+const ENGAGEMENTS_47 = [[[0,3],[2,4,5]],[[0,3],[2,4,5]]]
+const ENGAGEMENTS_61 = [[[0,3],[1,2,5]],[[0,3],[1,2,5]]]
+
const battle_strike_positions = [ D1, D2, D3, A1, A2, A3 ]
const battle_steps = [
@@ -7001,7 +7006,9 @@ states.reposition_center = {
// === 4.4.2 BATTLE ROUNDS: ENGAGE / STRIKE ===
-function determine_engagements() {
+function determine_engagements_BAD() {
+ // does not handle Ravine
+
let center = [ A2, D2 ]
let engagements = [
[ A1, D1 ],
@@ -7020,9 +7027,32 @@ function determine_engagements() {
}
}
results.unshift(center)
+
+ console.log("ENG", results)
+
return results
}
+function pack_battle_array() {
+ let bits = 0
+ for (let p = 0; p < 6; ++p)
+ if (filled(p))
+ bits |= (1 << p)
+ return bits
+}
+
+function determine_engagements() {
+ let bits = pack_battle_array()
+ if (bits === 47)
+ throw "BIT47" // return ENGAGEMENTS_47[0].slice()
+ else if (bits === 61)
+ throw "BIT61" // return ENGAGEMENTS_61[0].slice()
+ else if (ENGAGEMENTS[bits])
+ return ENGAGEMENTS[bits].slice()
+ else
+ return []
+}
+
function goto_determine_engagements() {
game.battle.step = 0
game.battle.engagements = determine_engagements()
diff --git a/tools/engage.js b/tools/engage.js
new file mode 100644
index 0000000..5b5ed90
--- /dev/null
+++ b/tools/engage.js
@@ -0,0 +1,167 @@
+"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 A1 = 0, A2 = 1, A3 = 2
+const D1 = 3, D2 = 4, D3 = 5
+
+const NAMES = [
+ "A1", "A2", "A3",
+ "D1", "D2", "D3",
+]
+
+function show_array(array) {
+ for (let row = 0; row < 6; row += 3) {
+ let s = []
+ for (let col = 0; col < 3; ++col) {
+ if (array[row+col])
+ s.push(NAMES[row+col].padEnd(3, ' '))
+ else
+ s.push("-- ")
+ }
+ console.log(s.join(" "))
+ }
+ console.log("")
+}
+
+function verify(array, out) {
+ for (let i = 0; i < 6; ++i) {
+ if (array[i]) {
+ let okay = false
+ for (let eng of out)
+ if (eng.includes(i))
+ okay = true
+ if (!okay)
+ return false
+ }
+ }
+ return true
+}
+
+function make_engagement(array, choice) {
+ let out = []
+ let a, b
+
+ function engage(a, b) {
+ for (let eng of out) {
+ if (eng.includes(a)) {
+ set_add(eng, b)
+ return
+ }
+ if (eng.includes(b)) {
+ set_add(eng, a)
+ return
+ }
+ }
+ out.push([a,b])
+ }
+
+ // A1 vs D1 etc
+ if (array[A1] && array[D1]) engage(A1, D1)
+ if (array[A2] && array[D2]) engage(A2, D2)
+ if (array[A3] && array[D3]) engage(A3, D3)
+
+ // A1 vs D2/D3 etc
+ if (array[A1] && !array[D1] && array[D2]) engage(A1, D2)
+ if (array[A1] && !array[D1] && !array[D2] && array[D3]) engage(A1, D3)
+
+ if (array[A3] && !array[D3] && array[D2]) engage(A3, D2)
+ if (array[A3] && !array[D3] && !array[D2] && array[D1]) engage(A3, D1)
+
+ if (array[D1] && !array[A1] && array[A2]) engage(D1, A2)
+ if (array[D1] && !array[A1] && !array[A2] && array[A3]) engage(D1, A3)
+
+ if (array[D3] && !array[A3] && array[A2]) engage(D3, A2)
+ if (array[D3] && !array[A3] && !array[A2] && array[A1]) engage(D3, A1)
+
+ // A2 vs D1/D3
+ if (array[A2] && !array[D2]) {
+ if (array[D1] && !array[D3]) engage(A2, D1)
+ if (!array[D1] && array[D3]) engage(A2, D3)
+ if (choice)
+ if (array[D1] && array[D3]) engage(A2, choice === 1 ? D1 : D3)
+ }
+
+ // D2 vs A1/D3
+ if (array[D2] && !array[A2]) {
+ if (array[A1] && !array[A3]) engage(D2, A1)
+ if (!array[A1] && array[A3]) engage(D2, A3)
+ if (choice)
+ if (array[A1] && array[A3]) engage(D2, choice === 1 ? A1 : A3)
+ }
+
+ if (verify(array, out)) {
+ console.log(out.map(eng => eng.map(x=>NAMES[x]).join("+")).join(" / "))
+ return out
+ }
+ return null
+}
+
+const ENGAGEMENTS = []
+const CHOICE = []
+
+function run(bits, array) {
+ console.log("<tr>")
+ console.log("<td>")
+ show_array(array)
+ console.log("<td>")
+ let eng = make_engagement(array, 0)
+ ENGAGEMENTS[bits] = eng
+ if (!eng) {
+ let eng_a = make_engagement(array, 1)
+ console.log("or")
+ let eng_b = make_engagement(array, 2)
+ CHOICE.push([ bits, eng_a, eng_b ])
+ }
+}
+
+function runall() {
+ for (let x = 0; x < 64; ++x) {
+ if ((x & 7) && (x & 56))
+ run(x, [ (x>>5)&1, (x>>4)&1, (x>>3)&1, (x>>2)&1, (x>>1)&1, (x>>0)&1 ])
+ }
+}
+
+console.log("<!DOCTYPE html>")
+console.log("<style>td{white-space:pre;font-family:monospace;padding:3em;border:1px solid black}</style>")
+console.log("<table>")
+runall()
+
+//run([1,1,0, 1,0,1])
+
+//run([1,1,1, 1,1,0])
+//run([1,1,1, 0,1,0])
+//run([1,0,1, 0,1,0])
+
+//run([1,0,1, 0,1,0])
+//run([0,1,1, 1,0,0])
+//run([1,0,0, 0,1,1])
+//run([1,1,0, 1,0,1])
+//run([1,1,1, 1,0,1])
+
+console.log("</table>")
+
+console.log("<pre>")
+console.log("const ENGAGEMENTS = " + JSON.stringify(ENGAGEMENTS))
+for (let [bits,a,b] of CHOICE)
+ console.log("const ENGAGEMENTS_" + bits + " = " + JSON.stringify([a,b]))