main
HeNine 1 year ago
parent 4abb431702
commit f0c556833c

@ -0,0 +1,68 @@
use kartsimrust::{
premade::{get_bandit, get_bob, get_george},
test_util::battle_stats::battle_stats,
};
fn main() {
env_logger::init();
let mut characters = vec![get_bob()];
let mut enemies = (0..1).map(|_| get_bandit()).collect::<Vec<_>>();
let (p, mu_t) = battle_stats(characters, enemies);
println!(
"Bob won {:.2}% of battles in an average of {:.1} turns.",
p, mu_t
);
characters = vec![get_george()];
enemies = (0..1).map(|_| get_bandit()).collect::<Vec<_>>();
let (p, mu_t) = battle_stats(characters, enemies);
println!(
"George won {:.2}% of battles in an average of {:.1} turns.",
p, mu_t
);
characters = vec![get_bob()];
enemies = (0..2).map(|_| get_bandit()).collect::<Vec<_>>();
let (p, mu_t) = battle_stats(characters, enemies);
println!(
"Bob won {:.2}% of battles against 2 Bandits in an average of {:.1} turns.",
p, mu_t
);
characters = vec![get_bob(), get_george()];
enemies = (0..1).map(|_| get_bandit()).collect::<Vec<_>>();
let (p, mu_t) = battle_stats(characters, enemies);
println!(
"Bob and George won {:.2}% of battles against 1 Bandit in an average of {:.1} turns.",
p, mu_t
);
characters = vec![get_bob(), get_george()];
enemies = (0..2).map(|_| get_bandit()).collect::<Vec<_>>();
let (p, mu_t) = battle_stats(characters, enemies);
println!(
"Bob and George won {:.2}% of battles against 2 Bandits in an average of {:.1} turns.",
p, mu_t
);
characters = vec![get_bob(), get_george()];
enemies = (0..3).map(|_| get_bandit()).collect::<Vec<_>>();
let (p, mu_t) = battle_stats(characters, enemies);
println!(
"Bob and George won {:.2}% of battles against 3 Bandits in an average of {:.1} turns.",
p, mu_t
)
}

@ -10,3 +10,5 @@ pub mod stats;
pub mod random_character;
pub mod premade;
pub mod test_util;

@ -38,7 +38,7 @@ pub fn get_george() -> Character {
}
/*
* Drub is a goblin.
* Drub is a ~~goblin~~ drub.
*/
pub fn get_drub() -> Character {
let mut drub = create_character(
@ -57,10 +57,30 @@ pub fn get_drub() -> Character {
return drub;
}
/*
* Just an average bandit.
*/
pub fn get_bandit() -> Character {
let mut drub = create_character(
String::from("Bandit"),
Class::NPC,
Class::NPC,
StatBlock::from((1, 0, 2, 1, 1, 1, 0, 1)),
StatBlock::default(),
Armor::Medium,
WeaponType::BladedWeapon.create_weapon(String::from("Shortsword")),
);
drub.proficiencies.bladed_weapons = true;
drub.proficiencies.medium_armor = true;
return drub;
}
#[cfg(test)]
mod premade_tests {
use super::{get_bob, get_drub, get_george};
use super::{get_bandit, get_bob, get_drub, get_george};
#[test]
fn print_bob() {
@ -82,4 +102,11 @@ mod premade_tests {
println!("{}", drub);
}
#[test]
fn print_bandit() {
let bandit = get_bandit();
println!("{}", bandit);
}
}

@ -0,0 +1,36 @@
use crate::{character::Character, combat::make_them_fight};
pub fn battle_stats(characters: Vec<Character>, enemies: Vec<Character>) -> (f64, f64) {
let mut a = 1.0;
let mut b = 1.0;
let mut total_turns = 0.0;
let mut battles = 0.0;
let mut chars: Vec<Character> = characters.iter().map(|c| c.clone()).collect();
let mut enms: Vec<Character> = enemies.iter().map(|c| c.clone()).collect();
loop {
if let Some(turns) = make_them_fight(chars.iter_mut().collect(), enms.iter_mut().collect())
{
battles += 1.0;
total_turns += turns as f64;
if chars.iter().all(|c| c.is_dead()) {
b += 1.0;
log::trace!("Bob died in {} turns.", turns)
} else {
a += 1.0;
log::trace!("Bandit died in {} turns.", turns)
}
if (a * b) / (f64::powi(a + b, 2) * (a + b + 1.0)) <= 0.0001 {
break;
}
} else {
log::trace!("No one died.")
}
}
(a / (a + b) * 100.0, total_turns / battles)
}

@ -0,0 +1 @@
pub mod battle_stats;
Loading…
Cancel
Save