summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2022-12-30 03:27:26 +0100
committerTor Andersson <tor@ccxvii.net>2023-02-18 13:02:38 +0100
commitffc58ffde8743071418547285e6bc62608fcd849 (patch)
treee7a388e639290e0fb0e630974d6d104c8fa2d228
parentd4765ff05c1d51f296c0e0b8891f884356fca209 (diff)
downloadnevsky-ffc58ffde8743071418547285e6bc62608fcd849.tar.gz
More striking.
-rw-r--r--rules.js14
-rw-r--r--tools/genstrike.js142
2 files changed, 137 insertions, 19 deletions
diff --git a/rules.js b/rules.js
index e0dcfe3..6e9eea5 100644
--- a/rules.js
+++ b/rules.js
@@ -20,7 +20,7 @@
const data = require("./data.js")
-// packed strike and hit group data
+// Packed strike and hit group lookup table.
const GROUPS = [[[0,0,0,0,0,0,0,0,0,[[8,1]],[[8,2]],[[8,3]],[[8,4]],[[8,5]],[[8,2]],[[8,7]],0,[[16,1]],[[16,2]],[[16,3]],[[16,4]],[[16,1]],[[16,6]],[[16,7]],0,[[24,1]],[[24,2]],[[8,1],[16,2]],[[24,4]],[[24,1]],[[24,2]],[[8,1],[16,6]],0,[[32,1]],[[32,2]],[[32,2]],[[32,4]],[[32,5]],[[32,6]],[[32,7]],0,[[40,1]],[[40,2]],[[8,3],[32,2]],[[40,4]],[[8,1],[32,4]],[[8,2],[32,6]],[[8,3],[32,6]],0,[[48,1]],[[48,2]],[[48,2]],[[48,4]],[[16,1],[32,4]],[[16,2],[32,4]],[[16,3],[32,4]],0,[[56,1]],[[56,2]],[[8,1],[48,2]],[[56,4]],[[24,1],[32,4]],[[24,2],[32,4]],[[8,1],[16,2],[32,4]]],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,[[16,4]],0,0,0,0,0,0,0,[[8,1],[16,4]],0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,[[48,4]],0,0,0,0,0,0,0,[[8,1],[48,4]],0,0]],[[0,0,0,0,0,0,0,0,0,[[1,8]],[[2,8]],[[3,8]],[[4,8]],[[5,8]],[[6,8]],[[7,8]],0,[[1,16]],[[2,16]],[[3,16]],[[4,16]],[[5,16]],[[6,16]],[[7,16]],0,[[1,24]],[[2,24]],[[1,8],[2,16]],[[4,16]],[[1,24],[4,16]],[[6,16]],[[1,8],[6,16]],0,[[1,32]],[[2,32]],[[3,32]],[[4,32]],[[5,32]],[[6,32]],[[7,32]],0,[[1,40]],[[2,8]],[[3,8]],[[4,40]],[[1,8],[4,32]],[[2,8],[4,32]],[[3,8],[4,32]],0,[[1,16]],[[2,48]],[[3,16]],[[4,48]],[[1,16],[4,48]],[[2,16],[4,32]],[[3,16],[4,32]],0,[[1,56]],[[2,56]],[[1,8],[2,48]],[[4,56]],[[1,24],[4,48]],[[2,24],[4,32]],[[1,8],[2,16],[4,32]]],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,[[2,32]],[[1,8],[2,32]],0,0,[[6,32]],[[1,8],[6,32]],0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]]]
const TODO = false
@@ -5672,13 +5672,19 @@ function has_no_unrouted_forces() {
function has_front_strike_choice() {
let s = game.battle.step & 1
let f = pack_battle_array_front()
- return GROUPS[s][1][f] !== 0
+ // Choice only matters if the center Lord has strikes this step
+ if (GROUPS[s][1][f] !== 0)
+ return (game.battle.ah1[A2] + game.battle.ah2[A2] + game.battle.ah1[D2] + game.battle.ah2[D2] > 0)
+ return false
}
function has_rear_strike_choice() {
let s = game.battle.step & 1
let r = pack_battle_array_rear()
- return GROUPS[s][1][r] !== 0
+ // Choice only matters if the center Lord has strikes this step
+ if (GROUPS[s][1][r] !== 0)
+ return (game.battle.ah1[SA2] + game.battle.ah2[SA2] + game.battle.ah1[RD2] + game.battle.ah2[RD2] > 0)
+ return false
}
function format_group(g) {
@@ -6008,7 +6014,7 @@ states.select_strike_group = {
for (let [sg, hg] of game.battle.groups) {
for (let p of sg) {
let lord = game.battle.array[p]
- if (game.battle.ah1[p] > 0 || game.battle.ah2[p] > 0)
+ if (game.battle.ah1[p] + game.battle.ah2[p] > 0)
gen_action_battle_lord(lord)
}
}
diff --git a/tools/genstrike.js b/tools/genstrike.js
index d81bdf8..348b007 100644
--- a/tools/genstrike.js
+++ b/tools/genstrike.js
@@ -141,7 +141,7 @@ function print_strikes(grp) {
console.log("")
}
-function list_hit_groups(array, flanking, strikers, step) {
+function list_hit_groups_OLD(array, flanking, strikers, step) {
function is_flanking_target(target, pos) {
return array[OPPOSE[pos]] === 0 && flanking[pos].includes(OPPOSE[target])
}
@@ -188,7 +188,100 @@ function list_hit_groups(array, flanking, strikers, step) {
return result
}
-function run_step(bits, array, i, output_a, output_b) {
+function list_hit_groups_INF(array, flanking, strikers, step) {
+ function is_flanking_all_strikers(def, strikers) {
+ for (let str of strikers)
+ if (!flanking[def].includes(str))
+ return false
+ return true
+ }
+ function list_flanking_2(target, strikers, list) {
+ let result = [ target ]
+ for (let pos of list) {
+ if (array[pos]) {
+ if (is_flanking_all_strikers(pos, strikers))
+ result.push(pos)
+ }
+ }
+ return result
+ }
+ function list_flanking_1(target, strikers) {
+ switch (target) {
+ case A1: return list_flanking_2(target, strikers, [ A2, A3 ])
+ case A2: return list_flanking_2(target, strikers, [ A1, A3 ])
+ case A3: return list_flanking_2(target, strikers, [ A1, A2 ])
+ case D1: return list_flanking_2(target, strikers, [ D2, D3 ])
+ case D2: return list_flanking_2(target, strikers, [ D1, D3 ])
+ case D3: return list_flanking_2(target, strikers, [ D1, D2 ])
+ }
+ }
+
+ let result = []
+ let sg, hg
+ for (let pos of step) {
+ if (strikers[pos].length > 0) {
+ sg = pack_group(strikers[pos])
+ hg = pack_group(list_flanking_1(pos, strikers[pos]))
+ result.push([sg,hg])
+ }
+ }
+ return result
+}
+
+function list_hit_groups(array, flanking, strikers, step) {
+ function is_target_flanked(target) {
+ for (let pos of flanking[target])
+ if (pos !== OPPOSE[target])
+ return true
+ return false
+ }
+ function is_flanking_all_strikers(def, strikers) {
+ for (let str of strikers)
+ if (!flanking[def].includes(str))
+ return false
+ return true
+ }
+ function list_flanking_2(target, strikers, list) {
+ let result = [ target ]
+ if (!is_target_flanked(target))
+ for (let pos of list) {
+ if (array[pos]) {
+ if (is_flanking_all_strikers(pos, strikers))
+ result.push(pos)
+ }
+ }
+ return result
+ }
+ function list_flanking_1(target, strikers) {
+ switch (target) {
+ case A1: return list_flanking_2(target, strikers, [ A2, A3 ])
+ case A2: return list_flanking_2(target, strikers, [ A1, A3 ])
+ case A3: return list_flanking_2(target, strikers, [ A1, A2 ])
+ case D1: return list_flanking_2(target, strikers, [ D2, D3 ])
+ case D2: return list_flanking_2(target, strikers, [ D1, D3 ])
+ case D3: return list_flanking_2(target, strikers, [ D1, D2 ])
+ }
+ }
+
+ let result = []
+ let sg, hg
+ for (let pos of step) {
+ if (strikers[pos].length > 0) {
+ sg = pack_group(strikers[pos])
+ hg = pack_group(list_flanking_1(pos, strikers[pos]))
+ result.push([sg,hg])
+ }
+ }
+ return result
+}
+
+function show_group_list(list) {
+ for (let [sg, hg] of list) {
+ console.log(show_group(sg) + " strike " + show_group(hg))
+ }
+}
+
+function run_step(bits, array, i, output_a, output_b, do_show) {
let a, b, strikers, flanking
flanking = list_flanking_groups(array)
@@ -200,10 +293,21 @@ function run_step(bits, array, i, output_a, output_b) {
b = list_hit_groups(array, flanking, strikers, receive_steps[i])
output_a[bits] = a.length > 0 ? a : 0
- if (JSON.stringify(a) !== JSON.stringify(b))
+ if (do_show) {
+ show_group_list(a)
+ }
+
+ if (JSON.stringify(a) !== JSON.stringify(b)) {
output_b[bits] = b.length > 0 ? b : 0
- else
+ if (do_show) {
+ console.log("-OR-")
+ show_group_list(b)
+ }
+ } else {
output_b[bits] = 0
+ }
+
+ console.log()
}
let group_defending_a = []
@@ -212,28 +316,36 @@ let group_attacking_a = []
let group_attacking_b = []
function run(bits, array, step) {
- run_step(bits, array, 0, group_defending_a, group_defending_b)
- run_step(bits, array, 1, group_attacking_a, group_attacking_b)
+ console.log("<tr>")
+ console.log("<td>")
+ show_array(array)
+
+ console.log("<td>")
+ run_step(bits, array, 0, group_defending_a, group_defending_b, true)
+ console.log("<td>")
+ run_step(bits, array, 1, group_attacking_a, group_attacking_b, true)
}
function runall() {
for (let x = 0; x < 64; ++x) {
- run(x, [
- (x>>0)&1,
- (x>>1)&1,
- (x>>2)&1,
- (x>>3)&1,
- (x>>4)&1,
- (x>>5)&1,
- ])
+ //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 ])
+ run(x, [ (x>>0)&1, (x>>1)&1, (x>>2)&1, (x>>3)&1, (x>>4)&1, (x>>5)&1 ])
}
}
+//run(0, [1,0,1, 0,1,0])
+//run(0, [0,1,1, 1,0,0])
+//run(0, [1,0,0, 0,1,1])
+//run(0, [1,1,0, 1,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()
+console.log("</table>")
let GROUPS = [
[ group_defending_a, group_defending_b ],
[ group_attacking_a, group_attacking_b ],
]
-
console.log("const GROUPS = " + JSON.stringify(GROUPS))