summaryrefslogtreecommitdiff
path: root/rules.js
diff options
context:
space:
mode:
Diffstat (limited to 'rules.js')
-rw-r--r--rules.js113
1 files changed, 74 insertions, 39 deletions
diff --git a/rules.js b/rules.js
index be60e29..8541933 100644
--- a/rules.js
+++ b/rules.js
@@ -19,6 +19,7 @@ UI: show TC modifiers
UI: show subsidy contracts
when are subsidies given?
+ when drawn
when are subsidies created?
example france subsidy to prussia
at france's stage?
@@ -1287,6 +1288,26 @@ function search_hussar_bfs(from) {
/* TACTICAL CARDS */
+function for_each_card_in_hand(f) {
+ for (let c of game.hand1[game.power])
+ f(c)
+ for (let c of game.hand2[game.power]) // subsidies and returned cards
+ f(c)
+}
+
+function gen_cards_in_hand() {
+ for_each_card_in_hand(gen_action_card)
+}
+
+function remove_card_in_hand(c) {
+ set_delete(game.hand1[game.power], c)
+ set_delete(game.hand2[game.power], c)
+}
+
+function count_cards_in_hand() {
+ return game.hand1[game.power].length + game.hand2[game.power].length > 0
+}
+
function find_largest_discard(u) {
for (let i = 0; i < 4; ++i)
if (u[i] <= u[0] && u[i] <= u[1] && u[i] <= u[2] && u[i] <= u[3])
@@ -1299,7 +1320,9 @@ function count_used_cards() {
// count cards in hands
for (let pow of all_powers) {
- for (let c of game.hand[pow])
+ for (let c of game.hand1[pow])
+ held[to_deck(c)]++
+ for (let c of game.hand2[pow])
held[to_deck(c)]++
}
@@ -1419,8 +1442,12 @@ states.tactical_cards_show = {
}
function end_tactical_cards() {
+ for (let c of game.hand2[game.power])
+ set_add(game.hand1[game.power], c)
+ game.hand2[game.power] = []
+
for (let c of game.draw)
- set_add(game.hand[game.power], c)
+ set_add(game.hand1[game.power], c)
delete game.draw
// draw minor power's cards after major power
@@ -1682,14 +1709,13 @@ states.supply_hussars = {
str += "."
if (paid < debt)
- for (let c of game.hand[game.power])
- gen_action_card(c)
+ gen_cards_in_hand()
prompt(str)
view.draw = game.supply.pool
- if (debt === 0 || (!can_pay && game.hand[game.power].length === 0))
+ if (debt === 0 || (!can_pay && count_cards_in_hand() === 0))
view.actions.next = 1
},
piece(p) {
@@ -1707,7 +1733,7 @@ states.supply_hussars = {
},
card(c) {
push_undo()
- set_delete(game.hand[game.power], c)
+ remove_card_in_hand(c)
set_add(game.supply.pool, c)
},
next() {
@@ -1728,7 +1754,7 @@ states.supply_hussars = {
// put back into hand unused cards
for (let c of game.supply.pool)
- set_add(game.hand[game.power], c)
+ set_add(game.hand2[game.power], c) // TODO: or hand1
delete game.supply.pool
delete game.supply.used
@@ -2464,10 +2490,8 @@ states.re_enter_train = {
}
}
- if (paid / 4 < av_trains) {
- for (let c of game.hand[game.power])
- gen_action_card(c)
- }
+ if (paid / 4 < av_trains)
+ gen_cards_in_hand()
if (game.recruit.used.length > 0)
view.actions.next = 1
@@ -2498,7 +2522,7 @@ states.re_enter_train = {
},
card(c) {
push_undo()
- set_delete(game.hand[game.power], c)
+ remove_card_in_hand(c)
set_add(game.recruit.pool, c)
},
next() {
@@ -2541,7 +2565,7 @@ function end_re_enter_train() {
// put back into hand unused cards
for (let c of game.recruit.pool)
- set_add(game.hand[game.power], c)
+ set_add(game.hand2[game.power], c) // TODO: or hand1
delete game.recruit
@@ -2688,10 +2712,8 @@ states.recruit = {
view.draw = game.recruit.pool
if (av_troops > 0) {
- if (paid / 4 < av_troops) {
- for (let c of game.hand[game.power])
- gen_action_card(c)
- }
+ if (paid / 4 < av_troops)
+ gen_cards_in_hand()
if (paid >= 4) {
for (let p of all_power_generals[game.power]) {
@@ -2708,7 +2730,7 @@ states.recruit = {
},
card(c) {
push_undo()
- set_delete(game.hand[game.power], c)
+ remove_card_in_hand(c)
set_add(game.recruit.pool, c)
},
piece(p) {
@@ -2829,7 +2851,7 @@ function end_recruit() {
// put back into hand unused cards
for (let c of game.recruit.pool)
- set_add(game.hand[game.power], c)
+ set_add(game.hand2[game.power], c) // TODO: or hand1
delete game.recruit
} else {
@@ -3049,7 +3071,7 @@ function gen_play_card(suit) {
let score = Math.abs(game.count)
let has_suit = false
- for (let c of game.hand[game.power]) {
+ for_each_card_in_hand(c => {
let c_suit = to_suit(c)
if (c_suit === suit) {
has_suit = true
@@ -3057,7 +3079,7 @@ function gen_play_card(suit) {
} else if (c_suit === RESERVE) {
gen_action_card(c)
}
- }
+ })
// cannot pass if at 0 (and can play)
if (score === 0 && has_suit)
@@ -3095,7 +3117,7 @@ function play_reserve(v, sign) {
function play_combat_card(c, sign, resume, next_state) {
push_undo()
- array_remove_item(game.hand[game.power], c)
+ remove_card_in_hand(c)
if (is_reserve(c)) {
game.state = next_state
game.reserve = c
@@ -3594,7 +3616,7 @@ function goto_politics() {
// 25.1 Return face-down (previously placed) TCs to the players
for (let pow of all_major_powers) {
for (let c of game.face_down[pow])
- set_add(game.hand[pow], c)
+ set_add(game.hand2[pow], c)
game.face_down[pow] = []
}
@@ -3653,14 +3675,13 @@ states.place_tc_on_display = {
inactive: "place TC on political display",
prompt() {
prompt(`Place TC on political display (${suit_name[game.trump]} is trump).`)
- for (let c of game.hand[game.power])
- gen_action_card(c)
+ gen_cards_in_hand()
view.actions.pass = 1
},
card(c) {
push_undo()
log(power_name[game.power] + " placed a TC.")
- set_delete(game.hand[game.power], c)
+ remove_card_in_hand(c)
set_add(game.face_down[game.power], c)
game.state = "place_tc_on_display_done"
},
@@ -3985,7 +4006,7 @@ states.political_troops_draw = {
let info = event_troops[current_political_effect()]
if (info.tcs > 0) {
for (let c of game.draw)
- set_add(game.hand[game.power], c)
+ set_add(game.hand1[game.power], c)
delete game.draw
}
game.state = "political_troops_place"
@@ -4949,9 +4970,12 @@ function make_tactics_discard(n) {
return make_tactics_deck(n).filter(c => {
if (game.draw && set_has(game.draw, c))
return false
- for (let pow of all_powers)
- if (set_has(game.hand[pow], c))
+ for (let pow of all_powers) {
+ if (set_has(game.hand1[pow], c))
+ return false
+ if (set_has(game.hand2[pow], c))
return false
+ }
for (let pow of all_major_powers) {
if (set_has(game.face_up[pow], c))
return false
@@ -4989,7 +5013,8 @@ exports.setup = function (seed, _scenario, _options) {
pol_deck: null,
deck: null,
- hand: [ [], [], [], [], [], [] ],
+ hand1: [ [], [], [], [], [], [] ],
+ hand2: [ [], [], [], [], [], [] ],
// face-up (saved) TCs
face_up: [ [], [], [], [] ],
@@ -5031,7 +5056,7 @@ exports.setup = function (seed, _scenario, _options) {
// Deal initial cards
for (let pow of all_powers)
for (let i = 0; i < setup_initial_tcs[pow]; ++i)
- set_add(game.hand[pow], game.deck.pop())
+ set_add(game.hand1[pow], game.deck.pop())
log("# 1741")
@@ -5158,16 +5183,24 @@ function mask_troops(player) {
return view_troops
}
-function mask_hand(player) {
+function mask_hand1(player) {
+ let view_hand = []
+ for (let pow of all_powers) {
+ if (player_from_power(pow) === player)
+ view_hand[pow] = game.hand1[pow]
+ else
+ view_hand[pow] = game.hand1[pow].map(c => c & ~127)
+ }
+ return view_hand
+}
+
+function mask_hand2(player) {
let view_hand = []
for (let pow of all_powers) {
if (player_from_power(pow) === player)
- view_hand[pow] = game.hand[pow]
+ view_hand[pow] = game.hand2[pow]
else
- view_hand[pow] = game.hand[pow].map(c => c & ~127)
- //view_hand[pow] = game.hand[pow].length
- //view_hand[pow] = Math.ceil(game.hand[pow].length / 3) * 3
- //view_hand[pow] = Math.ceil(game.hand[pow].length / 5)
+ view_hand[pow] = game.hand2[pow].map(c => c & ~127)
}
return view_hand
}
@@ -5211,7 +5244,8 @@ exports.view = function (state, player) {
oos: game.oos,
supreme: game.supreme,
troops: mask_troops(player),
- hand: mask_hand(player),
+ hand1: mask_hand1(player),
+ hand2: mask_hand2(player),
pt: total_troops_list(),
discard: total_discard_list(),
@@ -5234,7 +5268,8 @@ exports.view = function (state, player) {
if (game.state === "game_over") {
view.prompt = game.victory
view.troops = game.troops
- view.hand = game.hand
+ view.hand1 = game.hand1
+ view.hand2 = game.hand2
} else if (game.active !== player) {
let inactive = states[game.state].inactive || game.state
if (typeof inactive === "function")