george
parent
35616e74cc
commit
848ca7c358
@ -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::<Vec<_>>();
|
||||
|
||||
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
|
||||
)
|
||||
}
|
Loading…
Reference in New Issue