summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2024-05-26 01:25:12 +0200
committerTor Andersson <tor@ccxvii.net>2024-05-30 21:59:25 +0200
commit816b0f22d45894544e6d9d4d2252c7854cabd88e (patch)
tree207ce2d3c019742638e2959a0e88258a9b8bbe58
parent66dfcd920e52ea0966cf5f4602545965cea2754c (diff)
downloadfriedrich-816b0f22d45894544e6d9d4d2252c7854cabd88e.tar.gz
must play zero
-rw-r--r--play.js35
-rw-r--r--rules.js63
2 files changed, 57 insertions, 41 deletions
diff --git a/play.js b/play.js
index 46e0083..cc3eb25 100644
--- a/play.js
+++ b/play.js
@@ -89,7 +89,6 @@ const all_power_trains = [
const RESERVE = 4
let suit_class = [ "S", "C", "H", "D", "R" ]
-let suit_name = [ "\u2660", "\u2663", "\u2665", "\u2666", "R" ]
function to_suit(c) {
return (c >> 4) & 7
@@ -836,18 +835,26 @@ function cmp_tc(a, b) {
return ax - bx
}
-const colorize_S = '<span class="spades">$&</span>'
-const colorize_C = '<span class="clubs">$&</span>'
-const colorize_H = '<span class="hearts">$&</span>'
-const colorize_D = '<span class="diamonds">$&</span>'
-const colorize_R = '<span class="reserve">$&</span>'
+const colorize_S = '<span class="suit spades">\u2660</span>'
+const colorize_C = '<span class="suit clubs">\u2663</span>'
+const colorize_H = '<span class="suit hearts">\u2665</span>'
+const colorize_D = '<span class="suit diamonds">\u2666</span>'
+const colorize_R = '$1<span class="suit reserve">R</span>'
+
+const suit_text = [
+ '<span class="suit spades">\u2660</span>',
+ '<span class="suit clubs">\u2663</span>',
+ '<span class="suit hearts">\u2665</span>',
+ '<span class="suit diamonds">\u2666</span>',
+ '<span class="suit reserve">R</span>'
+]
function colorize(text) {
- text = text.replace(/\d+\u2660/g, colorize_S)
- text = text.replace(/\d+\u2663/g, colorize_C)
- text = text.replace(/\d+\u2665/g, colorize_H)
- text = text.replace(/\d+\u2666/g, colorize_D)
- text = text.replace(/\d+R/g, colorize_R)
+ text = text.replaceAll("\u2660", colorize_S)
+ text = text.replaceAll("\u2663", colorize_C)
+ text = text.replaceAll("\u2665", colorize_H)
+ text = text.replaceAll("\u2666", colorize_D)
+ text = text.replace(/(\d+)R/g, colorize_R)
return text
}
@@ -910,7 +917,7 @@ function on_update() {
ui.markers_element.appendChild(ui.retro[s])
/* troops 1-8, reserve 1-10 with modifiers +1 and +5 */
- for (let v = 16; v >= 1; --v)
+ for (let v = 16; v >= 0; --v)
action_button_with_argument("value", v, v)
action_button("take", "Take")
@@ -972,8 +979,8 @@ function sub_tc(match, p1) {
let suit = to_suit(x)
let value = to_value(x)
if (suit === RESERVE)
- return suit_name[suit]
- return value + suit_name[suit]
+ return suit_text[suit]
+ return value + suit_text[suit]
}
function on_log(text) {
diff --git a/rules.js b/rules.js
index 146e786..5fa3621 100644
--- a/rules.js
+++ b/rules.js
@@ -2491,8 +2491,10 @@ function gen_play_reserve() {
for (let i = n + 1; i < 10; ++i)
view.actions.value.push(i)
view.actions.value.push(10)
+ } else if (fate_card_zero()) {
+ view.actions.value.push(0)
} else {
- let bonus = fate_card_bonus()
+ let bonus = fate_card_bonus(0, 0)
let max = 10
if (forbid_play_value_10_or_more())
max = 9
@@ -2501,6 +2503,13 @@ function gen_play_reserve() {
}
}
+function fate_card_zero() {
+ if (game.fx === NEXT_TURN_IF_FRIEDRICH_IS_ATTACKED_THE_FIRST_TC_PLAYED_BY_PRUSSIA_IS_WORTH_NOTHING_0_POINTS)
+ if (game.power === P_PRUSSIA && game.pos[GEN_FRIEDRICH] === game.defender)
+ return true
+ return false
+}
+
function fate_card_bonus(c) {
if (game.fx === NEXT_TURN_THE_FIRST_TC_PLAYED_BY_FRANCE_IS_WORTH_AN_ADDITIONAL_POINT)
if (game.power === P_FRANCE)
@@ -2508,9 +2517,6 @@ function fate_card_bonus(c) {
if (game.fx === NEXT_TURN_IF_FRIEDRICH_ATTACKS_HIS_FIRST_TC_IS_WORTH_5_ADDITIONAL_POINTS)
if (game.power === P_PRUSSIA && game.pos[GEN_FRIEDRICH] === game.attacker)
return 5
- if (game.fx === NEXT_TURN_IF_FRIEDRICH_IS_ATTACKED_THE_FIRST_TC_PLAYED_BY_PRUSSIA_IS_WORTH_NOTHING_0_POINTS)
- if (game.power === P_PRUSSIA && game.pos[GEN_FRIEDRICH] === game.defender)
- return 0
if (game.fx === NEXT_TURN_PRUSSIA_MAY_PLAY_THE_11_OF_SPADES_ONCE_AT_DOUBLE_VALUE)
if (game.power === P_PRUSSIA && to_suit(c) === SPADES && to_value(c) === 11)
return 11
@@ -2518,6 +2524,11 @@ function fate_card_bonus(c) {
}
function play_card(c, sign) {
+ if (fate_card_zero()) {
+ log(POWER_NAME[game.power] + " C" + c + " - " + to_value(c) + " = " + game.count)
+ clear_fate_effect()
+ return
+ }
let bonus = fate_card_bonus(c)
if (sign < 0)
game.count -= to_value(c) + bonus
@@ -2532,20 +2543,36 @@ function play_card(c, sign) {
}
function play_reserve(v, sign) {
- // bonus is already baked into v!
+ if (fate_card_zero()) {
+ log(POWER_NAME[game.power] + " 0R = " + game.count)
+ clear_fate_effect()
+ return
+ }
let bonus = fate_card_bonus(0)
if (sign < 0)
game.count -= v
else
game.count += v
if (bonus > 0)
- log(POWER_NAME[game.power] + " reserve " + (v-bonus) + " + " + bonus + " = " + (game.count))
+ log(POWER_NAME[game.power] + " " + (v-bonus) + "R +" + bonus + " = " + (game.count))
else
- log(POWER_NAME[game.power] + " reserve " + (v) + " = " + (game.count))
+ log(POWER_NAME[game.power] + " " + (v) + "R = " + (game.count))
if (bonus > 0)
clear_fate_effect()
}
+function play_combat_card(c, sign, resume, next_state) {
+ push_undo()
+ array_remove_item(game.hand[game.power], c)
+ let c_suit = to_suit(c)
+ if (c_suit === RESERVE) {
+ game.state = next_state
+ } else {
+ play_card(c, sign)
+ resume()
+ }
+}
+
states.combat_attack = {
inactive: inactive_attack,
prompt() {
@@ -2554,16 +2581,7 @@ states.combat_attack = {
gen_play_card(get_space_suit(game.attacker))
},
card(c) {
- push_undo()
-
- array_remove_item(game.hand[game.power], c)
- let c_suit = to_suit(c)
- if (c_suit === RESERVE) {
- game.state = "combat_attack_reserve"
- } else {
- play_card(c, +1)
- resume_combat_attack()
- }
+ play_combat_card(c, +1, resume_combat_attack, "combat_attack_reserve")
},
pass() {
clear_undo()
@@ -2579,16 +2597,7 @@ states.combat_defend = {
gen_play_card(get_space_suit(game.defender))
},
card(c) {
- push_undo()
-
- array_remove_item(game.hand[game.power], c)
- let c_suit = to_suit(c)
- if (c_suit === RESERVE) {
- game.state = "combat_defend_reserve"
- } else {
- play_card(c, -1)
- resume_combat_defend()
- }
+ play_combat_card(c, -1, resume_combat_defend, "combat_defend_reserve")
},
pass() {
clear_undo()