summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2024-05-26 12:52:13 +0200
committerTor Andersson <tor@ccxvii.net>2024-05-30 21:59:25 +0200
commitf689313ce7252ee3679122b1ae65e0848a7af7f9 (patch)
treef396e41ee8ed676203686377d67547b383f91a98
parent825a9baf74d2c872703dbcc11f7d798545d0f6fd (diff)
downloadfriedrich-f689313ce7252ee3679122b1ae65e0848a7af7f9.tar.gz
fix stacking limit check
-rw-r--r--rules.js12
1 files changed, 6 insertions, 6 deletions
diff --git a/rules.js b/rules.js
index a82e850..c0acd9c 100644
--- a/rules.js
+++ b/rules.js
@@ -839,10 +839,10 @@ function has_own_general(to) {
return false
}
-function count_pieces(to) {
+function count_generals(to) {
let n = 0
- for (let s of game.pos)
- if (s === to)
+ for (let p of all_generals)
+ if (game.pos[p] === to)
++n
return n
}
@@ -1530,7 +1530,7 @@ function can_move_general_in_theory(p, to) {
return false
if (has_enemy_supply_train(to) && forbid_capture_by(p, to))
return false
- if (count_pieces(to) >= 3)
+ if (count_generals(to) >= 3)
return false
return true
}
@@ -1542,7 +1542,7 @@ function can_move_general_to(to) {
return false
if (has_enemy_supply_train(to) && forbid_capture(to))
return false
- if (game.selected.length + count_pieces(to) > 3)
+ if (game.selected.length + count_generals(to) > 3)
return false
// TODO: in search_move apply this as a post-process filter on the list of destinations
@@ -2246,7 +2246,7 @@ function can_re_enter_general(to) {
return false
if (has_any_other_general(to))
return false
- if (1 + count_pieces(to) > 3)
+ if (1 + count_generals(to) > 3)
return false
return true
}