bandit
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
|
||||
)
|
||||
}
|
@ -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…
Reference in New Issue