From ab889d495cc617cd99f073448427132b127f4288 Mon Sep 17 00:00:00 2001 From: iainp5 Date: Sat, 5 Oct 2024 11:54:01 +0100 Subject: Fix for Samizdat and empty deck --- rules.js | 121 +++++++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 75 insertions(+), 46 deletions(-) diff --git a/rules.js b/rules.js index 85e184d..96cdc0c 100644 --- a/rules.js +++ b/rules.js @@ -48,7 +48,6 @@ exports.setup = function (seed, scenario, options) { played_card: 0, table_cards: [], - austria_hungary_border_reopened_tracker: false, temp: 0, available_ops: 0, vm_available_ops: 0, @@ -581,8 +580,10 @@ states.play_card ={ } } - // Set AHBR tracker to true - game.austria_hungary_border_reopened_tracker = true + // If ABHR - Set AHBR tracker to true + if (game.persistent_events.includes(58)) { + game.austria_hungary_border_reopened_tracker = true + } game.state='add_influence' valid_spaces_infl() }, @@ -648,8 +649,10 @@ states.resolve_opponent_event = { }, influence(){ push_undo() - // Set AHBR tracker to true - game.austria_hungary_border_reopened_tracker = true + // If ABHR - Set AHBR tracker to true + if (game.persistent_events.includes(58)) { + game.austria_hungary_border_reopened_tracker = true + } game.state = 'finish_add_infl' valid_spaces_infl() }, @@ -739,13 +742,15 @@ states.finish_support_check_prep = { game.selected_space = find_space_index(space) // Check for Austria-Hungary Border Reopened - check on first support check only //console.log('game.austria_hungary_border_reopened_checked', game.austria_hungary_border_reopened_checked) - if (game.active === DEM && game.available_ops > 1) { - //console.log('in ahb check, country, ', spaces[game.selected_space].country, 'ahb', 'austria_hungary_border_reopened']) - if (spaces[game.selected_space].country === 'East_Germany' && game.persistent_events.includes(58) && game.active === DEM) { - game.state = 'finish_austria_hungary_border_reopened_check' - return - } - } + if (game.persistent_events.includes(58)){ + if (game.active === DEM && game.available_ops > 1) { + //console.log('in ahb check, country, ', spaces[game.selected_space].country, 'ahb', 'austria_hungary_border_reopened']) + if (spaces[game.selected_space].country === 'East_Germany' && game.persistent_events.includes(58) && game.active === DEM) { + game.state = 'finish_austria_hungary_border_reopened_check' + return + } + } + } game.state = 'finish_do_support_check' }, done () { @@ -962,13 +967,15 @@ states.support_check_prep = { // Check for Austria-Hungary Border Reopened - check on first support check only //console.log('game.austria_hungary_border_reopened_checked', game.austria_hungary_border_reopened_checked) - if (game.active === DEM && game.available_ops > 1) { - if (spaces[game.selected_space].country === 'East_Germany' && game.persistent_events.includes(58) && game.active === DEM) { - game.state = 'austria_hungary_border_reopened_check' - return - } - //game.state = 'do_support_check' - } /*else { */ + if (game.persistent_events.includes(58)) { + if (game.active === DEM && game.available_ops > 1) { + if (spaces[game.selected_space].country === 'East_Germany' && game.persistent_events.includes(58) && game.active === DEM) { + game.state = 'austria_hungary_border_reopened_check' + return + } + //game.state = 'do_support_check' + } /*else { */ + } game.state = 'do_support_check' console.log('game.state after space selected:', game.state) //} @@ -2165,8 +2172,11 @@ function add_infl(space) { //log(`Added 1 influence in %${clicked_space}`) log_summary(`Added £ SP in %${clicked_space}`) - if (spaces[clicked_space].country !== 'East_Germany'){ - game.austria_hungary_border_reopened_tracker = false + //If AHBR - check AHBR conditions + if (game.persistent_events.includes(58)) { + if (spaces[clicked_space].country !== 'East_Germany'){ + game.austria_hungary_border_reopened_tracker = false + } } // Check Genscher @@ -2467,8 +2477,10 @@ function do_sc(space) { } // If Austria-Hungary Border Reopened used, all future support checks must be in East Germany - if (game.austria_hungary_border_reopened_tracker) { - game.valid_spaces = game.valid_spaces.filter(n => spaces[n].country === 'East_Germany') + if (game.persistent_events.includes(58)){ + if (game.austria_hungary_border_reopened_tracker) { + game.valid_spaces = game.valid_spaces.filter(n => spaces[n].country === 'East_Germany') + } } game.selected_space = 0 clear_undo() @@ -3504,6 +3516,7 @@ function new_turn() { //Austria Hungary Border Reopened if (game.persistent_events.includes(58)) { game.persistent_events = game.persistent_events.filter(n => n !== 58) + delete game.austria_hungary_border_reopened_tracker log(`C58 no longer in effect`) //permanently_remove(58) } @@ -3641,12 +3654,12 @@ function draw_deck(deck) { } function draw_cards(deck, democrat_hand, communist_hand, dem_hand_limit, com_hand_limit) { - console.log('game.valid_cards at start of draw cards: ', game.valid_cards) + //console.log('game.valid_cards at start of draw cards: ', game.valid_cards) let turn = 'communist'; // Start with the communist player console.log('game.strategy_deck', game.strategy_deck) console.log('deck', deck, 'democrat_hand', democrat_hand, 'communist_hand', communist_hand, 'dem_hand_limit', dem_hand_limit, 'com_hand_limit', com_hand_limit) while (democrat_hand.length < dem_hand_limit || communist_hand.length < com_hand_limit) { - console.log('deck.length: ', deck.length) + //console.log('deck.length: ', deck.length) //console.log('discard.length', game.strategy_discard ) if (deck.length === 0) { log_h3('--- Reshuffle ---') @@ -3657,16 +3670,16 @@ function draw_cards(deck, democrat_hand, communist_hand, dem_hand_limit, com_han else if (turn === 'communist' && communist_hand.length < com_hand_limit) { communist_hand.push(draw_card(deck)); - console.log('game.valid_cards after communist draw: ', JSON.stringify(game.valid_cards)); + //console.log('game.valid_cards after communist draw: ', JSON.stringify(game.valid_cards)); turn = 'democrat'; } else if(turn === 'communist' && communist_hand.length === com_hand_limit) { turn = 'democrat'; } else if (turn === 'democrat' && democrat_hand.length < dem_hand_limit) { democrat_hand.push(draw_card(deck)); - console.log('democrat_hand: ', democrat_hand) + //console.log('democrat_hand: ', democrat_hand) - console.log('game.valid_cards after democrat draw: ', JSON.stringify(game.valid_cards)); + //console.log('game.valid_cards after democrat draw: ', JSON.stringify(game.valid_cards)); turn = 'communist'; } else if (turn === 'democrat' && democrat_hand.length === dem_hand_limit) { @@ -3679,8 +3692,16 @@ function draw_cards(deck, democrat_hand, communist_hand, dem_hand_limit, com_han function draw_card(deck) { //console.log('draw card called with:', deck) + console.log('game.strategy_deck before', game.strategy_deck) + if (deck.length === 0) { + log_h3('--- Reshuffle ---') + + deck.push(...game.strategy_discard) + game.strategy_discard = [] + } const randomIndex = Math.floor(Math.random() * deck.length) //console.log('card chosen:', randomIndex) + console.log('game.strategy_deck after', game.strategy_deck) return deck.splice(randomIndex, 1)[0]; } @@ -4541,8 +4562,11 @@ function vm_do_add_infl(space) { log_summary(`Added £ SP in %${clicked_space}.`) - if (spaces[clicked_space].country !== 'East_Germany'){ - game.austria_hungary_border_reopened_tracker = false + //If AHBR - check AHBR condition + if (game.persistent_events.includes(58)) { + if (spaces[clicked_space].country !== 'East_Germany'){ + game.austria_hungary_border_reopened_tracker = false + } } // Check Genscher @@ -4945,6 +4969,7 @@ function vm_army_backs_revolution() { function vm_austria_hungary_border_reopened() { game.persistent_events.push(58) permanently_remove(58) + game.austria_hungary_border_reopened_tracker = false //game.table_cards.push(58) //remove_from_discard(58) vm_next() @@ -6164,7 +6189,7 @@ states.vm_support_check_prep = { // Check for Austria-Hungary Border Reopened - check on first support check only //First check for Monday Demonstrations - support checks will always be in East Germany - if (game.vm_event === 61) { + if (game.vm_event === 61 && game.persistent_events.includes(58)) { game.austria_hungary_border_reopened_tracker = true game.state = 'vm_do_support_check' return @@ -6172,13 +6197,15 @@ states.vm_support_check_prep = { //Then check Austria-Hungary Border Reopened normally //console.log('game.austria_hungary_border_reopened_checked', game.austria_hungary_border_reopened_checked) - if (game.active === DEM && game.vm_available_ops > 1) { - if (spaces[game.selected_space].country === 'East_Germany' && game.persistent_events.includes(58) && game.active === DEM) { - game.state = 'vm_austria_hungary_border_reopened_check' - return - } - //game.state = 'do_support_check' - } /*else { */ + if (game.persistent_events.includes(58)) { + if (game.active === DEM && game.vm_available_ops > 1) { + if (spaces[game.selected_space].country === 'East_Germany' && game.persistent_events.includes(58) && game.active === DEM) { + game.state = 'vm_austria_hungary_border_reopened_check' + return + } + //game.state = 'do_support_check' + } /*else { */ + } game.state = 'vm_do_support_check' }, done () { @@ -6209,14 +6236,16 @@ states.vm_ceh_support_check_prep = { //Then check Austria-Hungary Border Reopened normally //console.log('game.austria_hungary_border_reopened_checked', game.austria_hungary_border_reopened_checked) - if (game.active === DEM && game.vm_available_ops > 1) { - console.log('in ahb check, country, ', spaces[game.selected_space].country, 'ahb', game.persistent_events.includes(58)) - if (spaces[game.selected_space].country === 'East_Germany' && game.persistent_events.includes(58) && game.active === DEM) { - game.state = 'vm_austria_hungary_border_reopened_check' - return - } - //game.state = 'do_support_check' - } /*else { */ + if (game.persistent_events.includes(58)) { + if (game.active === DEM && game.vm_available_ops > 1) { + console.log('in ahb check, country, ', spaces[game.selected_space].country, 'ahb', game.persistent_events.includes(58)) + if (spaces[game.selected_space].country === 'East_Germany' && game.persistent_events.includes(58) && game.active === DEM) { + game.state = 'vm_austria_hungary_border_reopened_check' + return + } + //game.state = 'do_support_check' + } /*else { */ + } game.state = 'vm_ceh_do_support_check' }, done () { -- cgit v1.2.3