You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
128 lines
3.9 KiB
Rust
128 lines
3.9 KiB
Rust
use std::{
|
|
io::{self, Write},
|
|
iter,
|
|
};
|
|
|
|
use rand::{seq::SliceRandom, thread_rng};
|
|
// use rayon::prelude::*;
|
|
use kartsimrust::{
|
|
character::Character,
|
|
combat::{make_them_fight, EncounterType},
|
|
random_character::random_character,
|
|
stats::Stat,
|
|
};
|
|
|
|
fn print_chars<'a, L>(characters: L)
|
|
where
|
|
L: IntoIterator<Item = &'a Character>,
|
|
{
|
|
println!("Name | Classes | HP MP AC DP | STR DEX CON STB | INT KND CMP CHA | Armor | Weapon");
|
|
for ch in characters {
|
|
let mut c = ch.to_owned();
|
|
c.init_encounter(EncounterType::Physical);
|
|
println!(
|
|
"{name:<8} | {class1:<12} {class2:<12} | {hp:>2} {mp:>2} {ac:>2} {dp:>2} | {str:>3} {dex:>3} {con:>3} {stb:>3} | {int:>3} {knd:>3} {cmp:>3} {cha:>3} | {armor:<6} | {weapon:<15}",
|
|
name = c.name,
|
|
class1 = c.class1,
|
|
class2 = c.class2,
|
|
hp=c.hp,
|
|
mp = c.mp,
|
|
ac=c.ac(),
|
|
dp = c.dice_pool(),
|
|
str=c.stat(Stat::STR),
|
|
dex=c.stat(Stat::DEX),
|
|
con=c.stat(Stat::CON),
|
|
stb=c.stat(Stat::STB),
|
|
int=c.stat(Stat::INT),
|
|
knd=c.stat(Stat::KND),
|
|
cmp=c.stat(Stat::CMP),
|
|
cha=c.stat(Stat::CHA),
|
|
armor = c.armor,
|
|
weapon = c.weapon,
|
|
);
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
let mut rng = thread_rng();
|
|
|
|
let n = 100;
|
|
let keep = 20;
|
|
let gen = 50000;
|
|
|
|
let mut characters: Vec<Character> = iter::repeat_with(random_character).take(n).collect();
|
|
print_chars(characters.iter().take(keep).collect::<Vec<&Character>>());
|
|
// print_chars(&characters1);
|
|
// print_chars(&characters2);
|
|
|
|
for g in 0..gen {
|
|
characters.shuffle(&mut rng);
|
|
|
|
let teams: (Vec<(usize, Character)>, Vec<(usize, Character)>) = characters
|
|
.iter()
|
|
.cloned()
|
|
.enumerate()
|
|
.partition(|(i, _)| *i % 2 == 0);
|
|
let matches: Vec<(Character, Character)> = iter::zip(teams.0.iter(), teams.1.iter())
|
|
.map(|((_, c1), (_, c2))| (c1.to_owned(), c2.to_owned()))
|
|
.collect();
|
|
|
|
let mut winners: Vec<(i64, Character)> = matches
|
|
.iter()
|
|
.map(|(c1, c2)| {
|
|
let n_rounds = 50;
|
|
let mut w: i64 = 0;
|
|
|
|
for _i in 0..n_rounds {
|
|
let mut c1l = c1.to_owned();
|
|
let mut c2l = c2.to_owned();
|
|
let t = make_them_fight(&mut c1l, &mut c2l);
|
|
|
|
match t {
|
|
Some(_turns) => {
|
|
if c2l.hp <= 0 {
|
|
w += 1
|
|
}
|
|
}
|
|
None => (),
|
|
}
|
|
}
|
|
if w >= n_rounds / 2 {
|
|
(-w, c1.to_owned())
|
|
} else {
|
|
(-(n_rounds - w), c2.to_owned())
|
|
}
|
|
})
|
|
.collect();
|
|
|
|
winners.sort_by_key(|(i, _)| *i);
|
|
|
|
characters = winners
|
|
.iter()
|
|
.take(keep)
|
|
.map(|(_, c)| c.clone())
|
|
.chain(
|
|
(0..(n - keep))
|
|
.into_iter()
|
|
.map(|_| random_character())
|
|
.take(n - keep),
|
|
)
|
|
.collect();
|
|
|
|
if g % (gen / 100) == 0 {
|
|
print!(
|
|
"\r{:#<c$}{:.<r$}",
|
|
"",
|
|
"",
|
|
c = (((g as f32) / (gen as f32)) * 100.0) as usize,
|
|
r = 100 - (((g as f32) / (gen as f32)) * 100.0) as usize
|
|
);
|
|
io::stdout().flush().unwrap();
|
|
}
|
|
}
|
|
|
|
println!("");
|
|
|
|
print_chars(characters.iter().take(keep).collect::<Vec<&Character>>());
|
|
}
|