summaryrefslogtreecommitdiff
path: root/rules.js
diff options
context:
space:
mode:
Diffstat (limited to 'rules.js')
-rw-r--r--rules.js21
1 files changed, 10 insertions, 11 deletions
diff --git a/rules.js b/rules.js
index 30bee2f..c0a9af3 100644
--- a/rules.js
+++ b/rules.js
@@ -3768,13 +3768,7 @@ states.combat_target = {
game.defender = game.pos[p]
- // TODO: map_filter
- for (let i = 0; i < game.combat.length; i += 2) {
- if (game.combat[i] === game.attacker && game.combat[i+1] === game.defender) {
- array_remove_pair(game.combat, i)
- break
- }
- }
+ game.combat = map_filter(game.combat, (atk, def) => atk !== game.attacker || def !== game.defender)
goto_resolve_combat()
},
@@ -4356,10 +4350,7 @@ function goto_retroactive_conquest() {
}
})
- // TODO: map_filter
- for (let i = 0; i < game.retro.length; i += 2)
- if (game.retro[i+1] === game.power)
- array_remove_pair(game.retro, i)
+ game.retro = map_filter(game.retro, (s,pow) => pow !== game.power)
log_conquest(conq)
@@ -7238,6 +7229,14 @@ function map_for_each(map, f) {
f(map[i], map[i+1])
}
+function map_filter(map, f) {
+ let out = []
+ for (let i = 0; i < map.length; i += 2)
+ if (f(map[i], map[i+1]))
+ out.push(map[i], map[i+1])
+ return out
+}
+
function map_group_by(items, callback) {
let groups = []
if (typeof callback === "function") {