Lot of debug on scenarios&sustained

This commit is contained in:
Dandaedre 2025-02-24 23:33:58 +01:00
parent 101b8c778a
commit 788f9fb112
Signed by: Dandaedre
GPG Key ID: 440C6592E8A26D99
5 changed files with 64 additions and 22 deletions

View File

@ -7,6 +7,7 @@ use clap::Parser;
use std::path::Path;
use weaponry::interfaces::ToAnalysis;
use weaponry::sort_by;
use weaponry::sort_by_cat_then;
use weaponry::weaponry_structs::RefinedEquipement;
// TODO : All of these should likely be in the prelude if used like this
@ -30,14 +31,24 @@ fn main() {
})
.unwrap();
let mut refined_list = scenarios.generate_refined_recipes().unwrap();
let mut refined_list = scenarios
.generate_refined_recipes()
.unwrap()
// .inner_filter(|e| (e.advanced.max_damage_per_attack > 0.))
.inner_filter(|e| {
e.inner.macro_category.as_ref().is_some_and(|v| {
!matches!(v, weaponry::weaponry_structs::WeaponMacroCategory::Shields)
&& !matches!(v, weaponry::weaponry_structs::WeaponMacroCategory::Armor)
})
});
// TODO[!]: Have an enum
match args.sort.as_str() {
"max_per_turn" => refined_list.inner_sort(sort_by!(max_damage_per_turn)),
"avg_huge" => refined_list.inner_sort(sort_by!(avg_damage_single_huge_hit)),
"avg_safe" => refined_list.inner_sort(sort_by!(avg_damage_2a_safe)),
"max_armor" => refined_list.inner_sort(sort_by!(armor_break_per_attack)),
// "id" => refined_list.inner_sort(|a, b| a.inner.id[0].cmp(&b.inner.id[0])), // It's actually the natural sorted way
"cat+avg" => refined_list.inner_sort(sort_by_cat_then!(avg_damage_2a_safe)),
_ => (),
}

View File

@ -41,6 +41,7 @@
///
/// Knowing this tradeoff, the difficulty to maintain is considered an acceptable tradeoff
// TODO[4]: If the field accessed are only in advanced, remove the closure entirely and auto_generate it
// TODO[4]: A good part of this code shouldn't be generic and instead in weaponry
#[macro_export]
macro_rules! add_field_to_chart {
($base_struct:expr, $chart:ident, ($names:ident # $name_type:ty, $($table_names:ident # $table_type:ty),* $(,)*), | $closure_name:ident | {($($fields:expr,)*)}
@ -58,8 +59,16 @@ macro_rules! add_field_to_chart {
let $chart = $chart
.series(
charming::series::Line::new()
.stack("Total")
.data($table_names)
.name(stringify!($table_names)),
.name(stringify!($table_names))
.mark_point(charming::element::MarkPoint::new().data(vec![("max", "Max"), ("min", "Min")]))
.mark_line(charming::element::MarkLine::new().data(vec![charming::element::MarkLineVariant::Simple(
charming::element::MarkLineData::new()
.type_(charming::element::MarkLineDataType::Average)
.name("Avg"),
)])),
);
)*

View File

@ -84,6 +84,17 @@ macro_rules! sort_by {
}
};
}
#[macro_export]
/// A simple macro to sort the inner advanced field by a specific field
// TODO[6] find a way to not have to import the refinedequipement
macro_rules! sort_by_cat_then {
($field:ident) => {
|a, b| match a.inner.id[0].cmp(&b.inner.id[0]) {
std::cmp::Ordering::Equal => a.advanced.$field.total_cmp(&b.advanced.$field),
ord => ord,
}
};
}
impl ToAnalysis for RefinedEquipementList {
type InnerData = RefinedEquipement;
@ -115,6 +126,11 @@ impl ToAnalysis for RefinedEquipementList {
self.inner.len()
));
macro_rules! round {
($a:expr) => {
($a * 10.).round() / 10.
};
}
add_field_to_chart!(
self,
initial_chart,
@ -139,11 +155,11 @@ impl ToAnalysis for RefinedEquipementList {
// ref_equipement.advanced.speed,
// ref_equipement.advanced.armor_break_per_attack,
// ref_equipement.advanced.expected_armor_break_per_2a,
ref_equipement.advanced.avg_damage_2a_safe,
ref_equipement.advanced.avg_damage_single_huge_hit,
round!(ref_equipement.advanced.avg_damage_2a_safe),
round!(ref_equipement.advanced.avg_damage_single_huge_hit),
// ref_equipement.advanced.scenario_damage,
// ref_equipement.advanced.defensive,
ref_equipement.advanced.mini_scenario_damage,
round!(ref_equipement.advanced.mini_scenario_damage),
)
}

View File

@ -120,7 +120,6 @@ impl BestDamageScenarios {
0,
)
}
/// Recursive part of the from_action_constraints call
///
/// This algorithm takes a recursive approact to avoid too much forward complexity
@ -139,13 +138,18 @@ impl BestDamageScenarios {
|| reload_remaining > 0
|| *dices_allowed < 1
{
println!(
"[{depth}] > Reach the end of recursion {}>{actions_allowed}, {attacks_allowed}a, {dices_allowed}d {reload_remaining}r",
value.action_cost
);
// println!(
// "[{depth}] > Reach the end of recursion {}>{actions_allowed}, {attacks_allowed}a, {dices_allowed}d {reload_remaining}r",
// value.action_cost
// );
return None;
}
// if depth == 0 {
// println!(
// "Starting recursion: {actions_allowed}A {attacks_allowed}atk {dices_allowed}*"
// );
// }
let atkreload_cost = value.reload_cost.unwrap_or_default() + value.action_cost;
// We create our first contender, One attack only
@ -160,10 +164,10 @@ impl BestDamageScenarios {
.clamp(0, actions_allowed),
depth,
};
println!(
"[{depth}] > One attack ({}): {one_attack:?}",
Dices(*dices_allowed)
);
// println!(
// "[{depth}] > One attack ({}d): {one_attack:?}/{actions_allowed}A",
// Dices(*dices_allowed)
// );
// We can only try two attacks if two attack would be valid aka:
// - We can spend: 2 attacks and (at least) 1 reload (as actions)
@ -173,20 +177,22 @@ impl BestDamageScenarios {
if let (Some(a), Some(b)) = (
(Self::from_action_constraints_recursive(
value,
actions_allowed - atkreload_cost, //.div_floor(2).div_floor(2) * 2 -value.reload_cost.unwrap_or_default(),
// TODO[9]: THIS APPROACH IS DEEPLY INCORRECT
// : It does however work for the values we will be using it
actions_allowed - atkreload_cost,
attacks_allowed.div_floor(2),
Dices(dices_allowed.div_floor(2)),
precision,
reload_remaining - value.reload_cost.unwrap_or_default(),
reload_remaining,
depth + 1,
)),
(Self::from_action_constraints_recursive(
value,
actions_allowed - atkreload_cost, // .div_ceil(2).div_ceil(2) * 2 -value.reload_cost.unwrap_or_default(),
actions_allowed - atkreload_cost,
attacks_allowed.div_ceil(2),
Dices(dices_allowed.div_ceil(2)),
precision,
reload_remaining,
reload_remaining - value.reload_cost.unwrap_or_default(),
depth + 1,
)),
) {
@ -424,8 +430,8 @@ mod test {
36.,
),
];
known_data.iter().for_each(|(val, res)| {
println!("{:?} ~= {res}", val.clone().unwrap_or_default());
known_data.iter().enumerate().for_each(|(i, (val, res))| {
println!("[{i}] {:?} ~= {res}", val.clone().unwrap_or_default());
assert_close!(val.clone().map_or(0., |v| v.damage_done), res);
});
// todo!()

View File

@ -107,7 +107,7 @@ pub struct InnerEquipementStats {
pub(super) speed: i8,
pub(super) stealth: i8,
/// The initial macro category, in turn combined with other stats it will describe a final category
pub(super) macro_category: Option<WeaponMacroCategory>, // TODO : This initial macro category fill as a final stat feed the final category
pub macro_category: Option<WeaponMacroCategory>, // TODO : This initial macro category fill as a final stat feed the final category
pub(super) target: Option<WeaponMacroCategory>, // TODO: This might be incorrect, to check
pub(super) special: SpecialField,
pub(super) action_cost: i8,