From 810e98edf8af847903f8ef4e0700da90b57546a3 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Mon, 27 May 2024 23:25:59 +0200 Subject: log when shuffling in middle of draw --- play.js | 11 +++++++++++ rules.js | 59 ++++++++++++++++++++++++++++++++++++++--------------------- 2 files changed, 49 insertions(+), 21 deletions(-) diff --git a/play.js b/play.js index c664c89..9272ab0 100644 --- a/play.js +++ b/play.js @@ -276,6 +276,16 @@ const ui = { markers_element: document.getElementById("markers"), clock_of_fate: document.getElementById("clock_of_fate"), power_panel_list: document.getElementById("power_panel_list"), + power_header: [ + document.getElementById("hand_prussia_header"), + document.getElementById("hand_hanover_header"), + document.getElementById("hand_russia_header"), + document.getElementById("hand_sweden_header"), + document.getElementById("hand_austria_header"), + document.getElementById("hand_imperial_header"), + document.getElementById("hand_france_header"), + document.getElementById("clock_of_fate_header"), + ], power_panel: [ document.getElementById("hand_prussia_panel"), document.getElementById("hand_hanover_panel"), @@ -779,6 +789,7 @@ function on_update() { ui.turns[i].classList.toggle("hide", (typeof view.fate === "object") || (i + 1 < view.fate)) for (let pow = 0; pow < 7; ++pow) { + ui.power_header[pow].textContent = power_name[pow] + " - " + view.pt[pow] + " troops" ui.power_panel[pow].classList.toggle("hide", has_removed_all_pieces(pow)) ui.hand[pow].replaceChildren() diff --git a/rules.js b/rules.js index b8e0103..1dc14df 100644 --- a/rules.js +++ b/rules.js @@ -2,6 +2,7 @@ // TODO: prussian offensive (no capture when not offensive) // TODO: final score summary at game end (FWC rules) +// TODO: show running tally of troops/objectives const R_FREDERICK = "Frederick" const R_ELISABETH = "Elisabeth" @@ -999,28 +1000,33 @@ function next_tactics_deck() { shuffle_bigint(game.deck) } -function draw_next_tc() { - if (game.deck.length === 0) - next_tactics_deck() - if (game.deck.length === 0) - return -1 - return game.deck.pop() +function draw_tc(n) { + let draw = [] + + let k = 0 + while (n > 0) { + if (game.deck.length === 0) { + if (k > 0) + log("Drew " + k + " TC.") + k = 0 + next_tactics_deck() + if (game.deck.length === 0) { + log("The cards ran out!") + break + } + } + set_add(draw, game.deck.pop()) + ++k + --n + } + + return draw } function goto_tactical_cards() { let n = turn_power_draw() - game.draw = [] - for (let i = 0; i < n; ++i) { - let c = draw_next_tc() - if (c >= 0) - set_add(game.draw, c) - } - - if (game.draw.length < n) - log("Drew " + game.draw.length + " / " + n + " TC.") - else - log("Drew " + n + " TC.") + game.draw = draw_tc(turn_power_draw()) if (should_power_discard_tc() && game.draw.length > 0) game.state = "tactical_cards_discard" @@ -2880,8 +2886,7 @@ function goto_clock_of_fate() { if (game.scenario === 1 || game.scenario === 2) { log("Imaginary player drew 5 TC.") - for (let i = 0; i < 5; ++i) - draw_next_tc() + draw_tc(5) } // Check before drawing a fate card. @@ -3441,8 +3446,8 @@ states.france_may_discard_any_one_tc_for_a_new_one_from_the_draw_deck = { log("France discarded one TC.") log("France drew one TC.") set_delete(game.hand[P_FRANCE], c) - c = draw_next_tc() - if (c >= 0) + let draw = draw_tc(1) + for (let c of draw) set_add(game.hand[P_FRANCE], c) goto_start_turn() }, @@ -4047,6 +4052,17 @@ function mask_hand(player) { return view_hand } +function total_troops_list() { + let list = [] + for (let pow of all_powers) { + let n = 0 + for (let p of all_power_generals) + n += game.troops[p] + list[pow] = n + } + return list +} + exports.view = function (state, player) { game = state view = { @@ -4060,6 +4076,7 @@ exports.view = function (state, player) { conquest: game.conquest, troops: mask_troops(player), hand: mask_hand(player), + pt: total_troops_list(), power: game.power, retro: game.retro, -- cgit v1.2.3