From dbbe5ae68ffc6210241bbbb6eb86f9e4d0f16956 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Fri, 18 Oct 2024 23:15:45 +0200 Subject: Mixed stack supreme commander when equal ranks. --- play.js | 41 ++++++++++++++++------------------------- 1 file changed, 16 insertions(+), 25 deletions(-) (limited to 'play.js') diff --git a/play.js b/play.js index 4e560aa..b87f53f 100644 --- a/play.js +++ b/play.js @@ -677,27 +677,20 @@ function on_blur_piece() { /* UPDATE UI */ -function layout_general_offset(g, s) { - // if not selected: number of unselected generals below us - // if not selected: (number of unselected generals + 1) + number of selected generals below us - if (!set_has(view.selected, g)) { - let n = 0 - for (let i = g+1; i < 20; ++i) - if (view.pos[i] === s && !set_has(view.selected, i)) - ++n - return n - } else { - let n = 0 - for (let i = 0; i < 20; ++i) - if (view.pos[i] === s && !set_has(view.selected, i)) - ++n - if (n > 0) - ++n - for (let i = g+1; i < 20; ++i) - if (view.pos[i] === s && set_has(view.selected, i)) - ++n - return n - } +function layout_general_offset(who, here) { + let other = -1 + for (let p = 0; p < 20; ++p) + if (view.pos[p] === here && who !== p) + other = p + if (other < 0) + return 0 + if ((view.supreme & (1 << who)) || view.selected === who) + return 1 + if ((view.supreme & (1 << other)) || view.selected === other) + return 0 + if (who < other) + return 1 + return 0 } function layout_general_offset_elim(g) { @@ -1026,10 +1019,8 @@ function on_update() { for (let v = 16; v >= 0; --v) action_button_with_argument("value", v, v) - for (let p = 0; p < 20; ++p) { - action_button_with_argument("promote", p, "Promote " + piece_abbr[p]) - action_button_with_argument("demote", p, "Demote " + piece_abbr[p]) - } + for (let p = 0; p < 20; ++p) + action_button_with_argument("supreme", p, power_name[piece_power[p]]) action_button("force_march", "Force march") -- cgit v1.2.3