summaryrefslogtreecommitdiff
path: root/rules.js
diff options
context:
space:
mode:
Diffstat (limited to 'rules.js')
-rw-r--r--rules.js88
1 files changed, 25 insertions, 63 deletions
diff --git a/rules.js b/rules.js
index d85ea43..296c761 100644
--- a/rules.js
+++ b/rules.js
@@ -1152,18 +1152,12 @@ function shuffle_cards() {
// === SUPPLY NETWORK ===
-function ind(d, msg, here, ...extra) {
- //console.log(new Array(d).fill("-").join("") + msg, here, "("+hex_name[here]+")", extra.join(" "))
-}
-
var supply_defender, supply_defender_sides, supply_friendly, supply_enemy, supply_net, supply_line, supply_fortress_enemy
var supply_visited = new Array(hexcount).fill(0)
var supply_src = new Array(hexcount).fill(0)
var trace_total
-var OPT = true
-
function is_supply_line_blocked(here, next, side) {
// impassable hexside
if (side_limit[side] === 0)
@@ -1194,9 +1188,11 @@ function is_supply_line_blocked(here, next, side) {
return false
}
-function trace_supply_highway(here, d) {
+function trace_supply_highway(here) {
trace_total++
- ind(d, "> highway", here)
+
+ if (supply_src[here])
+ return true
let has_supply = false
@@ -1215,34 +1211,15 @@ function trace_supply_highway(here, d) {
if (is_supply_line_blocked(here, next, side))
continue
- if (supply_src[next]) {
- ind(d, "!! source highway", next)
- supply_line[side] = 1
- has_supply = true
- continue
- }
-
let road = side_road[side]
if (road === HIGHWAY) {
if (supply_friendly[next] > 1) {
- //ind(d, "? highway chain head", next)
- // XXX prevent loopback?
- if (OPT && supply_net[next]) {
- //console.log("already found", hex_name[next])
- supply_line[side] = 1
- has_supply = true
- }
- else
- if (trace_supply_chain(next, d+1, 0, 3)) {
- //console.log("found", hex_name[next])
- ind(d, "< highway chain", here, next)
+ if (supply_net[next] || trace_supply_chain(next, 0, 3)) {
supply_line[side] = 1
has_supply = true
}
} else {
- //ind(d, "? highway tail", next)
- if (trace_supply_highway(next, d+1)) {
- ind(d, "< highway", here, next)
+ if (trace_supply_highway(next)) {
supply_line[side] = 1
has_supply = true
}
@@ -1258,9 +1235,11 @@ function trace_supply_highway(here, d) {
return has_supply
}
-function trace_supply_chain(here, d, n, range) {
+function trace_supply_chain(here, n, range) {
trace_total++
- ind(d, "> chain", here, n, range)
+
+ if (supply_src[here])
+ return true
let has_supply = false
@@ -1279,18 +1258,9 @@ function trace_supply_chain(here, d, n, range) {
if (is_supply_line_blocked(here, next, side))
continue
- if (supply_src[next]) {
- ind(d, "!! source chain", next)
- supply_line[side] = 1
- has_supply = true
- continue
- }
-
let road = side_road[side]
if (road === HIGHWAY) {
- //ind(d, "? chain highway", next)
- if (trace_supply_highway(next, d+1)) {
- ind(d, "< chain highway", here, next)
+ if (trace_supply_highway(next)) {
supply_line[side] = 1
has_supply = true
}
@@ -1299,24 +1269,12 @@ function trace_supply_chain(here, d, n, range) {
let next_range = min(range, SUPPLY_RANGE[road])
if (n + 1 <= next_range) {
if (supply_friendly[next] > 1) {
- //ind(d, "? chain head", next)
- // XXX prevent loopback?
- if (OPT && supply_net[next]) {
- //console.log("already found", hex_name[next])
- supply_line[side] = 1
- has_supply = true
- }
- else
- if (trace_supply_chain(next, d+1, 0, 3)) {
- //console.log("found", hex_name[next])
- ind(d, "< highway chain", here, next)
+ if (supply_net[next] || trace_supply_chain(next, 0, 3)) {
supply_line[side] = 1
has_supply = true
}
} else {
- //ind(d, "? chain tail", next)
- if (trace_supply_chain(next, d+1, n+1, next_range)) {
- ind(d, "< chain trail", here, next_range)
+ if (trace_supply_chain(next, n + 1, next_range)) {
supply_line[side] = 1
has_supply = true
}
@@ -1357,12 +1315,13 @@ function trace_supply_network(start) {
supply_net[start] = 1
trace_total = 0
- for (let x of search_order)
- if (supply_friendly[x] > 0 && x !== start)
- {
- console.log("search from", hex_name[x])
- trace_supply_chain(x, 0, 0, 3)
+ for (let x of search_order) {
+ if (supply_friendly[x] > 0 && x !== start) {
+ if (supply_friendly[x] > 1 && supply_net[x])
+ continue
+ trace_supply_chain(x, 0, 3)
}
+ }
console.log("SUPPLY VISITS", trace_total)
}
@@ -1381,8 +1340,11 @@ function trace_fortress_network(fortress, ss) {
for (let u = 0; u < unit_count; ++u) {
if (unit_supply(u) === ss) {
let x = unit_hex(u)
- if (is_map_hex(x) && x !== fortress)
- trace_supply_chain(x, 0, 0, 3)
+ if (is_map_hex(x) && x !== fortress) {
+ if (supply_friendly[x] > 1 && supply_net[x])
+ continue
+ trace_supply_chain(x, 0, 3)
+ }
}
}
@@ -1421,7 +1383,7 @@ function can_trace_supply_to_base_or_fortress(base, from) {
supply_visited.fill(0)
supply_src.fill(0)
supply_src[base] = 1
- return trace_supply_chain(from, 0, 0, 3)
+ return trace_supply_chain(from, 0, 3)
}
function update_axis_supply() {