diff options
author | Tor Andersson <tor@ccxvii.net> | 2024-10-22 16:11:05 +0200 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2024-10-22 16:11:05 +0200 |
commit | 78754928c9b1c55bdffe40ff33342c7329f3ce77 (patch) | |
tree | e7c2b523d843a18ea0aa21750441ec237bcdb690 /rules.js | |
parent | 5ab7ccf00da33d2fcc02d582b8528596d92f22ed (diff) | |
download | maria-78754928c9b1c55bdffe40ff33342c7329f3ce77.tar.gz |
political phase - card data
Diffstat (limited to 'rules.js')
-rw-r--r-- | rules.js | 106 |
1 files changed, 84 insertions, 22 deletions
@@ -61,7 +61,8 @@ exports.roles = [ exports.scenarios = [ "Advanced" ] -const data = require("./data") +const data = require("./data.js") +const political_cards = require("./cards.js") var game var view @@ -955,7 +956,6 @@ function goto_end_turn() { function goto_start_turn() { game.turn += 1 - game.stage = 0 log("# " + TURN_NAME[game.turn]) @@ -1004,6 +1004,8 @@ function end_place_hussars() { log("=" + P_AUSTRIA + " Hussars") for (let p of all_hussars) log("Hussar at S" + game.pos[p] + ".") + + game.stage = 0 goto_action_stage() } @@ -1149,13 +1151,13 @@ function total_discard_list() { return discard } -function draw_tc(n) { +function draw_tc(n, verbose = true) { game.draw = [] let k = 0 while (n > 0) { if (game.deck.length === 0) { - if (k > 0) + if (verbose && k > 0) log(power_name[game.power] + " " + k + " TC.") k = 0 next_tactics_deck() @@ -1169,7 +1171,7 @@ function draw_tc(n) { --n } - if (k > 0) + if (verbose && k > 0) log(power_name[game.power] + " " + k + " TC.") } @@ -2300,6 +2302,7 @@ function goto_winter_turn() { // TODO: winter scoring + game.stage = 0 goto_winter_stage() } @@ -3227,17 +3230,22 @@ const POWER_FROM_POLITICAL_STAGE = [ P_AUSTRIA, ] -function set_active_political_power() { - set_active_to_power(POWER_FROM_POLITICAL_STAGE[game.stage]) -} +const INFLUENCE_ORDER = [ + P_AUSTRIA, + P_PRAGMATIC, + P_FRANCE, + P_PRUSSIA, +] function goto_politics() { game.political = [] game.display = [ 0, 0, 0, 0 ] game.stage = 0 + log("Reveal") while (game.political.length < 2) { let pc = game.pol_deck.pop() + log(">C" + pc) if (pc === IMPERIAL_ELECTION) game.flags |= F_IMPERIAL_ELECTION else @@ -3249,7 +3257,7 @@ function goto_politics() { game.state = "determine_trump_suit" } else { for (;;) { - draw_tc(1) + draw_tc(1, false) log("Trump " + format_card(game.draw[0]) + ".") if (!is_reserve(game.draw[0])) { game.trump = to_suit(game.draw[0]) @@ -3257,6 +3265,7 @@ function goto_politics() { } delete game.draw } + log_br() goto_place_tc_on_display() } } @@ -3268,13 +3277,15 @@ states.determine_trump_suit = { view.actions.suit = [ 0, 1, 2, 3 ] }, suit(s) { + log(power_name[game.power] + " chose " + suit_name[game.trump] + " as trump.") + log_br() game.trump = s goto_place_tc_on_display() } } function goto_place_tc_on_display() { - set_active_political_power() + set_active_to_power(POWER_FROM_POLITICAL_STAGE[game.stage]) game.state = "place_tc_on_display" } @@ -3318,30 +3329,67 @@ function end_place_tc_on_display() { } function goto_determine_order_of_influence() { + log_br() + log("Influence") + // Turn cards face-up and return bluff cards - for (let pow of all_major_powers) { + for (let pow of POWER_FROM_POLITICAL_STAGE) { let c = game.display[pow] if (c > 0) { if (to_suit(c) === game.trump) { - log(power_name[pow] + " played " + format_card(c) + ".") + log(">" + format_card(c) + " " + power_name[pow]) set_add(game.saved[pow], c) } else { - log(power_name[pow] + " bluffed " + format_card(c) + ".") + log(">" + format_card(c) + " " + power_name[pow] + "(bluff)") set_add(game.hand[pow], c) } } } delete game.display - game.stage = 4 - goto_select_political_cards() + log_br() + game.stage = 0 + goto_select_political_card() } -function goto_select_political_cards() { - if (--game.stage < 0) +function count_influence(pow) { + let n = 0 + for (let c of game.saved[pow]) + if (is_reserve(c)) + n += 16 + else + n += to_value(c) + return n +} + +function most_influence() { + let p_most = -1 + let n_most = 0 + for (let pow of INFLUENCE_ORDER) { + if (game.stage & (1 << pow)) + continue + let n = count_influence(pow) + if (n > n_most) { + n_most = n + p_most = pow + } + } + return p_most +} + +function goto_select_political_card() { + if (game.political.length > 0) { + let pow = most_influence() + if (pow < 0) { + end_politics() + } else { + game.stage |= 1 << pow + set_active_to_power(pow) + game.state = "select_political_card" + } + } else { end_politics() - set_active_to_power(most_influence()) - game.state = "select_political_card" + } } states.select_political_card = { @@ -3349,7 +3397,8 @@ states.select_political_card = { prompt() { prompt(`Select a political card or save your TC.`) for (let pc of game.political) - gen_action_political(pc) + if (set_has(political_cards[pc].powers, game.power)) + gen_action_political(pc) view.actions.pass = 1 }, political(pc) { @@ -3359,14 +3408,25 @@ states.select_political_card = { }, pass() { log(power_name[game.power] + " saved its TC.") - goto_select_political_cards() + goto_select_political_card() }, } function end_politics() { delete game.political + + // did not take a turn; take cards back into hand + for (let pow of all_major_powers) { + if (!(game.stage & (1 << pow))) { + for (let c of game.saved[pow]) + set_add(game.hand, c) + game.saved[pow] = [] + } + } + if (check_instant_victory()) return + goto_place_hussars() } @@ -3780,7 +3840,7 @@ exports.view = function (state, player) { discard: total_discard_list(), pol_deck: mask_pol_deck(), - saved: mask_saved(player), + saved: game.saved, power: game.power, retro: game.retro, @@ -3791,6 +3851,8 @@ exports.view = function (state, player) { view.defender = game.defender } + if (game.political) + view.political = game.political if (game.display) view.display = mask_display(player) |