summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2024-10-22 00:02:23 +0200
committerTor Andersson <tor@ccxvii.net>2024-10-22 00:03:23 +0200
commit9161d8dab4ac318caf41f1f63879d59348d91554 (patch)
tree50f17ba820d2814729e8cd18aed510158b060962
parentfc71ebf81c6a7c672e0b13e1c274cef3a2e63b81 (diff)
downloadmaria-9161d8dab4ac318caf41f1f63879d59348d91554.tar.gz
victory check
-rw-r--r--play.js13
-rw-r--r--rules.js115
2 files changed, 99 insertions, 29 deletions
diff --git a/play.js b/play.js
index d8353a4..e012337 100644
--- a/play.js
+++ b/play.js
@@ -921,7 +921,18 @@ function layout_retro(s, pow) {
}
function layout_victory_pool(pow, max, x, y) {
- let n = 0
+ let n = view.vp[pow]
+ if (pow === P_PRUSSIA) {
+ if (view.flags & F_SILESIA_ANNEXED) ++n
+ }
+ if (pow === P_FRANCE) {
+ if (view.flags & F_ITALY_FRANCE) ++n
+ if (view.flags & F_EMPEROR_FRANCE) ++n
+ }
+ if (pow === P_AUSTRIA) {
+ if (view.flags & F_ITALY_AUSTRIA) ++n
+ if (view.flags & F_EMPEROR_AUSTRIA) ++n
+ }
for (let i = 0; i < view.victory.length; i += 2)
if (view.victory[i+1] === pow)
++n
diff --git a/rules.js b/rules.js
index 7e2dc29..8a123f6 100644
--- a/rules.js
+++ b/rules.js
@@ -966,10 +966,7 @@ function goto_start_turn() {
if (game.turn % 4 === 0) {
goto_winter_turn()
} else {
-
- // MARIA: politics
-
- goto_place_hussars()
+ goto_politics()
}
}
@@ -988,20 +985,16 @@ function goto_action_stage() {
function end_action_stage() {
clear_undo()
+ if (check_instant_victory())
+ return
+
if (++game.stage === 4)
goto_end_turn()
else
goto_action_stage()
}
-/* VICTORY */
-
-function check_victory() {
- // TODO
- return false
-}
-
-/* HUSSARS */
+/* AUSTRIA PLACES ITS HUSSARS */
function goto_place_hussars() {
set_active_to_power(P_AUSTRIA)
@@ -1621,10 +1614,6 @@ function give_troops(total) {
/* MOVEMENT */
-function movement_range() {
- return 3
-}
-
function goto_movement() {
set_active_to_current_action_stage()
@@ -1884,7 +1873,7 @@ states.move_supply_train = {
states.move_general = {
inactive: "move",
prompt() {
- prompt("Move " + format_selected() + format_move(movement_range()))
+ prompt("Move " + format_selected() + format_move(3))
view.selected = game.selected
let who = game.selected
@@ -1910,12 +1899,12 @@ states.move_general = {
view.actions.stop = 1
}
- if (game.count < movement_range() + game.main)
+ if (game.count < 3 + game.main)
for (let next of data.cities.main_roads[here])
if (can_move_general_to(here, next))
gen_action_space_or_piece(next)
- if (game.count < movement_range())
+ if (game.count < 3)
for (let next of data.cities.roads[here])
if (can_move_general_to(here, next))
gen_action_space_or_piece(next)
@@ -1948,7 +1937,7 @@ states.move_general = {
if (!set_has(data.cities.main_roads[from], to))
game.main = 0
- if (move_general_to(to, false) || ++game.count === movement_range() + game.main)
+ if (move_general_to(to, false) || ++game.count === 3 + game.main)
end_move_piece()
},
force_march() {
@@ -2038,10 +2027,7 @@ states.move_take = {
},
value(v) {
take_troops(v)
- if (game.state === "laudon_take")
- game.state = "austria_may_move_laudon_by_one_city_immediately"
- else
- game.state = "move_general"
+ game.state = "move_general"
},
}
@@ -2059,10 +2045,7 @@ states.move_give = {
},
value(v) {
give_troops(v)
- if (game.state === "laudon_give")
- game.state = "austria_may_move_laudon_by_one_city_immediately"
- else
- game.state = "move_general"
+ game.state = "move_general"
},
}
@@ -3169,6 +3152,82 @@ function goto_retroactive_conquest() {
end_action_stage()
}
+/* VICTORY */
+
+const power_victory_target = [ 11, 13, 8, 8 ]
+
+function elector_majority() {
+ let elector_france = 0
+ let elector_pragmatic = 0
+ for (let i = 0; i < 8; i += 2) {
+ if (view.elector[i+1] === P_FRANCE)
+ elector_france ++
+ else
+ elector_pragmatic ++
+ }
+ if (elector_france >= 3)
+ return P_FRANCE
+ if (elector_pragmatic >= 3)
+ return P_PRAGMATIC
+ return -1
+}
+
+function count_vp_markers(pow) {
+ let n = game.vp[pow]
+ if (pow === P_PRUSSIA) {
+ if (game.flags & F_SILESIA_ANNEXED) ++n
+ }
+ if (pow === P_FRANCE) {
+ if (game.flags & F_ITALY_FRANCE) ++n
+ if (game.flags & F_EMPEROR_FRANCE) ++n
+ if (elector_majority() === P_FRANCE) ++n
+ }
+ if (pow === P_AUSTRIA) {
+ if (game.flags & F_ITALY_AUSTRIA) ++n
+ if (game.flags & F_EMPEROR_AUSTRIA) ++n
+ }
+ if (pow === P_PRAGMATIC) {
+ if (elector_majority() === P_PRAGMATIC) ++n
+ }
+ for (let i = 0; i < game.victory.length; i += 2)
+ if (game.victory[i+1] === pow)
+ ++n
+ return n
+}
+
+function check_instant_victory() {
+ let margin = [
+ count_vp_markers(P_FRANCE) - 11,
+ count_vp_markers(P_PRUSSIA) - 13,
+ count_vp_markers(P_PRAGMATIC) - 8,
+ count_vp_markers(P_AUSTRIA) - 8,
+ ]
+
+ let best = 0
+ for (let pow = 1; pow < 4; ++pow)
+ if (margin[pow] >= margin[best])
+ best = pow
+
+ if (margin[best] >= 0) {
+ goto_game_over(player_from_power(best), power_name[best] + " won!")
+ return true
+ }
+
+ return false
+}
+
+/* POLITICS */
+
+function goto_politics() {
+ end_politics()
+}
+
+function end_politics() {
+ if (check_instant_victory())
+ return
+ goto_place_hussars()
+}
+
/* SETUP */
const POWER_FROM_SETUP_STAGE = [