premades and many-v-many combat
parent
d26a39f56f
commit
110eefd597
@ -1,40 +1,43 @@
|
|||||||
use kartsimrust::{
|
use kartsimrust::{
|
||||||
character::create_character,
|
combat::make_them_fight,
|
||||||
class::Class,
|
premade::{get_bob, get_drub},
|
||||||
combat::EncounterType,
|
|
||||||
equipment::{Armor, WeaponType},
|
|
||||||
stats::StatBlock,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut bob = create_character(
|
let mut a = 1.0;
|
||||||
String::from("Bob"),
|
let mut b = 1.0;
|
||||||
Class::Guard,
|
|
||||||
Class::Brawler,
|
|
||||||
StatBlock::from((1, 0, 1, 0, 0, 0, 0, 0)),
|
|
||||||
StatBlock::from((2, 0, 2, 0, -1, -2, 0, -1)),
|
|
||||||
Armor::Medium,
|
|
||||||
WeaponType::BladedWeapon.create_weapon("Longsword".to_owned()),
|
|
||||||
);
|
|
||||||
|
|
||||||
let mut drub = create_character(
|
let mut total_turns = 0.0;
|
||||||
String::from("Drub"),
|
let mut battles = 0.0;
|
||||||
Class::Hunter,
|
|
||||||
Class::Thief,
|
|
||||||
StatBlock::from((0, 1, 1, 0, 0, 0, 0, 0)),
|
|
||||||
StatBlock::from((0, 2, 2, 0, -2, 0, 0, -2)),
|
|
||||||
Armor::Light,
|
|
||||||
WeaponType::RangedWeapon.create_weapon(String::from("Shortbow")),
|
|
||||||
);
|
|
||||||
|
|
||||||
bob.init_dice_pool(EncounterType::Physical);
|
loop {
|
||||||
drub.init_dice_pool(EncounterType::Physical);
|
let mut bob = get_bob();
|
||||||
|
|
||||||
println!("{}", bob);
|
let mut drub = get_drub();
|
||||||
println!("{}", drub);
|
let mut drub2 = get_drub();
|
||||||
|
|
||||||
bob.attacks(&mut drub);
|
if let Some(turns) = make_them_fight(vec![&mut bob], vec![&mut drub, &mut drub2]) {
|
||||||
|
battles += 1.0;
|
||||||
|
total_turns += turns as f64;
|
||||||
|
|
||||||
println!("{}", bob);
|
if bob.hp <= 0 {
|
||||||
println!("{}", drub);
|
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.00001 {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
println!("No one died.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
println!(
|
||||||
|
"Bob won {:.2}% of battles in an average of {:.1} turns.",
|
||||||
|
a / (a + b) * 100.0,
|
||||||
|
total_turns / battles
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,61 @@
|
|||||||
|
use super::character::{create_character, Character};
|
||||||
|
use super::class::Class;
|
||||||
|
use super::equipment::{Armor, WeaponType};
|
||||||
|
use super::stats::StatBlock;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Bob has chosen to play a knight who is also an [NPC].
|
||||||
|
* He has chosen to make a knight who is strong and dexterous.
|
||||||
|
* He has also decided that his knight is not charismatic, but rather athletic.
|
||||||
|
*/
|
||||||
|
pub fn get_bob() -> Character {
|
||||||
|
create_character(
|
||||||
|
"Bob".to_owned(),
|
||||||
|
Class::Knight,
|
||||||
|
Class::NPC,
|
||||||
|
StatBlock::from((1, 1, 0, 0, 0, 0, 0, 0)),
|
||||||
|
StatBlock::from((0, 0, 2, 0, 0, 0, 0, -2)),
|
||||||
|
Armor::Medium,
|
||||||
|
WeaponType::BladedWeapon.create_weapon("Longsword".to_owned()),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Drub is a goblin.
|
||||||
|
*/
|
||||||
|
pub fn get_drub() -> Character {
|
||||||
|
let mut drub = create_character(
|
||||||
|
String::from("Drub"),
|
||||||
|
Class::NPC,
|
||||||
|
Class::NPC,
|
||||||
|
StatBlock::from((2, 3, 2, 0, 1, 0, -3, -2)),
|
||||||
|
StatBlock::default(),
|
||||||
|
Armor::Light,
|
||||||
|
WeaponType::SimpleWeapon.create_weapon(String::from("Knife")),
|
||||||
|
);
|
||||||
|
|
||||||
|
drub.proficiencies.simple_weapons = true;
|
||||||
|
drub.proficiencies.light_armor = true;
|
||||||
|
|
||||||
|
return drub
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod premade_tests {
|
||||||
|
|
||||||
|
use super::{get_bob, get_drub};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn print_bob() {
|
||||||
|
let bob = get_bob();
|
||||||
|
|
||||||
|
println!("{}", bob);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn print_drub() {
|
||||||
|
let drub = get_drub();
|
||||||
|
|
||||||
|
println!("{}", drub);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue