From 848ca7c3581b02a9780fb06395a5282ce6098c25 Mon Sep 17 00:00:00 2001 From: HeNine <> Date: Sun, 28 May 2023 20:56:09 +0200 Subject: [PATCH] george --- examples/george_v_drub.rs | 42 +++++++++++++++++++++++++++++++++++++++ src/premade/mod.rs | 28 ++++++++++++++++++++++++-- 2 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 examples/george_v_drub.rs diff --git a/examples/george_v_drub.rs b/examples/george_v_drub.rs new file mode 100644 index 0000000..5e955b6 --- /dev/null +++ b/examples/george_v_drub.rs @@ -0,0 +1,42 @@ +use kartsimrust::{ + combat::make_them_fight, + premade::{get_george, get_drub}, +}; + +fn main() { + let mut a = 1.0; + let mut b = 1.0; + + let mut total_turns = 0.0; + let mut battles = 0.0; + + loop { + let mut george = get_george(); + + let mut drubs = (0..1).map(|_| get_drub()).collect::>(); + + if let Some(turns) = make_them_fight(vec![&mut george], drubs.iter_mut().collect()) { + battles += 1.0; + total_turns += turns as f64; + + if george.is_dead() { + b += 1.0; + println!("Bob died in {} turns.", turns) + } else { + a += 1.0; + println!("Drub died in {} turns.", turns) + } + + if (a * b) / (f64::powi(a + b, 2) * (a + b + 1.0)) <= 0.0001 { + break; + } + } else { + println!("No one died.") + } + } + println!( + "George won {:.2}% of battles in an average of {:.1} turns.", + a / (a + b) * 100.0, + total_turns / battles + ) +} diff --git a/src/premade/mod.rs b/src/premade/mod.rs index e536844..5661b05 100644 --- a/src/premade/mod.rs +++ b/src/premade/mod.rs @@ -20,6 +20,23 @@ pub fn get_bob() -> Character { ) } +/* + * George is a swashbuckler. + * He has chosen to be more dextrous, and have better composure. + * George is a himbo. + */ +pub fn get_george() -> Character { + create_character( + "George".to_owned(), + Class::Swashbuckler, + Class::NPC, + StatBlock::from((0, 1, 0, 0, 0, 0, 1, 0)), + StatBlock::from((0, 2, 1, 0, -2, -1, 0, 0)), + Armor::None, + WeaponType::BladedWeapon.create_weapon("Rapier".to_owned()), + ) +} + /* * Drub is a goblin. */ @@ -37,13 +54,13 @@ pub fn get_drub() -> Character { drub.proficiencies.simple_weapons = true; drub.proficiencies.light_armor = true; - return drub + return drub; } #[cfg(test)] mod premade_tests { - use super::{get_bob, get_drub}; + use super::{get_bob, get_drub, get_george}; #[test] fn print_bob() { @@ -52,6 +69,13 @@ mod premade_tests { println!("{}", bob); } + #[test] + fn print_george() { + let george = get_george(); + + println!("{}", george); + } + #[test] fn print_drub() { let drub = get_drub();