diff --git a/.github/workflows/bench.yml b/.github/workflows/bench.yml index fc9b3c4b..fe62d8ad 100644 --- a/.github/workflows/bench.yml +++ b/.github/workflows/bench.yml @@ -1,13 +1,10 @@ name: Performance Benchmark on: - workflow_dispatch: - # still hangs -# -# push: -# branches: [ "main" ] -# pull_request: -# branches: [ "main" ] + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] jobs: check: diff --git a/client/src/status_phase_ui.rs b/client/src/status_phase_ui.rs index e3452b5f..a5f01a3b 100644 --- a/client/src/status_phase_ui.rs +++ b/client/src/status_phase_ui.rs @@ -52,7 +52,7 @@ pub fn change_government_type_dialog( .get_governments() .iter() .find(|g| g.advances[0].name == a.name) - .is_some_and(|_| p.can_advance_in_change_government(a.advance, rc.game)) + .is_some_and(|_| p.can_advance_ignore_contradicting(a.advance, rc.game)) { AdvanceState::Available } else if rc.shown_player.has_advance(a.advance) && a.government.is_some() { diff --git a/mise.toml b/mise.toml index ed5c3c8b..6fea0f26 100644 --- a/mise.toml +++ b/mise.toml @@ -4,8 +4,13 @@ RUSTFLAGS = '-Dwarnings' # Make sure CI fails on all warnings, including Clippy CARGO_TERM_COLOR = 'always' [tasks.random-actions] -description = "Run server tests" -run = 'cargo nextest run --release --nocapture test_random_actions -Pbench' +description = "Run random actions tests" +run = 'cargo test --package server --test random_actions test_random_actions -- --exact --nocapture' +dir = "server" + +[tasks.profile-random-actions] +description = "Run AI random actions test with profiling" +run = ["cargo test --release --features profiling --package server --test random_actions test_random_actions -- --exact --nocapture"] dir = "server" [tasks.test] @@ -62,11 +67,6 @@ description = "Run AI client with profiling" run = ["cargo run --release --package client --features profiling --bin local_client -- ai"] dir = "client" -[tasks.profile-random-actions] -description = "Run AI random actions test with profiling" -run = ["cargo test --release --features profiling random_actions"] -dir = "server" - [tools] "cargo:cargo-nextest" = "latest" rust = { version = "latest", components = "clippy,rustfmt" } diff --git a/server/.config/nextest.toml b/server/.config/nextest.toml index 655caeae..f7b60887 100644 --- a/server/.config/nextest.toml +++ b/server/.config/nextest.toml @@ -2,4 +2,4 @@ default-filter = 'not test(test_random_actions)' [profile.bench] -default-filter = 'all()' +default-filter = 'test(random_actions)' diff --git a/server/src/ability_initializer.rs b/server/src/ability_initializer.rs index 124d6315..5ef3fe33 100644 --- a/server/src/ability_initializer.rs +++ b/server/src/ability_initializer.rs @@ -918,18 +918,18 @@ where let key = setup.get_key().clone(); let deinitialize_event = event.clone(); let initializer = move |game: &mut Game, player_index: usize, prio_delta: i32| { - event(&mut game.players[player_index].events) - .inner + let e = event(&mut game.players[player_index].events); + e.inner .as_mut() - .expect("events should be set") + .unwrap_or_else(|| panic!("event {} should be set: {key:?}", e.name)) .add_listener_mut(listener.clone(), priority + prio_delta, key.clone()); }; let key = setup.get_key().clone(); let deinitializer = move |game: &mut Game, player_index: usize| { - deinitialize_event(&mut game.players[player_index].events) - .inner + let e = deinitialize_event(&mut game.players[player_index].events); + e.inner .as_mut() - .expect("events should be set") + .unwrap_or_else(|| panic!("event {} should be set: {key:?}", e.name)) .remove_listener_mut_by_key(&key); }; setup diff --git a/server/src/action.rs b/server/src/action.rs index da6a8d8b..e457f63f 100644 --- a/server/src/action.rs +++ b/server/src/action.rs @@ -22,7 +22,7 @@ use crate::movement::MovementAction::{Move, Stop}; use crate::movement::{ CurrentMove, MoveState, MoveUnits, MovementAction, has_movable_units, move_units_destinations, }; -use crate::objective_card::{on_objective_cards, present_objective_cards}; +use crate::objective_card::{gain_objective_card, on_objective_cards, present_objective_cards}; use crate::playing_actions::{PlayingAction, PlayingActionType}; use crate::recruit::on_recruit; use crate::resource::check_for_waste; @@ -44,33 +44,6 @@ pub enum Action { } impl Action { - #[must_use] - pub fn playing(self) -> Option { - if let Self::Playing(v) = self { - Some(v) - } else { - None - } - } - - #[must_use] - pub fn movement(self) -> Option { - if let Self::Movement(v) = self { - Some(v) - } else { - None - } - } - - #[must_use] - pub fn response(self) -> Option { - if let Self::Response(v) = self { - Some(v) - } else { - None - } - } - #[must_use] pub fn get_type(&self) -> ActionType { match self { @@ -101,7 +74,7 @@ pub enum ActionType { pub fn execute_action(mut game: Game, action: Action, player_index: usize) -> Game { assert_eq!(player_index, game.active_player(), "Not your turn"); - if !game.supports_undo { + if game.ai_mode { execute_without_undo(&mut game, action, player_index).expect("action should be executed"); return game; } @@ -152,7 +125,11 @@ pub fn execute_without_undo( match game.current_event_handler_mut() { Some(s) => { - s.response = action.response(); + s.response = if let Action::Response(v) = action { + Some(v) + } else { + return Err(format!("action should be a response: {action:?}")); + }; let details = game.current_event().event_type.clone(); execute_custom_phase_action(game, player_index, details) } @@ -161,6 +138,10 @@ pub fn execute_without_undo( check_for_waste(game); update_stats(game); + if let Some(o) = game.player(player_index).gained_objective { + gain_objective_card(game, player_index, o); + } + if game .player(player_index) .cities @@ -257,19 +238,24 @@ fn execute_regular_action( ) -> Result<(), String> { match game.state { Playing => { - if let Some(m) = action.clone().movement() { - execute_movement_action(game, m, player_index) + if let Action::Movement(m) = action { + execute_movement_action(game, m.clone(), player_index) } else { - let action = action.playing().expect("action should be a playing action"); + let Action::Playing(action) = action else { + return Err(format!("Action {action:?} is not a playing action")); + }; action.execute(game, player_index, false) } } - Movement(_) => { - let action = action - .movement() - .expect("action should be a movement action"); - execute_movement_action(game, action, player_index) - } + Movement(_) => execute_movement_action( + game, + if let Action::Movement(v) = action { + v + } else { + return Err(format!("action {action:?} is not a movement action")); + }, + player_index, + ), Finished => Err("actions can't be executed when the game is finished".to_string()), } } diff --git a/server/src/ai.rs b/server/src/ai.rs index 5495aee2..7a749164 100644 --- a/server/src/ai.rs +++ b/server/src/ai.rs @@ -220,7 +220,7 @@ async fn evaluate_action( let action_group_score = get_action_group_score(game, action_group, &players_active_missions[player_index]); let mut game = game.clone(); - game.supports_undo = false; + game.ai_mode = true; let game = action::execute_action(game, action.clone(), player_index); let score = get_average_score( game, diff --git a/server/src/ai_actions.rs b/server/src/ai_actions.rs index cef7eda2..34d2f766 100644 --- a/server/src/ai_actions.rs +++ b/server/src/ai_actions.rs @@ -1,5 +1,4 @@ use crate::action::{Action, ActionType}; -use crate::advance::Advance; use crate::card::validate_card_selection; use crate::city::{City, MoodState}; use crate::collect::available_collect_actions; @@ -69,9 +68,12 @@ impl AiActions { /// e.g. selecting to sacrifice a unit for an incident) /// - move actions are not returned at all - this required special handling /// + /// # Panics + /// + /// Panics if the actions for any type is empty #[must_use] pub fn get_available_actions(&mut self, game: &Game) -> Vec<(ActionType, Vec)> { - if let Some(event) = game.events.last() { + let actions = if let Some(event) = game.events.last() { vec![( ActionType::Response, responses(event, game.player(game.active_player()), game) @@ -81,7 +83,15 @@ impl AiActions { )] } else { base_actions(self, game) + }; + for (t, a) in &actions { + assert!( + !a.is_empty(), + "Empty actions for action type: {t:?} - {:?}", + game.events.last().as_ref().expect("event not found") + ); } + actions } } @@ -302,10 +312,6 @@ fn advances(ai_actions: &mut AiActions, p: &Player, game: &Game) -> Vec .iter() .filter_map(|info| { let a = info.advance; - if deny_advance(a) { - return None; - } - if !p.can_advance_free(a, game) { return None; } @@ -324,13 +330,6 @@ fn advances(ai_actions: &mut AiActions, p: &Player, game: &Game) -> Vec .collect() } -fn deny_advance(name: Advance) -> bool { - //todo collect cache doesn't work, because husbandry can only be used once per turn - //correct cache: 1) only store total in cache 2) sort by distance 3) add husbandry flag - - name == Advance::Husbandry -} - fn collect_actions(p: &Player, game: &Game) -> Vec { let collect = available_collect_actions(game, p.index); if collect.is_empty() { @@ -508,7 +507,6 @@ fn responses(event: &PersistentEventState, player: &Player, game: &Game) -> Vec< PersistentEventRequest::SelectAdvance(a) => a .choices .iter() - .filter(|c| !deny_advance(**c)) .map(|c| EventResponse::SelectAdvance(*c)) .collect(), PersistentEventRequest::SelectPlayer(p) => p @@ -573,7 +571,7 @@ fn change_government(p: &Player, c: &ChangeGovernmentRequest, game: &Game) -> Ve .cache .get_governments() .iter() - .find(|g| p.can_advance_in_change_government(g.advances[0].advance, game)) + .find(|g| p.can_advance_ignore_contradicting(g.advances[0].advance, game)) .expect("government not found"); let advances = new diff --git a/server/src/ai_collect.rs b/server/src/ai_collect.rs index d692ed61..cae3ec21 100644 --- a/server/src/ai_collect.rs +++ b/server/src/ai_collect.rs @@ -1,5 +1,4 @@ use crate::ability_initializer::AbilityInitializerSetup; -use crate::advance::Advance; use crate::city::City; use crate::collect::{ CollectInfo, PositionCollection, add_collect, apply_total_collect, @@ -84,6 +83,7 @@ fn pick_resource( if info.max_selection == tiles_used(collected) { return None; } + let city = info.city; let used = collected .iter() @@ -97,6 +97,12 @@ fn pick_resource( .iter() // .sorted_by_key(|(pos, _)| **pos) .filter(|(pos, _)| { + // AI does not husbandry, because husbandry can only be used once per turn + // correct cache: 1) only store total in cache 2) sort by distance 3) add husbandry flag + if pos.distance(city) > 1 { + return false; + } + let u = used .iter() .find_map(|(p, u)| (*p == **pos).then_some(*u)) @@ -135,13 +141,15 @@ pub(crate) fn invalidate_collect_cache() -> Builtin { } pub(crate) fn reset_collect_within_range(player: usize, position: Position, game: &mut Game) { - let is_land = game.map.is_land(position); let p = game.player_mut(player); - let range = if is_land && p.has_advance(Advance::Husbandry) { - 2 - } else { - 1 - }; + let range = 1; + + // husbandry is not used yet by the AI + // if is_land && p.has_advance(Advance::Husbandry) { + // 2 + // } else { + // 1 + // }; for c in &mut p.cities { if c.position.distance(position) <= range { c.possible_collections.clear(); diff --git a/server/src/ai_missions.rs b/server/src/ai_missions.rs index d10504a6..504afbc1 100644 --- a/server/src/ai_missions.rs +++ b/server/src/ai_missions.rs @@ -368,7 +368,7 @@ impl ActiveMissions { let difficulty_factor = ai::difficulty_factor(difficulty); for mission in &missions { let mut game = game.clone(); - game.supports_undo = false; + game.ai_mode = true; let mut players_active_missions = players_active_missions.clone(); players_active_missions[self.player_index] .missions diff --git a/server/src/city.rs b/server/src/city.rs index cb8cfa38..be04e17b 100644 --- a/server/src/city.rs +++ b/server/src/city.rs @@ -13,6 +13,7 @@ use crate::{ position::Position, }; use MoodState::*; +use itertools::Itertools; use num::Zero; #[readonly::make] @@ -279,3 +280,12 @@ pub(crate) fn on_found_city(game: &mut Game, player_index: usize, position: Posi PersistentEventType::FoundCity, ); } + +#[must_use] +pub(crate) fn non_angry_cites(p: &Player) -> Vec { + p.cities + .iter() + .filter(|c| !matches!(c.mood_state, MoodState::Angry)) + .map(|c| c.position) + .collect_vec() +} diff --git a/server/src/combat.rs b/server/src/combat.rs index f1106954..9186cd9f 100644 --- a/server/src/combat.rs +++ b/server/src/combat.rs @@ -537,7 +537,7 @@ pub mod tests { action_log_index: 0, log: Vec::new(), undo_limit: 0, - supports_undo: true, + ai_mode: false, actions_left: 3, successful_cultural_influence: false, round: 1, diff --git a/server/src/construct.rs b/server/src/construct.rs index d43b84cc..f68b904f 100644 --- a/server/src/construct.rs +++ b/server/src/construct.rs @@ -1,3 +1,4 @@ +use crate::advance::{Advance, gain_advance_without_payment}; use crate::city::{City, MoodState}; use crate::city_pieces::Building; use crate::consts::MAX_CITY_PIECES; @@ -115,17 +116,39 @@ pub(crate) fn construct(game: &mut Game, player_index: usize, c: &Construct) -> cost.activate_city, ); cost.pay(game, &c.payment); - on_construct(game, player_index, c.city_piece); + on_construct(game, player_index, ConstructInfo::new(c.city_piece)); Ok(()) } -pub(crate) fn on_construct(game: &mut Game, player_index: usize, building: Building) { - let _ = game.trigger_persistent_event( +#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug)] +pub struct ConstructInfo { + pub building: Building, + #[serde(default)] + #[serde(skip_serializing_if = "Option::is_none")] + pub gained_advance: Option, +} + +impl ConstructInfo { + #[must_use] + pub fn new(building: Building) -> Self { + Self { + building, + gained_advance: None, + } + } +} + +pub(crate) fn on_construct(game: &mut Game, player_index: usize, info: ConstructInfo) { + if let Some(i) = game.trigger_persistent_event( &[player_index], |e| &mut e.construct, - building, + info, PersistentEventType::Construct, - ); + ) { + if let Some(advance) = i.gained_advance { + gain_advance_without_payment(game, advance, player_index, ResourcePile::empty(), true); + } + } } #[must_use] diff --git a/server/src/content/advances/education.rs b/server/src/content/advances/education.rs index 7d0b84f7..510f800a 100644 --- a/server/src/content/advances/education.rs +++ b/server/src/content/advances/education.rs @@ -5,7 +5,7 @@ use crate::advance::{Advance, AdvanceBuilder, AdvanceInfo}; use crate::city_pieces::Building; use crate::content::advances::{AdvanceGroup, advance_group_builder}; use crate::content::persistent_events::PaymentRequest; -use crate::objective_card::gain_objective_card_from_pile; +use crate::objective_card::draw_and_log_objective_card_from_pile; use crate::payment::PaymentOptions; use crate::resource_pile::ResourcePile; @@ -31,13 +31,16 @@ fn writing() -> AdvanceBuilder { .with_unlocked_building(Building::Academy) .add_one_time_ability_initializer(|game, player_index| { gain_action_card_from_pile(game, player_index); - gain_objective_card_from_pile(game, player_index); + // can't gain objective card directly, because the "combat_end" listener might + // currently being processed ("teach us now") + game.player_mut(player_index).gained_objective = + draw_and_log_objective_card_from_pile(game, player_index); }) .add_simple_persistent_event_listener( |event| &mut event.construct, 3, |game, player_index, _player_name, b| { - if matches!(b, Building::Academy) { + if matches!(b.building, Building::Academy) { game.players[player_index].gain_resources(ResourcePile::ideas(2)); game.add_info_log_item("Academy gained 2 ideas"); } diff --git a/server/src/content/advances/science.rs b/server/src/content/advances/science.rs index 15a5ef0b..c8fee21f 100644 --- a/server/src/content/advances/science.rs +++ b/server/src/content/advances/science.rs @@ -35,7 +35,7 @@ fn math() -> AdvanceBuilder { |event| &mut event.construct, 4, |game, player_index, _player_name, b| { - if matches!(b, Building::Observatory) { + if matches!(b.building, Building::Observatory) { gain_action_card_from_pile(game, player_index); game.add_info_log_item("Observatory gained 1 action card"); } diff --git a/server/src/content/advances/spirituality.rs b/server/src/content/advances/spirituality.rs index 1ca8ab20..f197ee53 100644 --- a/server/src/content/advances/spirituality.rs +++ b/server/src/content/advances/spirituality.rs @@ -29,7 +29,7 @@ fn myths() -> AdvanceBuilder { |event| &mut event.construct, 1, |_game, _player_index, building| { - if matches!(building, Temple) { + if matches!(building.building, Temple) { return Some(ResourceRewardRequest::new( PaymentOptions::sum(1, &[MoodTokens, CultureTokens]), "Select Temple bonus".to_string(), diff --git a/server/src/content/advances/theocracy.rs b/server/src/content/advances/theocracy.rs index 2e603380..8be2ee2c 100644 --- a/server/src/content/advances/theocracy.rs +++ b/server/src/content/advances/theocracy.rs @@ -1,5 +1,5 @@ use crate::ability_initializer::AbilityInitializerSetup; -use crate::advance::{Advance, AdvanceBuilder, AdvanceInfo, gain_advance_without_payment}; +use crate::advance::{Advance, AdvanceBuilder, AdvanceInfo}; use crate::city_pieces::Building::Temple; use crate::consts::STACK_LIMIT; use crate::content::advances::{AdvanceGroup, advance_group_builder}; @@ -21,8 +21,8 @@ fn dogma() -> AdvanceBuilder { Advance::Dogma, "Dogma", "Whenever you Construct a new Temple, \ - you may immediately get a Theocracy Advance for free, \ - You are now limited to a maximum of 2 ideas (discard if necessary) \ + you may immediately get a Theocracy Advance for free. \ + You are now limited to a maximum of 2 ideas (discard if necessary). \ Note: Dogma Advance does not apply when you conquer a city with a Temple.", ) .add_one_time_ability_initializer(|game, player_index| { @@ -41,7 +41,7 @@ fn dogma() -> AdvanceBuilder { |event| &mut event.construct, 0, |game, player_index, building| { - if matches!(building, Temple) { + if matches!(building.building, Temple) { let player = game.player(player_index); let choices: Vec = game .cache @@ -58,7 +58,7 @@ fn dogma() -> AdvanceBuilder { } None }, - |game, c, _| { + |game, c, i| { let verb = if c.actively_selected { "selected" } else { @@ -69,13 +69,9 @@ fn dogma() -> AdvanceBuilder { c.player_name, c.choice.name(game) )); - gain_advance_without_payment( - game, - c.choice, - c.player_index, - ResourcePile::empty(), - true, - ); + // the advance may trigger the Anarchy incident, which will remove Dogma + // this needs to happen after the Dogma listener is processed + i.gained_advance = Some(c.choice); }, ) } diff --git a/server/src/content/incidents/civil_war.rs b/server/src/content/incidents/civil_war.rs index 8b57f5b6..ec9281f5 100644 --- a/server/src/content/incidents/civil_war.rs +++ b/server/src/content/incidents/civil_war.rs @@ -1,3 +1,4 @@ +use crate::city; use crate::city::MoodState; use crate::content::effects::PermanentEffect; use crate::content::incidents::famine::kill_incident_units; @@ -5,7 +6,7 @@ use crate::content::incidents::good_year::select_player_to_gain_settler; use crate::content::persistent_events::{PaymentRequest, PositionRequest, UnitsRequest}; use crate::game::Game; use crate::incident::{ - Incident, IncidentBaseEffect, IncidentBuilder, MoodModifier, decrease_mod_and_log, + DecreaseMood, Incident, IncidentBaseEffect, IncidentBuilder, MoodModifier, decrease_mod_and_log, }; use crate::payment::{PaymentConversion, PaymentConversionType, PaymentOptions}; use crate::player::Player; @@ -43,19 +44,11 @@ fn migration(id: u8) -> Incident { .add_decrease_mood( IncidentTarget::ActivePlayer, MoodModifier::Decrease, - |p, _game, _| (non_angry_cites(p), 1), + |p, _game, _| DecreaseMood::new(city::non_angry_cites(p), 1), ) .build() } -pub(crate) fn non_angry_cites(p: &Player) -> Vec { - p.cities - .iter() - .filter(|c| !matches!(c.mood_state, MoodState::Angry)) - .map(|c| c.position) - .collect_vec() -} - fn civil_war(id: u8) -> Incident { Incident::builder( id, @@ -70,9 +63,9 @@ fn civil_war(id: u8) -> Incident { MoodModifier::Decrease, |p, _game, _| { if non_happy_cites_with_infantry(p).is_empty() { - (non_angry_cites(p), 1) + DecreaseMood::new(city::non_angry_cites(p), 1) } else { - (vec![], 0) + DecreaseMood::none() } }, ) @@ -81,7 +74,7 @@ fn civil_war(id: u8) -> Incident { 0, |game, player_index, i| { let p = game.player(player_index); - let suffix = if !non_angry_cites(p).is_empty() && i.player.payment.is_empty() { + let suffix = if !city::non_angry_cites(p).is_empty() && i.player.payment.is_empty() { " and decrease the mood" } else { "" diff --git a/server/src/content/incidents/earthquake.rs b/server/src/content/incidents/earthquake.rs index 3049d999..151f8593 100644 --- a/server/src/content/incidents/earthquake.rs +++ b/server/src/content/incidents/earthquake.rs @@ -6,7 +6,7 @@ use crate::content::persistent_events::{ PositionRequest, SelectedStructure, Structure, StructuresRequest, is_selected_structures_valid, }; use crate::game::Game; -use crate::incident::{Incident, IncidentBaseEffect, MoodModifier}; +use crate::incident::{DecreaseMood, Incident, IncidentBaseEffect, MoodModifier}; use crate::player_events::{IncidentInfo, IncidentTarget}; use crate::position::Position; use itertools::Itertools; @@ -99,7 +99,7 @@ fn earthquake(id: u8, name: &str, target: IncidentTarget) -> Incident { MoodModifier::Decrease, move |_p, _game, i| { let c = &i.player.must_reduce_mood; - (c.clone(), c.len() as u8) + DecreaseMood::new(c.clone(), c.len() as u8) }, ) .build() @@ -235,7 +235,7 @@ fn flood(id: u8, name: &str, target: IncidentTarget) -> Incident { IncidentBaseEffect::None, ) .add_decrease_mood(target, MoodModifier::Decrease, |p, game, _| { - (non_angry_shore_cites(game, p.index), 1) + DecreaseMood::new(non_angry_shore_cites(game, p.index), 1) }) .build() } diff --git a/server/src/content/incidents/famine.rs b/server/src/content/incidents/famine.rs index c1f0da6f..7b6157d5 100644 --- a/server/src/content/incidents/famine.rs +++ b/server/src/content/incidents/famine.rs @@ -1,12 +1,12 @@ use crate::ability_initializer::{AbilityInitializerSetup, SelectedChoice}; use crate::advance::Advance; +use crate::city::non_angry_cites; use crate::city::{City, MoodState}; use crate::content::builtin::Builtin; use crate::content::effects::PermanentEffect; -use crate::content::incidents::civil_war::non_angry_cites; use crate::content::persistent_events::UnitsRequest; use crate::game::Game; -use crate::incident::{Incident, IncidentBaseEffect, MoodModifier}; +use crate::incident::{DecreaseMood, Incident, IncidentBaseEffect, MoodModifier}; use crate::player::Player; use crate::player_events::IncidentTarget; use crate::playing_actions::PlayingActionType; @@ -37,18 +37,19 @@ fn pestilence() -> Incident { .add_decrease_mood( IncidentTarget::AllPlayers, MoodModifier::Decrease, - move |p, _game, i| { + move |p, _game, _| { if !pestilence_applies(p) { - return (vec![], 0); + return DecreaseMood::none(); } - let needed = if additional_sanitation_damage(p) { - 2 - } else { - 1 - } - i.player.payment.amount(); - - (non_angry_cites(p), needed) + DecreaseMood::new( + non_angry_cites(p), + if additional_sanitation_damage(p) { + 2 + } else { + 1 + }, + ) }, ) .add_simple_incident_listener(IncidentTarget::ActivePlayer, 0, |game, _, _, _| { @@ -221,9 +222,9 @@ pub(crate) fn famine( }) .add_decrease_mood(target, MoodModifier::MakeAngry, move |p, game, i| { if player_pred2(p) && i.player.payment.is_empty() { - (famine_targets(p, game, city_pred2.clone()), 1) + DecreaseMood::new(famine_targets(p, game, city_pred2.clone()), 1) } else { - (vec![], 0) + DecreaseMood::none() } }) .build() diff --git a/server/src/content/incidents/pandemics.rs b/server/src/content/incidents/pandemics.rs index beb6899a..89544b13 100644 --- a/server/src/content/incidents/pandemics.rs +++ b/server/src/content/incidents/pandemics.rs @@ -9,7 +9,7 @@ use crate::content::persistent_events::{ HandCardsRequest, PaymentRequest, PositionRequest, UnitsRequest, }; use crate::game::Game; -use crate::incident::{Incident, IncidentBaseEffect, MoodModifier}; +use crate::incident::{DecreaseMood, Incident, IncidentBaseEffect, MoodModifier}; use crate::map::{Map, Terrain}; use crate::objective_card::discard_objective_card; use crate::payment::PaymentOptions; @@ -282,7 +282,7 @@ fn fire() -> Incident { |p, game, i| { let b = burning_cities(p, game, i); let a = b.len() as u8; - (b, a) + DecreaseMood::new(b, a) }, ) .build() diff --git a/server/src/content/persistent_events.rs b/server/src/content/persistent_events.rs index ec59e451..f464db66 100644 --- a/server/src/content/persistent_events.rs +++ b/server/src/content/persistent_events.rs @@ -7,6 +7,7 @@ use crate::collect::CollectInfo; use crate::combat::Combat; use crate::combat_listeners::{CombatEnd, CombatRoundEnd, CombatRoundStart}; use crate::combat_stats::CombatStats; +use crate::construct::ConstructInfo; use crate::content::custom_actions::CustomEventAction; use crate::events::EventOrigin; use crate::explore::ExploreResolutionState; @@ -106,7 +107,7 @@ pub enum PersistentEventType { StatusPhase(StatusPhaseState), TurnStart, Advance(OnAdvanceInfo), - Construct(Building), + Construct(ConstructInfo), Recruit(Recruit), FoundCity(Position), Incident(IncidentInfo), diff --git a/server/src/events.rs b/server/src/events.rs index 65915acc..af7dceab 100644 --- a/server/src/events.rs +++ b/server/src/events.rs @@ -163,6 +163,7 @@ where } pub struct Event { + pub name: String, pub inner: Option>, } @@ -174,6 +175,7 @@ impl Event { W: Clone + PartialEq, { Self { + name: name.to_string(), inner: Some(EventMut::new(name)), } } diff --git a/server/src/game.rs b/server/src/game.rs index d89624c0..a9fe02f3 100644 --- a/server/src/game.rs +++ b/server/src/game.rs @@ -48,7 +48,7 @@ pub struct Game { pub action_log_index: usize, pub log: Vec>, pub undo_limit: usize, - pub supports_undo: bool, // if false: optimizend AI mode + pub ai_mode: bool, pub actions_left: u32, pub successful_cultural_influence: bool, pub round: u32, // starts at 1 @@ -68,7 +68,7 @@ pub struct Game { impl Clone for Game { fn clone(&self) -> Self { let mut game = Self::from_data(self.cloned_data(), self.cache.clone()); - game.supports_undo = self.supports_undo; + game.ai_mode = self.ai_mode; game } } @@ -100,7 +100,7 @@ impl Game { action_log_index: data.action_log_index, log: data.log, undo_limit: data.undo_limit, - supports_undo: true, + ai_mode: false, round: data.round, age: data.age, messages: data.messages, @@ -225,7 +225,7 @@ impl Game { } pub(crate) fn lock_undo(&mut self) { - if self.supports_undo { + if !self.ai_mode { self.undo_limit = self.action_log_index; current_player_turn_log_mut(self).clear_undo(); } @@ -406,21 +406,21 @@ impl Game { #[must_use] pub(crate) fn execute_cost_trigger(&self) -> CostTrigger { - if self.supports_undo { - CostTrigger::WithModifiers - } else { + if self.ai_mode { CostTrigger::NoModifiers + } else { + CostTrigger::WithModifiers } } #[must_use] pub fn can_undo(&self) -> bool { - self.supports_undo && self.undo_limit < self.action_log_index + !self.ai_mode && self.undo_limit < self.action_log_index } #[must_use] pub fn can_redo(&self) -> bool { - self.supports_undo && self.action_log_index < current_player_turn_log(self).items.len() + !self.ai_mode && self.action_log_index < current_player_turn_log(self).items.len() } pub(crate) fn is_pirate_zone(&self, position: Position) -> bool { diff --git a/server/src/game_setup.rs b/server/src/game_setup.rs index 501f2dcc..e5025430 100644 --- a/server/src/game_setup.rs +++ b/server/src/game_setup.rs @@ -82,7 +82,7 @@ pub fn setup_game(player_amount: usize, seed: String, setup: bool) -> Game { .map(|s| vec![s.clone()]) .collect(), undo_limit: 0, - supports_undo: true, + ai_mode: false, actions_left: ACTIONS, successful_cultural_influence: false, round: 1, diff --git a/server/src/incident.rs b/server/src/incident.rs index a37cfc62..d3ba2508 100644 --- a/server/src/incident.rs +++ b/server/src/incident.rs @@ -130,6 +130,29 @@ pub(crate) enum MoodModifier { MakeAngry, } +pub(crate) struct DecreaseMood { + pub choices: Vec, + pub needed: u8, +} + +impl DecreaseMood { + #[must_use] + pub fn new(possible: Vec, needed: u8) -> Self { + Self { + needed: needed.min(possible.len() as u8), + choices: possible, + } + } + + #[must_use] + pub fn none() -> Self { + Self { + choices: vec![], + needed: 0, + } + } +} + pub struct IncidentBuilder { id: u8, pub name: String, @@ -463,14 +486,10 @@ impl IncidentBuilder { self, target: IncidentTarget, mood_modifier: MoodModifier, - cities: impl Fn(&Player, &Game, &IncidentInfo) -> (Vec, u8) - + 'static - + Clone - + Sync - + Send, + cities: impl Fn(&Player, &Game, &IncidentInfo) -> DecreaseMood + 'static + Clone + Sync + Send, ) -> Self { let cities2 = cities.clone(); - self.add_myths_payment(target, mood_modifier, move |g, p, i| cities(p, g, i).1) + self.add_myths_payment(target, mood_modifier, move |g, p, i| cities(p, g, i).needed) .decrease_mood(target, mood_modifier, cities2) } @@ -526,17 +545,14 @@ impl IncidentBuilder { self, target: IncidentTarget, mood_modifier: MoodModifier, - cities: impl Fn(&Player, &Game, &IncidentInfo) -> (Vec, u8) - + 'static - + Clone - + Sync - + Send, + cities: impl Fn(&Player, &Game, &IncidentInfo) -> DecreaseMood + 'static + Clone + Sync + Send, ) -> Self { self.add_incident_position_request( target, 9, move |game, p, i| { - let (cities, mut needed) = cities(game.player(p), game, i); + let d = cities(game.player(p), game, i); + let mut needed = d.needed; needed -= i.player.myths_payment; let action = match mood_modifier { @@ -546,7 +562,7 @@ impl IncidentBuilder { let needed1 = needed..=needed; let description = &format!("Select a city to {action}"); - Some(PositionRequest::new(cities, needed1, description)) + Some(PositionRequest::new(d.choices, needed1, description)) }, move |game, s, _| { decrease_mod_and_log(game, s, mood_modifier); diff --git a/server/src/objective_card.rs b/server/src/objective_card.rs index 553b6162..2a6de96f 100644 --- a/server/src/objective_card.rs +++ b/server/src/objective_card.rs @@ -390,13 +390,20 @@ fn filter_duplicated_objectives( } pub(crate) fn gain_objective_card_from_pile(game: &mut Game, player: usize) { - if let Some(c) = draw_objective_card_from_pile(game) { + if let Some(c) = draw_and_log_objective_card_from_pile(game, player) { + gain_objective_card(game, player, c); + } +} + +pub(crate) fn draw_and_log_objective_card_from_pile(game: &mut Game, player: usize) -> Option { + let card = draw_objective_card_from_pile(game); + if card.is_some() { game.add_info_log_item(&format!( "{} gained an objective card from the pile", game.player_name(player) )); - gain_objective_card(game, player, c); } + card } fn draw_objective_card_from_pile(game: &mut Game) -> Option { diff --git a/server/src/player.rs b/server/src/player.rs index 48819bfe..95aad752 100644 --- a/server/src/player.rs +++ b/server/src/player.rs @@ -74,6 +74,7 @@ pub struct Player { pub event_info: HashMap, pub secrets: Vec, pub(crate) objective_opportunities: Vec, // transient + pub(crate) gained_objective: Option, // transient } impl Clone for Player { @@ -182,6 +183,7 @@ impl Player { event_info: data.event_info, secrets: data.secrets, objective_opportunities: Vec::new(), + gained_objective: None, } } @@ -308,6 +310,7 @@ impl Player { event_info: HashMap::new(), secrets: Vec::new(), objective_opportunities: Vec::new(), + gained_objective: None, } } @@ -439,7 +442,7 @@ impl Player { } #[must_use] - pub fn can_advance_in_change_government(&self, advance: Advance, game: &Game) -> bool { + pub fn can_advance_ignore_contradicting(&self, advance: Advance, game: &Game) -> bool { if self.has_advance(advance) { return false; } @@ -453,16 +456,12 @@ impl Player { #[must_use] pub fn can_advance_free(&self, advance: Advance, game: &Game) -> bool { - if self.has_advance(advance) { - return false; - } - for contradicting_advance in &advance.info(game).contradicting { if self.has_advance(*contradicting_advance) { return false; } } - self.can_advance_in_change_government(advance, game) + self.can_advance_ignore_contradicting(advance, game) } #[must_use] diff --git a/server/src/player_events.rs b/server/src/player_events.rs index 21616c1b..759a238b 100644 --- a/server/src/player_events.rs +++ b/server/src/player_events.rs @@ -5,6 +5,7 @@ use crate::collect::{CollectContext, CollectInfo}; use crate::combat::Combat; use crate::combat_listeners::{CombatEnd, CombatRoundEnd, CombatRoundStart}; use crate::combat_stats::CombatStats; +use crate::construct::ConstructInfo; use crate::content::custom_actions::CustomEventAction; use crate::content::persistent_events::KilledUnits; use crate::cultural_influence::{InfluenceCultureInfo, InfluenceCultureOutcome}; @@ -85,7 +86,7 @@ impl TransientEvents { pub(crate) struct PersistentEvents { pub collect: PersistentEvent, - pub construct: PersistentEvent, + pub construct: PersistentEvent, pub draw_wonder_card: PersistentEvent, pub advance: PersistentEvent, pub recruit: PersistentEvent, diff --git a/server/src/status_phase.rs b/server/src/status_phase.rs index 5555edca..bbe9db79 100644 --- a/server/src/status_phase.rs +++ b/server/src/status_phase.rs @@ -305,7 +305,7 @@ fn change_government_type(game: &mut Game, player_index: usize, new_government: let a = game.cache.get_government(government); assert!( game.player(player_index) - .can_advance_in_change_government(a.advances[0].advance, game), + .can_advance_ignore_contradicting(a.advances[0].advance, game), "Cannot advance in change government" ); @@ -364,7 +364,7 @@ pub(crate) fn can_change_government_for_free(player: &Player, game: &Game) -> bo player.government(game).is_some_and(|government| { game.cache.get_governments().iter().any(|g| { g.government != Some(government.clone()) - && player.can_advance_in_change_government(g.advances[0].advance, game) + && player.can_advance_ignore_contradicting(g.advances[0].advance, game) }) }) } diff --git a/server/tests/action_card_tests.rs b/server/tests/action_card_tests.rs index 19a354fd..5e879be3 100644 --- a/server/tests/action_card_tests.rs +++ b/server/tests/action_card_tests.rs @@ -384,7 +384,7 @@ fn test_teach_us() { move_action(vec![0, 1, 2, 3, 4, 5], Position::from_offset("C1")), ) .without_json_comparison(), - TestAction::undoable( + TestAction::not_undoable( 0, Action::Response(EventResponse::SelectHandCards(vec![HandCard::ActionCard( 35, diff --git a/server/tests/advances_tests.rs b/server/tests/advances_tests.rs index be67466a..e33def10 100644 --- a/server/tests/advances_tests.rs +++ b/server/tests/advances_tests.rs @@ -505,7 +505,7 @@ fn test_trade_routes_with_currency() { } #[test] -fn test_dogma() { +fn test_dogma_with_anarchy() { JSON.test( "dogma", vec![ @@ -515,7 +515,8 @@ fn test_dogma() { advance: advance::Advance::Dogma, payment: ResourcePile::ideas(2), }), - ), + ) + .without_json_comparison(), TestAction::undoable( 1, Action::Playing(Construct(construct::Construct::new( @@ -523,14 +524,16 @@ fn test_dogma() { Temple, ResourcePile::new(0, 1, 1, 0, 0, 0, 0), ))), - ), + ) + .without_json_comparison(), TestAction::undoable( 1, Action::Response(EventResponse::ResourceReward(ResourcePile::culture_tokens( 1, ))), - ), - TestAction::undoable( + ) + .without_json_comparison(), + TestAction::not_undoable( 1, Action::Response(EventResponse::SelectAdvance(advance::Advance::Fanaticism)), ), diff --git a/server/tests/ai_tests.rs b/server/tests/ai_tests.rs index 0d0af417..9992297e 100644 --- a/server/tests/ai_tests.rs +++ b/server/tests/ai_tests.rs @@ -46,7 +46,7 @@ fn all_actions() { matches!(t, ActionType::Playing(PlayingActionType::Advance)) }) .unwrap(); - assert_eq!(advances.len(), 12); + assert_eq!(advances.len(), 13); assert_eq!( all, diff --git a/server/tests/random_actions.rs b/server/tests/random_actions.rs index e77caecb..05de17fc 100644 --- a/server/tests/random_actions.rs +++ b/server/tests/random_actions.rs @@ -42,7 +42,7 @@ fn test_random_actions() { fn random_actions_iterations(mut rng: Rng) { let seed = rng.range(0, 10_usize.pow(15)).to_string(); let mut game = game_setup::setup_game(2, seed, true); - game.supports_undo = false; + game.ai_mode = true; let mut ai_actions = AiActions::new(); loop { if matches!(game.state, GameState::Finished) { diff --git a/server/tests/test_games/action_cards/teach_us.json b/server/tests/test_games/action_cards/teach_us.json index a509899d..be3d1fc4 100644 --- a/server/tests/test_games/action_cards/teach_us.json +++ b/server/tests/test_games/action_cards/teach_us.json @@ -135,8 +135,8 @@ "Fanaticism", "Farming", "Mining", - "Storage", - "Tactics" + "Tactics", + "Writing" ], "incident_tokens": 3, "next_unit_id": 2 @@ -226,5 +226,11 @@ ], "wonders_left": [ "Pyramids" + ], + "action_cards_left": [ + 1 + ], + "objective_cards_left": [ + 1 ] } \ No newline at end of file diff --git a/server/tests/test_games/action_cards/teach_us.outcome1.json b/server/tests/test_games/action_cards/teach_us.outcome1.json index 003cec82..48f826fd 100644 --- a/server/tests/test_games/action_cards/teach_us.outcome1.json +++ b/server/tests/test_games/action_cards/teach_us.outcome1.json @@ -9,11 +9,11 @@ "ore": 7, "ideas": 3, "gold": 7, - "mood_tokens": 8, - "culture_tokens": 7 + "mood_tokens": 7, + "culture_tokens": 8 }, "resource_limit": { - "food": 7, + "food": 2, "wood": 7, "ore": 7, "ideas": 7, @@ -96,10 +96,16 @@ "advances": [ "Farming", "Mining", - "Storage", - "Tactics" + "Tactics", + "Writing" ], "incident_tokens": 2, + "action_cards": [ + 1 + ], + "objective_cards": [ + 1 + ], "next_unit_id": 8 }, { @@ -127,8 +133,8 @@ "Fanaticism", "Farming", "Mining", - "Storage", - "Tactics" + "Tactics", + "Writing" ], "incident_tokens": 3, "next_unit_id": 2 @@ -241,109 +247,6 @@ ] } }, - "undo": [ - { - "op": "add", - "path": "/events", - "value": [ - { - "event_type": { - "CombatEnd": { - "combat": { - "attacker": 0, - "attacker_position": "C2", - "attackers": [ - 0, - 1, - 2, - 3, - 4, - 5 - ], - "defender": 1, - "defender_position": "C1", - "retreat": "CanRetreat", - "round": 1, - "stats": { - "attacker": { - "player": 0, - "present": { - "cavalry": 1, - "elephants": 1, - "infantry": 1, - "leaders": 1, - "settlers": 2 - } - }, - "battleground": "City", - "defender": { - "losses": { - "infantry": 2 - }, - "player": 1, - "present": { - "infantry": 2 - } - }, - "position": "C1", - "result": "AttackerWins" - } - }, - "result": "AttackerWins" - } - }, - "handler": { - "origin": { - "Builtin": "Teach us" - }, - "priority": 91, - "request": { - "SelectHandCards": { - "choices": [ - { - "ActionCard": 35 - } - ], - "description": "Select Teach Us card", - "needed": { - "end": 1, - "start": 0 - } - } - } - }, - "last_priority_used": 91, - "player": 0 - } - ] - }, - { - "op": "add", - "path": "/players/0/action_cards", - "value": [ - 35 - ] - }, - { - "op": "replace", - "path": "/players/0/advances/2", - "value": "Tactics" - }, - { - "op": "remove", - "path": "/players/0/advances/3" - }, - { - "op": "replace", - "path": "/players/0/resource_limit/food", - "value": 2 - }, - { - "op": "replace", - "path": "/players/0/resources/mood_tokens", - "value": 7 - } - ], "combat_stats": { "position": "C1", "battleground": "City", @@ -394,11 +297,13 @@ ], [ "Player1 selected to use Teach Us.", - "Player1 selected Storage as advance for Teach Us.", - "Player gained 1 mood token as advance bonus" + "Player1 selected Writing as advance for Teach Us.", + "Player1 gained an action card from the pile", + "Player1 gained an objective card from the pile", + "Player gained 1 culture token as advance bonus" ] ], - "undo_limit": 1, + "undo_limit": 2, "actions_left": 3, "round": 2, "age": 1, @@ -421,4 +326,4 @@ "wonders_left": [ "Pyramids" ] -} \ No newline at end of file +} diff --git a/server/tests/test_games/advances/dogma.json b/server/tests/test_games/advances/dogma.json index 4a62a8a1..bdf36d78 100644 --- a/server/tests/test_games/advances/dogma.json +++ b/server/tests/test_games/advances/dogma.json @@ -181,7 +181,7 @@ "Myths", "StateReligion" ], - "incident_tokens": 3, + "incident_tokens": 2, "next_unit_id": 2 }, { @@ -313,5 +313,8 @@ "rng": "46312381643103681595563341886777350953", "wonders_left": [ "Pyramids" + ], + "incidents_left": [ + 44 ] } \ No newline at end of file diff --git a/server/tests/test_games/advances/dogma.outcome.json b/server/tests/test_games/advances/dogma.outcome.json deleted file mode 100644 index 9ecb80cc..00000000 --- a/server/tests/test_games/advances/dogma.outcome.json +++ /dev/null @@ -1,388 +0,0 @@ -{ - "state": "Playing", - "players": [ - { - "id": 0, - "resources": { - "food": 7, - "wood": 5, - "ore": 5, - "ideas": 1, - "gold": 5, - "mood_tokens": 12, - "culture_tokens": 10 - }, - "resource_limit": { - "food": 7, - "wood": 7, - "ore": 7, - "ideas": 7, - "gold": 7 - }, - "cities": [ - { - "city_pieces": { - "market": 1 - }, - "mood_state": "Happy", - "position": "A1" - }, - { - "city_pieces": { - "academy": 1, - "port": 1 - }, - "mood_state": "Angry", - "position": "C2", - "port_position": "C3" - }, - { - "city_pieces": { - "obelisk": 1, - "observatory": 1, - "fortress": 1, - "temple": 1 - }, - "mood_state": "Neutral", - "position": "B1" - }, - { - "city_pieces": {}, - "mood_state": "Angry", - "position": "B3" - } - ], - "units": [ - { - "position": "C2", - "unit_type": "Infantry", - "id": 0 - }, - { - "position": "B3", - "unit_type": "Settler", - "id": 3 - }, - { - "position": "B3", - "unit_type": "Settler", - "id": 4 - }, - { - "position": "B3", - "unit_type": "Settler", - "id": 5 - }, - { - "position": "B3", - "unit_type": "Settler", - "id": 6 - }, - { - "position": "C3", - "unit_type": "Ship", - "id": 7, - "carried_units": [ - { - "unit_type": "Cavalry", - "id": 1 - }, - { - "unit_type": "Elephant", - "id": 2 - } - ] - }, - { - "position": "C3", - "unit_type": "Ship", - "id": 8 - }, - { - "position": "C3", - "unit_type": "Ship", - "id": 9 - } - ], - "civilization": "Maya", - "available_leaders": [ - "Kʼinich Janaab Pakal I" - ], - "advances": [ - "Farming", - "Fishing", - "FreeEconomy", - "FreeEducation", - "Mining", - "Storage", - "Voting", - "Writing" - ], - "incident_tokens": 3, - "wonder_cards": [ - "Great Gardens" - ], - "next_unit_id": 10 - }, - { - "id": 1, - "resources": { - "food": 2, - "wood": 5, - "ore": 5, - "ideas": 2, - "gold": 5, - "mood_tokens": 9, - "culture_tokens": 9 - }, - "resource_limit": { - "food": 2, - "wood": 7, - "ore": 7, - "ideas": 2, - "gold": 7 - }, - "cities": [ - { - "city_pieces": {}, - "mood_state": "Happy", - "position": "C1" - }, - { - "city_pieces": { - "port": 1 - }, - "mood_state": "Neutral", - "position": "B2", - "port_position": "C3" - } - ], - "units": [ - { - "position": "C1", - "unit_type": "Infantry", - "id": 0 - }, - { - "position": "C1", - "unit_type": "Infantry", - "id": 1 - } - ], - "civilization": "test0", - "available_leaders": [ - "Alexander", - "Kleopatra" - ], - "advances": [ - "Dogma", - "Farming", - "Fishing", - "Mining", - "Myths", - "StateReligion" - ], - "incident_tokens": 2, - "next_unit_id": 2 - }, - { - "id": 2, - "civilization": "Barbarians", - "next_unit_id": 0 - }, - { - "id": 3, - "civilization": "Pirates", - "next_unit_id": 0 - } - ], - "map": { - "tiles": [ - [ - "A1", - "Fertile" - ], - [ - "A2", - "Water" - ], - [ - "A3", - { - "Exhausted": "Forest" - } - ], - [ - "A4", - "Mountain" - ], - [ - "B1", - "Mountain" - ], - [ - "B2", - "Forest" - ], - [ - "B3", - "Fertile" - ], - [ - "B4", - "Fertile" - ], - [ - "B5", - "Fertile" - ], - [ - "B6", - "Fertile" - ], - [ - "C1", - "Barren" - ], - [ - "C2", - "Forest" - ], - [ - "C3", - "Water" - ], - [ - "C4", - "Water" - ], - [ - "C5", - "Water" - ], - [ - "D1", - "Fertile" - ], - [ - "D2", - "Water" - ], - [ - "E2", - "Fertile" - ] - ] - }, - "starting_player_index": 1, - "current_player_index": 1, - "action_log": [ - { - "rounds": [ - { - "players": [ - { - "index": 0, - "items": [ - { - "action": { - "Playing": { - "Advance": { - "advance": "Dogma", - "payment": { - "ideas": 2 - } - } - } - }, - "undo": [ - { - "op": "replace", - "path": "/actions_left", - "value": 3 - }, - { - "op": "replace", - "path": "/players/1/advances/0", - "value": "Farming" - }, - { - "op": "replace", - "path": "/players/1/advances/1", - "value": "Fishing" - }, - { - "op": "replace", - "path": "/players/1/advances/2", - "value": "Mining" - }, - { - "op": "replace", - "path": "/players/1/advances/3", - "value": "Myths" - }, - { - "op": "replace", - "path": "/players/1/advances/4", - "value": "StateReligion" - }, - { - "op": "remove", - "path": "/players/1/advances/5" - }, - { - "op": "replace", - "path": "/players/1/incident_tokens", - "value": 3 - }, - { - "op": "replace", - "path": "/players/1/resource_limit/ideas", - "value": 7 - }, - { - "op": "replace", - "path": "/players/1/resources/ideas", - "value": 6 - } - ] - } - ] - } - ] - } - ] - } - ], - "action_log_index": 1, - "log": [ - [ - "Player2 paid 2 ideas to get the Dogma advance", - "Player2 is now limited to a maximum of 2 ideas for Dogma Advance", - "Player2 could not store 2 ideas" - ] - ], - "undo_limit": 0, - "actions_left": 2, - "round": 1, - "age": 2, - "messages": [ - "The game has started" - ], - "dice_roll_outcomes": [ - 1, - 1, - 10, - 10, - 10, - 10, - 10, - 10, - 10, - 10 - ], - "rng": "46312381643103681595563341886777350953", - "wonders_left": [ - "Pyramids" - ] -} \ No newline at end of file diff --git a/server/tests/test_games/advances/dogma.outcome1.json b/server/tests/test_games/advances/dogma.outcome1.json deleted file mode 100644 index 4fe1ea7d..00000000 --- a/server/tests/test_games/advances/dogma.outcome1.json +++ /dev/null @@ -1,484 +0,0 @@ -{ - "state": "Playing", - "events": [ - { - "event_type": { - "Construct": "Temple" - }, - "player": 1, - "last_priority_used": 1, - "handler": { - "priority": 1, - "request": { - "ResourceReward": { - "reward": { - "default": { - "mood_tokens": 1 - }, - "conversions": [ - { - "from": [ - { - "mood_tokens": 1 - } - ], - "to": { - "culture_tokens": 1 - }, - "type": "Unlimited" - } - ] - }, - "name": "Select Temple bonus" - } - }, - "origin": { - "Advance": "Myths" - } - } - } - ], - "players": [ - { - "id": 0, - "resources": { - "food": 7, - "wood": 5, - "ore": 5, - "ideas": 1, - "gold": 5, - "mood_tokens": 12, - "culture_tokens": 10 - }, - "resource_limit": { - "food": 7, - "wood": 7, - "ore": 7, - "ideas": 7, - "gold": 7 - }, - "cities": [ - { - "city_pieces": { - "market": 1 - }, - "mood_state": "Happy", - "position": "A1" - }, - { - "city_pieces": { - "academy": 1, - "port": 1 - }, - "mood_state": "Angry", - "position": "C2", - "port_position": "C3" - }, - { - "city_pieces": { - "obelisk": 1, - "observatory": 1, - "fortress": 1, - "temple": 1 - }, - "mood_state": "Neutral", - "position": "B1" - }, - { - "city_pieces": {}, - "mood_state": "Angry", - "position": "B3" - } - ], - "units": [ - { - "position": "C2", - "unit_type": "Infantry", - "id": 0 - }, - { - "position": "B3", - "unit_type": "Settler", - "id": 3 - }, - { - "position": "B3", - "unit_type": "Settler", - "id": 4 - }, - { - "position": "B3", - "unit_type": "Settler", - "id": 5 - }, - { - "position": "B3", - "unit_type": "Settler", - "id": 6 - }, - { - "position": "C3", - "unit_type": "Ship", - "id": 7, - "carried_units": [ - { - "unit_type": "Cavalry", - "id": 1 - }, - { - "unit_type": "Elephant", - "id": 2 - } - ] - }, - { - "position": "C3", - "unit_type": "Ship", - "id": 8 - }, - { - "position": "C3", - "unit_type": "Ship", - "id": 9 - } - ], - "civilization": "Maya", - "available_leaders": [ - "Kʼinich Janaab Pakal I" - ], - "advances": [ - "Farming", - "Fishing", - "FreeEconomy", - "FreeEducation", - "Mining", - "Storage", - "Voting", - "Writing" - ], - "incident_tokens": 3, - "wonder_cards": [ - "Great Gardens" - ], - "next_unit_id": 10 - }, - { - "id": 1, - "resources": { - "food": 2, - "wood": 4, - "ore": 4, - "ideas": 2, - "gold": 5, - "mood_tokens": 9, - "culture_tokens": 9 - }, - "resource_limit": { - "food": 2, - "wood": 7, - "ore": 7, - "ideas": 2, - "gold": 7 - }, - "cities": [ - { - "city_pieces": { - "temple": 1 - }, - "mood_state": "Happy", - "activations": 1, - "position": "C1" - }, - { - "city_pieces": { - "port": 1 - }, - "mood_state": "Neutral", - "position": "B2", - "port_position": "C3" - } - ], - "units": [ - { - "position": "C1", - "unit_type": "Infantry", - "id": 0 - }, - { - "position": "C1", - "unit_type": "Infantry", - "id": 1 - } - ], - "civilization": "test0", - "available_leaders": [ - "Alexander", - "Kleopatra" - ], - "advances": [ - "Dogma", - "Farming", - "Fishing", - "Mining", - "Myths", - "StateReligion" - ], - "incident_tokens": 2, - "next_unit_id": 2, - "event_info": { - "StateReligion": "used" - } - }, - { - "id": 2, - "civilization": "Barbarians", - "next_unit_id": 0 - }, - { - "id": 3, - "civilization": "Pirates", - "next_unit_id": 0 - } - ], - "map": { - "tiles": [ - [ - "A1", - "Fertile" - ], - [ - "A2", - "Water" - ], - [ - "A3", - { - "Exhausted": "Forest" - } - ], - [ - "A4", - "Mountain" - ], - [ - "B1", - "Mountain" - ], - [ - "B2", - "Forest" - ], - [ - "B3", - "Fertile" - ], - [ - "B4", - "Fertile" - ], - [ - "B5", - "Fertile" - ], - [ - "B6", - "Fertile" - ], - [ - "C1", - "Barren" - ], - [ - "C2", - "Forest" - ], - [ - "C3", - "Water" - ], - [ - "C4", - "Water" - ], - [ - "C5", - "Water" - ], - [ - "D1", - "Fertile" - ], - [ - "D2", - "Water" - ], - [ - "E2", - "Fertile" - ] - ] - }, - "starting_player_index": 1, - "current_player_index": 1, - "action_log": [ - { - "rounds": [ - { - "players": [ - { - "index": 0, - "items": [ - { - "action": { - "Playing": { - "Advance": { - "advance": "Dogma", - "payment": { - "ideas": 2 - } - } - } - }, - "undo": [ - { - "op": "replace", - "path": "/actions_left", - "value": 3 - }, - { - "op": "replace", - "path": "/players/1/advances/0", - "value": "Farming" - }, - { - "op": "replace", - "path": "/players/1/advances/1", - "value": "Fishing" - }, - { - "op": "replace", - "path": "/players/1/advances/2", - "value": "Mining" - }, - { - "op": "replace", - "path": "/players/1/advances/3", - "value": "Myths" - }, - { - "op": "replace", - "path": "/players/1/advances/4", - "value": "StateReligion" - }, - { - "op": "remove", - "path": "/players/1/advances/5" - }, - { - "op": "replace", - "path": "/players/1/incident_tokens", - "value": 3 - }, - { - "op": "replace", - "path": "/players/1/resource_limit/ideas", - "value": 7 - }, - { - "op": "replace", - "path": "/players/1/resources/ideas", - "value": 6 - } - ] - }, - { - "action": { - "Playing": { - "Construct": { - "city_position": "C1", - "city_piece": "Temple", - "payment": { - "wood": 1, - "ore": 1 - }, - "port_position": null - } - } - }, - "undo": [ - { - "op": "replace", - "path": "/actions_left", - "value": 2 - }, - { - "op": "remove", - "path": "/players/1/cities/0/city_pieces/temple" - }, - { - "op": "remove", - "path": "/players/1/cities/0/activations" - }, - { - "op": "replace", - "path": "/players/1/resources/ore", - "value": 5 - }, - { - "op": "replace", - "path": "/players/1/resources/wood", - "value": 5 - }, - { - "op": "remove", - "path": "/players/1/event_info" - }, - { - "op": "remove", - "path": "/events" - } - ] - } - ] - } - ] - } - ] - } - ], - "action_log_index": 2, - "log": [ - [ - "Player2 paid 2 ideas to get the Dogma advance", - "Player2 is now limited to a maximum of 2 ideas for Dogma Advance", - "Player2 could not store 2 ideas" - ], - [ - "Player2 paid 1 wood and 1 ore to construct a Temple in the city at C1", - "State Religion reduced the food cost to 0" - ] - ], - "undo_limit": 0, - "actions_left": 1, - "round": 1, - "age": 2, - "messages": [ - "The game has started" - ], - "dice_roll_outcomes": [ - 1, - 1, - 10, - 10, - 10, - 10, - 10, - 10, - 10, - 10 - ], - "rng": "46312381643103681595563341886777350953", - "wonders_left": [ - "Pyramids" - ] -} \ No newline at end of file diff --git a/server/tests/test_games/advances/dogma.outcome2.json b/server/tests/test_games/advances/dogma.outcome2.json deleted file mode 100644 index cff99417..00000000 --- a/server/tests/test_games/advances/dogma.outcome2.json +++ /dev/null @@ -1,533 +0,0 @@ -{ - "state": "Playing", - "events": [ - { - "event_type": { - "Construct": "Temple" - }, - "player": 1, - "last_priority_used": 0, - "handler": { - "priority": 0, - "request": { - "SelectAdvance": { - "choices": [ - "Devotion", - "Conversion", - "Fanaticism" - ] - } - }, - "origin": { - "Advance": "Dogma" - } - } - } - ], - "players": [ - { - "id": 0, - "resources": { - "food": 7, - "wood": 5, - "ore": 5, - "ideas": 1, - "gold": 5, - "mood_tokens": 12, - "culture_tokens": 10 - }, - "resource_limit": { - "food": 7, - "wood": 7, - "ore": 7, - "ideas": 7, - "gold": 7 - }, - "cities": [ - { - "city_pieces": { - "market": 1 - }, - "mood_state": "Happy", - "position": "A1" - }, - { - "city_pieces": { - "academy": 1, - "port": 1 - }, - "mood_state": "Angry", - "position": "C2", - "port_position": "C3" - }, - { - "city_pieces": { - "obelisk": 1, - "observatory": 1, - "fortress": 1, - "temple": 1 - }, - "mood_state": "Neutral", - "position": "B1" - }, - { - "city_pieces": {}, - "mood_state": "Angry", - "position": "B3" - } - ], - "units": [ - { - "position": "C2", - "unit_type": "Infantry", - "id": 0 - }, - { - "position": "B3", - "unit_type": "Settler", - "id": 3 - }, - { - "position": "B3", - "unit_type": "Settler", - "id": 4 - }, - { - "position": "B3", - "unit_type": "Settler", - "id": 5 - }, - { - "position": "B3", - "unit_type": "Settler", - "id": 6 - }, - { - "position": "C3", - "unit_type": "Ship", - "id": 7, - "carried_units": [ - { - "unit_type": "Cavalry", - "id": 1 - }, - { - "unit_type": "Elephant", - "id": 2 - } - ] - }, - { - "position": "C3", - "unit_type": "Ship", - "id": 8 - }, - { - "position": "C3", - "unit_type": "Ship", - "id": 9 - } - ], - "civilization": "Maya", - "available_leaders": [ - "Kʼinich Janaab Pakal I" - ], - "advances": [ - "Farming", - "Fishing", - "FreeEconomy", - "FreeEducation", - "Mining", - "Storage", - "Voting", - "Writing" - ], - "incident_tokens": 3, - "wonder_cards": [ - "Great Gardens" - ], - "next_unit_id": 10 - }, - { - "id": 1, - "resources": { - "food": 2, - "wood": 4, - "ore": 4, - "ideas": 2, - "gold": 5, - "mood_tokens": 9, - "culture_tokens": 10 - }, - "resource_limit": { - "food": 2, - "wood": 7, - "ore": 7, - "ideas": 2, - "gold": 7 - }, - "cities": [ - { - "city_pieces": { - "temple": 1 - }, - "mood_state": "Happy", - "activations": 1, - "position": "C1" - }, - { - "city_pieces": { - "port": 1 - }, - "mood_state": "Neutral", - "position": "B2", - "port_position": "C3" - } - ], - "units": [ - { - "position": "C1", - "unit_type": "Infantry", - "id": 0 - }, - { - "position": "C1", - "unit_type": "Infantry", - "id": 1 - } - ], - "civilization": "test0", - "available_leaders": [ - "Alexander", - "Kleopatra" - ], - "advances": [ - "Dogma", - "Farming", - "Fishing", - "Mining", - "Myths", - "StateReligion" - ], - "incident_tokens": 2, - "next_unit_id": 2, - "event_info": { - "StateReligion": "used" - } - }, - { - "id": 2, - "civilization": "Barbarians", - "next_unit_id": 0 - }, - { - "id": 3, - "civilization": "Pirates", - "next_unit_id": 0 - } - ], - "map": { - "tiles": [ - [ - "A1", - "Fertile" - ], - [ - "A2", - "Water" - ], - [ - "A3", - { - "Exhausted": "Forest" - } - ], - [ - "A4", - "Mountain" - ], - [ - "B1", - "Mountain" - ], - [ - "B2", - "Forest" - ], - [ - "B3", - "Fertile" - ], - [ - "B4", - "Fertile" - ], - [ - "B5", - "Fertile" - ], - [ - "B6", - "Fertile" - ], - [ - "C1", - "Barren" - ], - [ - "C2", - "Forest" - ], - [ - "C3", - "Water" - ], - [ - "C4", - "Water" - ], - [ - "C5", - "Water" - ], - [ - "D1", - "Fertile" - ], - [ - "D2", - "Water" - ], - [ - "E2", - "Fertile" - ] - ] - }, - "starting_player_index": 1, - "current_player_index": 1, - "action_log": [ - { - "rounds": [ - { - "players": [ - { - "index": 0, - "items": [ - { - "action": { - "Playing": { - "Advance": { - "advance": "Dogma", - "payment": { - "ideas": 2 - } - } - } - }, - "undo": [ - { - "op": "replace", - "path": "/actions_left", - "value": 3 - }, - { - "op": "replace", - "path": "/players/1/advances/0", - "value": "Farming" - }, - { - "op": "replace", - "path": "/players/1/advances/1", - "value": "Fishing" - }, - { - "op": "replace", - "path": "/players/1/advances/2", - "value": "Mining" - }, - { - "op": "replace", - "path": "/players/1/advances/3", - "value": "Myths" - }, - { - "op": "replace", - "path": "/players/1/advances/4", - "value": "StateReligion" - }, - { - "op": "remove", - "path": "/players/1/advances/5" - }, - { - "op": "replace", - "path": "/players/1/incident_tokens", - "value": 3 - }, - { - "op": "replace", - "path": "/players/1/resource_limit/ideas", - "value": 7 - }, - { - "op": "replace", - "path": "/players/1/resources/ideas", - "value": 6 - } - ] - }, - { - "action": { - "Playing": { - "Construct": { - "city_position": "C1", - "city_piece": "Temple", - "payment": { - "wood": 1, - "ore": 1 - }, - "port_position": null - } - } - }, - "undo": [ - { - "op": "replace", - "path": "/actions_left", - "value": 2 - }, - { - "op": "remove", - "path": "/players/1/cities/0/city_pieces/temple" - }, - { - "op": "remove", - "path": "/players/1/cities/0/activations" - }, - { - "op": "replace", - "path": "/players/1/resources/ore", - "value": 5 - }, - { - "op": "replace", - "path": "/players/1/resources/wood", - "value": 5 - }, - { - "op": "remove", - "path": "/players/1/event_info" - }, - { - "op": "remove", - "path": "/events" - } - ] - }, - { - "action": { - "Response": { - "ResourceReward": { - "culture_tokens": 1 - } - } - }, - "undo": [ - { - "op": "replace", - "path": "/events/0/handler/origin/Advance", - "value": "Myths" - }, - { - "op": "replace", - "path": "/events/0/handler/priority", - "value": 1 - }, - { - "op": "add", - "path": "/events/0/handler/request/ResourceReward", - "value": { - "name": "Select Temple bonus", - "reward": { - "conversions": [ - { - "from": [ - { - "mood_tokens": 1 - } - ], - "to": { - "culture_tokens": 1 - }, - "type": "Unlimited" - } - ], - "default": { - "mood_tokens": 1 - } - } - } - }, - { - "op": "remove", - "path": "/events/0/handler/request/SelectAdvance" - }, - { - "op": "replace", - "path": "/events/0/last_priority_used", - "value": 1 - }, - { - "op": "replace", - "path": "/players/1/resources/culture_tokens", - "value": 9 - } - ] - } - ] - } - ] - } - ] - } - ], - "action_log_index": 3, - "log": [ - [ - "Player2 paid 2 ideas to get the Dogma advance", - "Player2 is now limited to a maximum of 2 ideas for Dogma Advance", - "Player2 could not store 2 ideas" - ], - [ - "Player2 paid 1 wood and 1 ore to construct a Temple in the city at C1", - "State Religion reduced the food cost to 0" - ], - [ - "Player2 selected 1 culture token as a reward for constructing a Temple" - ] - ], - "undo_limit": 0, - "actions_left": 1, - "round": 1, - "age": 2, - "messages": [ - "The game has started" - ], - "dice_roll_outcomes": [ - 1, - 1, - 10, - 10, - 10, - 10, - 10, - 10, - 10, - 10 - ], - "rng": "46312381643103681595563341886777350953", - "wonders_left": [ - "Pyramids" - ] -} \ No newline at end of file diff --git a/server/tests/test_games/advances/dogma.outcome3.json b/server/tests/test_games/advances/dogma.outcome3.json index d7753c0e..81f9eb3e 100644 --- a/server/tests/test_games/advances/dogma.outcome3.json +++ b/server/tests/test_games/advances/dogma.outcome3.json @@ -139,7 +139,7 @@ "food": 2, "wood": 7, "ore": 7, - "ideas": 2, + "ideas": 7, "gold": 7 }, "cities": [ @@ -178,15 +178,14 @@ "Kleopatra" ], "advances": [ - "Dogma", - "Fanaticism", "Farming", "Fishing", "Mining", "Myths", "StateReligion" ], - "incident_tokens": 1, + "incident_tokens": 3, + "event_victory_points": 2.0, "next_unit_id": 2, "event_info": { "StateReligion": "used" @@ -301,58 +300,7 @@ } } } - }, - "undo": [ - { - "op": "replace", - "path": "/actions_left", - "value": 3 - }, - { - "op": "replace", - "path": "/players/1/advances/0", - "value": "Farming" - }, - { - "op": "replace", - "path": "/players/1/advances/1", - "value": "Fishing" - }, - { - "op": "replace", - "path": "/players/1/advances/2", - "value": "Mining" - }, - { - "op": "replace", - "path": "/players/1/advances/3", - "value": "Myths" - }, - { - "op": "replace", - "path": "/players/1/advances/4", - "value": "StateReligion" - }, - { - "op": "remove", - "path": "/players/1/advances/5" - }, - { - "op": "replace", - "path": "/players/1/incident_tokens", - "value": 3 - }, - { - "op": "replace", - "path": "/players/1/resource_limit/ideas", - "value": 7 - }, - { - "op": "replace", - "path": "/players/1/resources/ideas", - "value": 6 - } - ] + } }, { "action": { @@ -367,40 +315,7 @@ "port_position": null } } - }, - "undo": [ - { - "op": "replace", - "path": "/actions_left", - "value": 2 - }, - { - "op": "remove", - "path": "/players/1/cities/0/city_pieces/temple" - }, - { - "op": "remove", - "path": "/players/1/cities/0/activations" - }, - { - "op": "replace", - "path": "/players/1/resources/ore", - "value": 5 - }, - { - "op": "replace", - "path": "/players/1/resources/wood", - "value": 5 - }, - { - "op": "remove", - "path": "/players/1/event_info" - }, - { - "op": "remove", - "path": "/events" - } - ] + } }, { "action": { @@ -409,129 +324,14 @@ "culture_tokens": 1 } } - }, - "undo": [ - { - "op": "replace", - "path": "/events/0/handler/origin/Advance", - "value": "Myths" - }, - { - "op": "replace", - "path": "/events/0/handler/priority", - "value": 1 - }, - { - "op": "add", - "path": "/events/0/handler/request/ResourceReward", - "value": { - "name": "Select Temple bonus", - "reward": { - "conversions": [ - { - "from": [ - { - "mood_tokens": 1 - } - ], - "to": { - "culture_tokens": 1 - }, - "type": "Unlimited" - } - ], - "default": { - "mood_tokens": 1 - } - } - } - }, - { - "op": "remove", - "path": "/events/0/handler/request/SelectAdvance" - }, - { - "op": "replace", - "path": "/events/0/last_priority_used", - "value": 1 - }, - { - "op": "replace", - "path": "/players/1/resources/culture_tokens", - "value": 9 - } - ] + } }, { "action": { "Response": { "SelectAdvance": "Fanaticism" } - }, - "undo": [ - { - "op": "add", - "path": "/events", - "value": [ - { - "event_type": { - "Construct": "Temple" - }, - "handler": { - "origin": { - "Advance": "Dogma" - }, - "priority": 0, - "request": { - "SelectAdvance": { - "choices": [ - "Devotion", - "Conversion", - "Fanaticism" - ] - } - } - }, - "last_priority_used": 0, - "player": 1 - } - ] - }, - { - "op": "replace", - "path": "/players/1/advances/1", - "value": "Farming" - }, - { - "op": "replace", - "path": "/players/1/advances/2", - "value": "Fishing" - }, - { - "op": "replace", - "path": "/players/1/advances/3", - "value": "Mining" - }, - { - "op": "replace", - "path": "/players/1/advances/4", - "value": "Myths" - }, - { - "op": "replace", - "path": "/players/1/advances/5", - "value": "StateReligion" - }, - { - "op": "remove", - "path": "/players/1/advances/6" - }, - { - "op": "replace", - "path": "/players/1/incident_tokens", - "value": 2 - } - ] + } } ] } @@ -556,9 +356,13 @@ ], [ "Player2 selected Fanaticism as a reward for constructing a Temple" + ], + [ + "A new game event has been triggered: Anarchy", + "Player2 lost 2 government advances due to Anarchy - adding 2 victory points" ] ], - "undo_limit": 0, + "undo_limit": 4, "actions_left": 1, "round": 1, "age": 2, @@ -580,5 +384,13 @@ "rng": "46312381643103681595563341886777350953", "wonders_left": [ "Pyramids" + ], + "permanent_effects": [ + { + "Anarchy": { + "player": 1, + "advances_lost": 2 + } + } ] -} \ No newline at end of file +} diff --git a/server/tests/test_games/advances/writing.outcome1.json b/server/tests/test_games/advances/writing.outcome1.json index 0ba44d14..c5f91c6f 100644 --- a/server/tests/test_games/advances/writing.outcome1.json +++ b/server/tests/test_games/advances/writing.outcome1.json @@ -124,6 +124,7 @@ 1 ], "objective_cards": [ + 1, 1 ], "next_unit_id": 10 @@ -317,6 +318,10 @@ "op": "remove", "path": "/players/0/cities/0/activations" }, + { + "op": "remove", + "path": "/players/0/objective_cards/1" + }, { "op": "replace", "path": "/players/0/resources/food", diff --git a/server/tests/test_games/incidents/great_persons/great_prophet.outcome4.json b/server/tests/test_games/incidents/great_persons/great_prophet.outcome4.json index c068414d..66a8da98 100644 --- a/server/tests/test_games/incidents/great_persons/great_prophet.outcome4.json +++ b/server/tests/test_games/incidents/great_persons/great_prophet.outcome4.json @@ -13,7 +13,9 @@ }, { "event_type": { - "Construct": "Temple" + "Construct": { + "building": "Temple" + } }, "player": 0, "last_priority_used": 1, @@ -149,7 +151,7 @@ "incident_tokens": 3, "next_unit_id": 8, "event_info": { - "State Religion": "used" + "StateReligion": "used" } }, {