Fix random actions (#227)

This commit is contained in:
Gregor Zeitlinger 2025-04-24 10:09:13 +02:00 • committed by GitHub
commit 00fb55e82d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
43 changed files with 287 additions and 1915 deletions

View file

@ -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:

View file

@ -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() {

View file

@ -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" }

View file

@ -2,4 +2,4 @@
default-filter = 'not test(test_random_actions)'
[profile.bench]
default-filter = 'all()'
default-filter = 'test(random_actions)'

View file

@ -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

View file

@ -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<PlayingAction> {
if let Self::Playing(v) = self {
Some(v)
} else {
None
}
}
#[must_use]
pub fn movement(self) -> Option<MovementAction> {
if let Self::Movement(v) = self {
Some(v)
} else {
None
}
}
#[must_use]
pub fn response(self) -> Option<EventResponse> {
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()),
}
}

View file

@ -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,

View file

@ -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<Action>)> {
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<Action>
.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<Action>
.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<Action> {
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

View file

@ -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();

View file

@ -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

View file

@ -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<Position> {
p.cities
.iter()
.filter(|c| !matches!(c.mood_state, MoodState::Angry))
.map(|c| c.position)
.collect_vec()
}

View file

@ -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,

View file

@ -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<Advance>,
}
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]

View file

@ -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");
}

View file

@ -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");
}

View file

@ -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(),

View file

@ -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<Advance> = 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);
},
)
}

View file

@ -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<Position> {
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 {
""

View file

@ -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()
}

View file

@ -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()

View file

@ -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()

View file

@ -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),

View file

@ -163,6 +163,7 @@ where
}
pub struct Event<T, U = (), V = (), W = ()> {
pub name: String,
pub inner: Option<EventMut<T, U, V, W>>,
}
@ -174,6 +175,7 @@ impl<T, U, V, W> Event<T, U, V, W> {
W: Clone + PartialEq,
{
Self {
name: name.to_string(),
inner: Some(EventMut::new(name)),
}
}

View file

@ -48,7 +48,7 @@ pub struct Game {
pub action_log_index: usize,
pub log: Vec<Vec<String>>,
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 {

View file

@ -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,

View file

@ -130,6 +130,29 @@ pub(crate) enum MoodModifier {
MakeAngry,
}
pub(crate) struct DecreaseMood {
pub choices: Vec<Position>,
pub needed: u8,
}
impl DecreaseMood {
#[must_use]
pub fn new(possible: Vec<Position>, 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<Position>, 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<Position>, 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);

View file

@ -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<u8> {
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<u8> {

View file

@ -74,6 +74,7 @@ pub struct Player {
pub event_info: HashMap<String, String>,
pub secrets: Vec<String>,
pub(crate) objective_opportunities: Vec<String>, // transient
pub(crate) gained_objective: Option<u8>, // 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]

View file

@ -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<CollectInfo>,
pub construct: PersistentEvent<Building>,
pub construct: PersistentEvent<ConstructInfo>,
pub draw_wonder_card: PersistentEvent,
pub advance: PersistentEvent<OnAdvanceInfo>,
pub recruit: PersistentEvent<Recruit>,

View file

@ -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)
})
})
}

View file

@ -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,

View file

@ -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)),
),

View file

@ -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,

View file

@ -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) {

View file

@ -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
]
}

View file

@ -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"
]
}
}

View file

@ -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
]
}

View file

@ -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"
]
}

View file

@ -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"
]
}

View file

@ -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"
]
}

View file

@ -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
}
}
]
}
}

View file

@ -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",

View file

@ -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"
}
},
{