summaryrefslogtreecommitdiff
path: root/rules.js
diff options
context:
space:
mode:
Diffstat (limited to 'rules.js')
-rw-r--r--rules.js39
1 files changed, 8 insertions, 31 deletions
diff --git a/rules.js b/rules.js
index bd11bf9..8cd4b9c 100644
--- a/rules.js
+++ b/rules.js
@@ -4,8 +4,6 @@
// TODO: select leader for defense instead of automatically picking the best
// TODO: remove old 7 command leader(s) immediately as they're drawn, before placing reinforcements
-// TODO: use set functions from rommel instead of array.includes array.push
-
const { spaces, pieces, cards } = require("./data")
const BRITAIN = 'Britain'
@@ -314,17 +312,6 @@ function set_delete(set, item) {
set.splice(i, 1)
}
-function set_clear(set) {
- set.length = 0
-}
-
-function set_toggle(set, item) {
- if (set_has(set, item))
- set_delete(set, item)
- else
- set_add(set, item)
-}
-
function remove_from_array(array, item) {
let i = array.indexOf(item)
if (i >= 0)
@@ -1270,10 +1257,6 @@ function has_friendly_fort(s) {
return set_has(player.forts, s)
}
-function has_enemy_fort_uc(s) {
- return set_has(enemy_player.forts_uc, s)
-}
-
function has_friendly_fort_uc(s) {
return set_has(player.forts_uc, s)
}
@@ -1406,14 +1389,6 @@ function count_units_in_space(s) {
return n
}
-function count_enemy_units_in_space(s) {
- let n = 0
- for (let p = first_enemy_unit; p <= last_enemy_unit; ++p)
- if (is_piece_in_space(p, s))
- ++n
- return n
-}
-
function has_unbesieged_friendly_leader(s) {
for (let p = first_friendly_leader; p <= last_friendly_leader; ++p)
if (is_piece_unbesieged_in_space(p, s))
@@ -2070,14 +2045,16 @@ function update_vp(name, s) {
function search_supply_spaces_imp(queue) {
// console.log("======")
- let reached = queue.slice()
+ let reached = []
+ for (let s of queue)
+ set_add(reached, s)
while (queue.length > 0) {
let current = queue.shift()
// If we must have come here by water way:
let cultivated = is_cultivated(current) || has_friendly_fortifications(current) || has_friendly_amphib(current)
// console.log("SUPPLY", space_name(current), cultivated)
for_each_exit_with_type(current, (next, type) => {
- if (reached.includes(next))
+ if (set_has(reached, next))
return // continue
if (has_unbesieged_enemy_units(next) || has_unbesieged_enemy_fortifications(next))
return // continue
@@ -2085,14 +2062,14 @@ function search_supply_spaces_imp(queue) {
// came from wilderness by water, must continue by water
if (type !== 'land') {
// console.log(" ", space_name(next), "(adjacent-water)")
- reached.push(next)
+ set_add(reached, next)
queue.push(next)
}
} else {
// came from cultivated by any path, may continue to cultivated or by water
if (is_cultivated(next) || has_friendly_fortifications(next) || has_friendly_amphib(next) || type !== 'land') {
// console.log(" ", space_name(next), "(from land)")
- reached.push(next)
+ set_add(reached, next)
queue.push(next)
}
}
@@ -2120,11 +2097,11 @@ function is_in_supply(from) {
return true
if (!supply_cache)
search_supply_spaces()
- if (supply_cache.includes(from))
+ if (set_has(supply_cache, from))
return true
let x = false
for_each_exit(from, next => {
- if (supply_cache.includes(next))
+ if (set_has(supply_cache, next))
x = true
})
return x