summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoriainp5 <iain.pearce.ip@gmail.com>2024-07-14 14:28:57 +0100
committerGitHub <noreply@github.com>2024-07-14 14:28:57 +0100
commit17bc208d942fd833e7787cbe78700ce730f6ebd0 (patch)
treece8bff602f1a87017ea5bf45efa2dd5e7d768bde
parentfe5b6789ecc6b3f525b162614c270feff830718b (diff)
download1989-dawn-of-freedom-17bc208d942fd833e7787cbe78700ce730f6ebd0.tar.gz
Update rules.js
-rw-r--r--rules.js126
1 files changed, 13 insertions, 113 deletions
diff --git a/rules.js b/rules.js
index 67b627b..90dab53 100644
--- a/rules.js
+++ b/rules.js
@@ -339,9 +339,6 @@ exports.setup = function (seed, scenario, options) {
}
log_h1("1989 Dawn of Freedom")
-
- console.log('game.raised_stakes_discard: ', game.raised_stakes_discard)
-
game.active = COM
start_game()
@@ -352,14 +349,9 @@ function start_game() {
//starting influence
// Draw cards
- /* const card_numbers = cards.filter(card => card !== null && card !== undefined).map(card => card.number);
- console.log('card numbers: ', card_numbers) */
game.strategy_deck = draw_deck(cards)
reset_power()
- console.log('game.strategy_deck: ', game.strategy_deck[1])
draw_cards(game.strategy_deck, game.democrat_hand, game.communist_hand, game.dem_hand_limit, game.com_hand_limit)
- console.log('game.strategy_deck: ', game.strategy_deck[1], 'democrat_hand:', game.democrat_hand)
-
spaces.forEach(space => {
game.pieces.push({
name_unique: space.name_unique,
@@ -372,8 +364,6 @@ function start_game() {
});
});
game.valid_spaces = valid_spaces();
- console.log('game.valid_spaces: ', game.valid_spaces)
- //console.log('game.pieces: ', game.pieces)
//Communist starts by placing 2 influence
game.available_ops = 2
log_h1("Place starting influence")
@@ -482,7 +472,6 @@ function gen_action(action, argument) {
view.actions[action] = []
view.actions[action].push(argument)
}
- //console.log('view.actions: ', view.actions, 'view.actions[action]: ', view.actions[action])
}
function gen_action_infl(space){
@@ -502,7 +491,6 @@ function gen_action_scoring(){
}
exports.action = function (state, player, action, arg) {
- //console.log('exports.action called with state:' , state, 'player:', player, 'action: ', action, 'arg: ', arg)
game = state
if (states[game.state] && action in states[game.state]) {
states[game.state][action](arg, player)
@@ -641,7 +629,6 @@ states.play_card ={
inactive: 'play a card',
prompt () {
if (game.is_pwr_struggle) {
- console.log('in is_pwr_struggle')
view.prompt = 'Draw cards'
gen_action('draw')
return
@@ -649,10 +636,9 @@ states.play_card ={
view.prompt = 'Play for:'
- if (scoring_cards.includes(game.played_card)) {
- gen_action('scoring');
- } else {
-
+ if (scoring_cards.includes(game.played_card)) {
+ gen_action('scoring');
+ } else {
if (cards[game.played_card].playable ===1) {
gen_action('event')
}
@@ -665,7 +651,6 @@ states.play_card ={
},
scoring() {
push_undo()
- console.log('in scoring')
if (game.played_card === 17) { game.pwr_struggle_in ="East Germany" }
if (game.played_card === 18) { game.pwr_struggle_in = "Czechoslovakia" }
if (game.played_card === 19) { game.pwr_struggle_in = "Bulgaria"}
@@ -676,9 +661,7 @@ states.play_card ={
},
draw() {
push_undo()
- console.log('game.pwr_struggle_in: ', game.pwr_struggle_in)
let presence = check_presence(game.pwr_struggle_in)
- console.log('presence', presence)
if (presence.dem_spaces > 0) {
game.dem_pwr_hand_limit = 6 + 2*(presence.dem_spaces - 1)
} else {
@@ -689,38 +672,29 @@ states.play_card ={
} else {
game.com_pwr_hand_limit = 0
}
-
- //console.log('dem limit:' , game.dem_pwr_hand_limit, 'com limit: ', game.com_pwr_hand_limit)
-
- console.log(game.power_struggle_deck, game.dem_pwr_hand, game.com_pwr_hand, game.dem_pwr_hand_limit, game.com_pwr_hand_limit)
draw_cards(game.power_struggle_deck, game.dem_pwr_hand, game.com_pwr_hand, game.dem_pwr_hand_limit, game.com_pwr_hand_limit)
game.valid_cards = all_power_cards
game.state = 'raise_stakes'
},
event() {
push_undo()
- console.log('in event()')
call_event(game.played_card)
},
influence(influence) {
push_undo()
- console.log('influence called')
game.state='add_influence'
valid_spaces()
},
tst(tst) {
push_undo()
- console.log('tst called')
game.state='tiananmen_square_attempt'
},
support_check(space) {
push_undo()
- console.log('sc called')
game.available_ops = 2
game.state='support_check_prep'
valid_spaces()
}
-
}
states.add_influence = {
@@ -823,8 +797,6 @@ states.raise_stakes = {
inactive: 'raise the stakes',
prompt () {
- //console.log('game.raised_stakes_discard: ', game.raised_stakes_discard)
- //console.log('game.raised_stakes_round: ', game.raised_stakes_round)
if (game.raised_stakes_round === 2) {
console.log('game raised stakes round == 2')
gen_action('struggle')
@@ -840,7 +812,6 @@ states.raise_stakes = {
view.prompt = `Discard ${3-game.raised_stakes_discard} cards to raise the stakes`
gen_action('done')
}
- console.log('game.valid_cards in raise the stakes: ', game.valid_cards)
for (let card of game.valid_cards) {
gen_action_card(card)
}
@@ -874,14 +845,6 @@ states.raise_stakes = {
},
struggle () {
do_valid_cards()
-
- /*let presence = check_presence(game.pwr_struggle_in)
- if (game.active === DEM) {
- valid_cards(game.dem_pwr_hand, presence.dem_leaders)
-
- } else {
- valid_cards(game.com_pwr_hand, presence.com_leaders)}
- //console.log('presence.dem_leaders: ', presence.dem_leaders, 'presence.com_leaders: ', presence.com_leaders)*/
game.state = 'power_struggle'
}
@@ -892,21 +855,15 @@ states.power_struggle = {
prompt () {
if (game.respond === 0 && game.valid_cards.length > 0) {
view.prompt = "Play a card"
- console.log('game.valid_cards: ', game.valid_cards)
- //console.log('dem_pwr_hand: ', game.dem_pwr_hand, 'com_pwr_hand: ', game.com_pwr_hand)
- //console.log('game.valid_cards: ', game.valid_cards, 'view.valid_cards: ', view.valid_cards)
for (let card of game.valid_cards) {
gen_action_card(card)
}
} else if (game.respond === 0 && game.valid_cards.length === 0) {
view.prompt = 'No valid cards. You must concede.'
gen_action('concede')
- }
-
- if (game.respond === 1 && game.valid_cards.length > 0) {
+ } else if (game.respond === 1 && game.valid_cards.length > 0) {
view.prompt = `${power_cards[game.played_power_card].name} played. You must match or concede`
gen_action('concede')
- console.log('game.valid_cards: ', game.valid_cards)
for (let card of game.valid_cards) {
gen_action_card(card)
}
@@ -950,7 +907,6 @@ states.power_struggle = {
},
card(card) {
push_undo()
- console.log('game.respond: ', game.respond)
discard(card)
if (game.respond === 0 && card >= 37 && card <= 48) {
game.played_power_card = card
@@ -976,15 +932,10 @@ states.power_struggle = {
else if (game.respond === 0) {
log(`Played: ${power_cards[card].name} ${power_cards[card].value}`)
game.played_power_card = card
- console.log('played power card when game respond 0:' , game.played_power_card)
game.respond = 1
next_player()
do_valid_cards()
- /*let presence = check_presence(game.pwr_struggle_in)
- if (game.active === DEM) {
- valid_cards(game.dem_pwr_hand, presence.dem_leaders)
- } else {valid_cards(game.com_pwr_hand, presence.com_leaders)}*/
-
+
} else if (game.respond === 1) {
if (card === 52) {
log(`Played Tactic Fails: ${power_cards[game.played_power_card].name} no longer playable`)
@@ -1123,7 +1074,6 @@ states.support_loss ={
log(`Modified roll: ${roll}`)
game.available_ops = support_loss_roll[roll]
game.respond++
- console.log('game.respond: ', game.respond)
valid_spaces()
},
infl (space) {
@@ -1171,9 +1121,7 @@ states.vp_roll = {
log(`Modified roll: ${roll}`)
let vp_change = vp_roll[roll]
log(`Gain ${vp_change} VP`)
- if (roll >= 4) {console.log('Democrat takes power')}
- console.log('starting VP: ', game.vp)
- console.log('change VP:', vp_change)
+ if (roll >= 4) {log('Democrat takes power')}
if (game.active === DEM) {game.vp += vp_change}
else {game.vp -= vp_change}
if (game.active === DEM && roll >= 4) {
@@ -1182,17 +1130,12 @@ states.vp_roll = {
game.respond = 0
game.state = 'choose_power'
}
-
- console.log('game.respond: ', game.respond)
},
take () {
- console.log('game.revolutions: ', game.revolutions)
take_power(game.pwr_struggle_in)
game.respond = 4
},
scoring () {
- console.log('in scoring')
- console.log('game.pwr_struggle_in: ', game.pwr_struggle_in)
score_country(game.pwr_struggle_in)
game.state = 'score_country'
},
@@ -1257,8 +1200,7 @@ function add_infl(space) {
log(`Added 1 influence in ${space}.`)
push_undo()
const clicked_space = find_space_index(space)
-
- console.log('space:', space, 'opponent control: ', check_control(space))
+
if (check_control(space)) {
game.available_ops -= 2
} else {
@@ -1284,13 +1226,11 @@ function add_infl(space) {
}
function remove_infl(space) {
- console.log('remove influence called with ', space)
log(`Removed 1 influence from ${space}.`)
push_undo()
const clicked_space = find_space_index(space)
if (game.remove_opponent_infl === true) {
- console.log('in remove opponenet infl true')
if (game.active === COM) {
game.pieces[clicked_space].demInfl--
} else {
@@ -1304,7 +1244,6 @@ function remove_infl(space) {
game.pieces[clicked_space].comCtrl = 0
}
} else {
- console.log('remove opponenet infl not true')
if (game.active === COM) {
game.pieces[clicked_space].comInfl--
} else {
@@ -1330,7 +1269,6 @@ function do_sc(space) {
log(`+${cards[game.played_card].ops} from card ops`)
const adj = count_adj(space)
- console.log('adj: ', adj)
if (adj.dem_adj > 0 || adj.com_adj > 0 ){
if (game.active === DEM) {
roll += adj.dem_adj
@@ -1359,7 +1297,6 @@ function do_sc(space) {
const change_infl = Math.max(0, roll - stability*2)
if (change_infl > 0) {
log(`${change_infl} point swing`)
- console.log('change_infl: ', change_infl)
let clicked_space = find_space_index(space)
if(game.active === DEM) {
if (change_infl > game.pieces[clicked_space].comInfl) {
@@ -1397,21 +1334,18 @@ function valid_spaces() {
let valid_spaces_set = new Set();
if (game.state === 'com_init') {
- //console.log('Valid spaces calculated for communist. Before run game.valid_spaces = ', game.valid_spaces, 'and game.valid_spaces.length = ',game.valid_spaces.length);
for (let space of game.pieces) {
if (space.demInfl === 0) {
valid_spaces_set.add(space.space_id);
}
}
} else if (game.state === 'dem_init') {
- //console.log('Valid spaces calculated for democrat');
for (let space of game.pieces) {
if (space.comInfl === 0) {
valid_spaces_set.add(space.space_id);
}
}
} else if (game.state === 'support_check_prep' || game.state === 'do_support_check') {
- //console.log('valid spaces calculated for support check')
if (game.active === DEM) {
for (let space of game.pieces) {
if (space.comInfl !== 0) {
@@ -1489,16 +1423,13 @@ function valid_spaces() {
}
}
}
- // Convert the set to an array before returning
game.valid_spaces = Array.from(valid_spaces_set);
- console.log('game.valid_spaces: ', game.valid_spaces);
return game.valid_spaces;
}
function valid_cards(player_hand, presence) {
const valid_cards_set= new Set();
if (game.respond === 0) {
- console.log('player hand: ', player_hand)
for (let c of player_hand) {
let card = power_cards.find(card => card && card.number === c);
if (card.number === 52) {continue} // Never add tactics fails
@@ -1534,7 +1465,6 @@ function do_valid_cards() {
function count_adj(name_unique) {
const space = spaces[find_space_index(name_unique)]
- //console.log('space: ', space)
let dem_adj = 0
let com_adj = 0
@@ -1551,7 +1481,6 @@ function count_adj(name_unique) {
}
}
}
- console.log('dem_adj: ', dem_adj, 'com_adj: ', com_adj)
return {dem_adj, com_adj}
}
@@ -1675,10 +1604,8 @@ function battlegrounds(country) {
}
function take_power(country) {
- console.log('game.revolutions: ', game.revolutions)
log(`Democrat takes power in ${game.pwr_struggle_in}`)
game.revolutions[country] = true
- console.log('game.revolutions: ', game.revolutions)
}
function retain_power(country){
@@ -1686,7 +1613,6 @@ function retain_power(country){
let vp_gain = get_value(country)*game.times_held[country]
log(`Communist gains ${vp_gain}VP from holding power`)
game.vp -= vp_gain
- console.log('times_held: ', game.times_held)
}
function find_country(country) {
@@ -1697,7 +1623,6 @@ function score_country(country) {
log_h3('Scoring')
let status
let presence = check_presence(country)
- console.log('presence: ', presence)
if (presence.dem_domination) {status = "Democrat has domination"}
else if (presence.com_domination) {status = "Communist has domination"}
else if (presence.dem_control) {status = "Democrat has control"}
@@ -1708,18 +1633,13 @@ function score_country(country) {
log(`${presence.com_battlegrounds} Communist battlegrounds`)
let value = get_value(country)
- console.log('value: ', value)
let dem_vp = 0
if (presence.dem_spaces > 0) {dem_vp += value}
- console.log('dem_vp after presence: ', dem_vp)
if (presence.dem_domination) {dem_vp += value}
- console.log('dem_vp after domination: ', dem_vp)
if (presence.dem_control && country !== "Hungary") {
- dem_vp += value
- console.log('dem_vp after control: ', dem_vp)}
+ dem_vp += value}
else if (presence.dem_control && country === "Hungary") {dem_vp += 2}
dem_vp += presence.dem_battlegrounds
- console.log('dem_vp after battlegrounds: ', dem_vp)
let com_vp = 0
if (presence.com_spaces > 0) {com_vp += value}
@@ -1730,15 +1650,10 @@ function score_country(country) {
let change_vp = dem_vp - com_vp
game.vp += change_vp
log(`Final VP: ${change_vp} VP`)
-
- console.log('dem_vp: ', dem_vp)
- console.log('com_vp: ', com_vp)
- console.log('change_vp: ', change_vp)
}
function get_value(country) {
let value
- console.log('get_value country: ', country)
if (country === "East Germany" || country === "Poland") {value = 3}
else if (country === "Czechoslovakia" || country === "Romania" || country === "Bulgaria") {value = 2}
else value = 1
@@ -1822,36 +1737,28 @@ 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)
let turn = 'communist'; // Start with the communist player
while (democrat_hand.length < dem_hand_limit || communist_hand.length < com_hand_limit) {
- //console.log('deck.length: ', deck.length)
if (deck.length === 0) {
log_h3('--- Reshuffle ---')
-
deck.push(...game.strategy_discard)
game.strategy_discard = []
}
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));
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('game.valid_cards after democrat draw: ', JSON.stringify(game.valid_cards));
turn = 'communist';
}
else if (turn === 'democrat' && democrat_hand.length === dem_hand_limit) {
turn = 'communist';
}
}
- console.log('game.valid_cards at end of draw cards: ', game.valid_cards)
clear_undo()
}
@@ -1861,7 +1768,6 @@ function draw_card(deck) {
}
function discard(card) {
- console.log('in discard(card)')
let find_card
if (!game.is_pwr_struggle) {
if (game.active === COM) {
@@ -1875,8 +1781,6 @@ function discard(card) {
} else if (game.is_pwr_struggle) {
log(`Discarded ${power_cards[card].name}`)
- console.log('dem hand before:', game.dem_pwr_hand)
- console.log('card to be discarded:', card)
if (game.active === COM) {
find_card = game.com_pwr_hand.indexOf(card);
game.com_pwr_hand.splice(find_card, 1);
@@ -1885,21 +1789,20 @@ function discard(card) {
game.dem_pwr_hand.splice(find_card, 1);
}
game.power_struggle_discard.push(card)
- console.log('dem hand after: ', game.dem_pwr_hand)
}
}
function add_midyear() {
- const mid_year = cards.filter(card => card && card.period === 2).map(card => card.number);
- game.strategy_deck.push(...mid_year);
+ const mid_year = cards.filter(card => card && card.period === 2).map(card => card.number)
+ game.strategy_deck.push(...mid_year)
log_h3('Mid-year cards added to draw deck')
}
-
function add_lateyear() {
- const late_year = cards.filter(card => card && card.period === 2).map(card => card.number);
- game.strategy_deck.push(...late_year);
+ const late_year = cards.filter(card => card && card.period === 2).map(card => card.number)
+ game.strategy_deck.push(...late_year)
+ log_h3('Late-year cards added to draw deck')
}
function reset_power() {
@@ -1925,9 +1828,6 @@ function shuffle(list) {
return list
}
-
-
-
// ======== LOG COMMANDS =============
function log(msg) {