Adds badges and finalises binomial distribution

This commit is contained in:
Dandaedre 2025-02-14 03:54:18 +01:00
parent a512e0518d
commit 6cc0f27d3d
Signed by: Dandaedre
GPG Key ID: 440C6592E8A26D99
6 changed files with 45 additions and 22 deletions

View File

@ -7,6 +7,9 @@ members = [ "cli_parser", "config", "graphs", "make",
]
resolver = "3"
[workspace.package]
version = "0.2.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[profile.dev]

View File

@ -1,8 +1,10 @@
![code coverage](badges/coverage.svg) ![version](badges/version.svg) ![code coverage](badges/test.svg)
# ravenous-tools
Set of tools to handle ravenous rulebook creation
# Installation
Now depends on libsqlite3-dev and sqlite3
A bundled implementation should be added
A bundled implementation should be added on all releases

1
badges/coverage.svg Normal file
View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="118" height="18" role="img" aria-label="test-coverage: N/A"><title>test-coverage: N/A</title><linearGradient id="bms-b5474c43532a9abd" x2="0" y2="100%"><stop offset="0" stop-color="#fff" stop-opacity=".7"/><stop offset=".1" stop-color="#aaa" stop-opacity=".1"/><stop offset=".9" stop-color="#000" stop-opacity=".3"/><stop offset="1" stop-color="#000" stop-opacity=".5"/></linearGradient><clipPath id="bmr-b5474c43532a9abd"><rect width="118" height="18" rx="4" fill="#fff"/></clipPath><g clip-path="url(#bmr-b5474c43532a9abd)"><rect width="87" height="18" fill="#555"/><rect x="87" width="31" height="18" fill="#e05d44"/><rect width="118" height="18" fill="url(#bms-b5474c43532a9abd)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="445" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="770">test-coverage</text><text x="445" y="130" transform="scale(.1)" fill="#fff" textLength="770">test-coverage</text><text aria-hidden="true" x="1015" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="210">N/A</text><text x="1015" y="130" transform="scale(.1)" fill="#fff" textLength="210">N/A</text></g></svg>

After

Width:  |  Height:  |  Size: 1.3 KiB

1
badges/test.svg Normal file
View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="74" height="18" role="img" aria-label="test: failing"><title>test: failing</title><linearGradient id="bms-a16a196477035f4f" x2="0" y2="100%"><stop offset="0" stop-color="#fff" stop-opacity=".7"/><stop offset=".1" stop-color="#aaa" stop-opacity=".1"/><stop offset=".9" stop-color="#000" stop-opacity=".3"/><stop offset="1" stop-color="#000" stop-opacity=".5"/></linearGradient><clipPath id="bmr-a16a196477035f4f"><rect width="74" height="18" rx="4" fill="#fff"/></clipPath><g clip-path="url(#bmr-a16a196477035f4f)"><rect width="31" height="18" fill="#555"/><rect x="31" width="43" height="18" fill="#e05d44"/><rect width="74" height="18" fill="url(#bms-a16a196477035f4f)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="165" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="210">test</text><text x="165" y="130" transform="scale(.1)" fill="#fff" textLength="210">test</text><text aria-hidden="true" x="515" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="330">failing</text><text x="515" y="130" transform="scale(.1)" fill="#fff" textLength="330">failing</text></g></svg>

After

Width:  |  Height:  |  Size: 1.3 KiB

1
badges/version.svg Normal file
View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="90" height="18" role="img" aria-label="version: 0.2.0"><title>version: 0.2.0</title><linearGradient id="bms-db7098c97f02adb0" x2="0" y2="100%"><stop offset="0" stop-color="#fff" stop-opacity=".7"/><stop offset=".1" stop-color="#aaa" stop-opacity=".1"/><stop offset=".9" stop-color="#000" stop-opacity=".3"/><stop offset="1" stop-color="#000" stop-opacity=".5"/></linearGradient><clipPath id="bmr-db7098c97f02adb0"><rect width="90" height="18" rx="4" fill="#fff"/></clipPath><g clip-path="url(#bmr-db7098c97f02adb0)"><rect width="51" height="18" fill="#555"/><rect x="51" width="39" height="18" fill="#fe7d37"/><rect width="90" height="18" fill="url(#bms-db7098c97f02adb0)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="265" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="410">version</text><text x="265" y="130" transform="scale(.1)" fill="#fff" textLength="410">version</text><text aria-hidden="true" x="695" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="290">0.2.0</text><text x="695" y="130" transform="scale(.1)" fill="#fff" textLength="290">0.2.0</text></g></svg>

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -14,7 +14,7 @@ use std::fmt::Display;
use crate::interfaces::RefinedList;
use probability::prelude::{Binomial, Discrete};
use strum::{EnumIter, IntoEnumIterator};
use strum::{Display, EnumIter, IntoEnumIterator};
use super::{Equipement, InitialEquipementList, equipement_structs::InnerEquipementStats};
@ -111,8 +111,26 @@ impl DamageMatrix {
impl Display for DamageMatrix {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let _ = f;
todo!()
// "[{:.3}:{:.3}] {:5.2}", dices, precision,
write!(
f,
"{}",
DiceNumber::iter()
.map(|dices| {
Precision::iter()
.map(move |precision| format!("{:5.2}", self.get_damage(precision, dices)))
.fold(format!("[{:.3}]", dices.to_string()), |res, new| {
res + " " + &new
})
})
.fold(
Precision::iter().fold(String::from(" D\\P "), |res, new| format!(
"{} [{:.3}]",
res, new
)),
|res, new| res + "\n" + &new
)
)
}
}
@ -121,11 +139,11 @@ impl From<&InnerEquipementStats> for DamageMatrix {
// let binomial_distribution = Binomial::new(dices, value.precision);
// binomial_distribution.mass(i) // -> The chance to have this number of success
DamageMatrix {
damage_matrix: (Precision::iter()
.flat_map(|precision| {
DiceNumber::iter()
.map(move |dices| {
binomial_dice_distribution(value, precision.value(), dices.value())
damage_matrix: (DiceNumber::iter()
.flat_map(|dices| {
Precision::iter()
.map(move |prec| {
binomial_dice_distribution(value, prec.value(), dices.value())
})
.collect::<Vec<_>>()
})
@ -136,15 +154,12 @@ impl From<&InnerEquipementStats> for DamageMatrix {
/// Calculate the binomial distribution and average the damage from there
fn binomial_dice_distribution(value: &InnerEquipementStats, precision: usize, dices: usize) -> f64 {
let p = ((precision as i8 + value.precision) as f64 / 10.).clamp(0., 1. - 1E-10);
// println!("precision: {},{}", p, 9.99999);
let p = ((precision as i8 + value.precision) as f64 / 10.).clamp(0. + 1E-10, 1. - 1E-10);
let binomial = Binomial::new(dices, p);
(0..dices + 1)
.map(|target_dices| {
// TODO: This non rounding can be veird
let probability_success = binomial.mass(target_dices); // Let's have weird half dices as usize;
println!("probability : {:?}", probability_success);
if target_dices >= 1 {
(value.damage as f64
+ value.p_damage as f64
@ -158,7 +173,7 @@ fn binomial_dice_distribution(value: &InnerEquipementStats, precision: usize, di
}
/// The precision infered for a damage calculation event
#[derive(EnumIter, Clone, Copy)]
#[derive(EnumIter, Clone, Copy, Display)]
#[allow(clippy::missing_docs_in_private_items)]
pub enum Precision {
High,
@ -167,12 +182,12 @@ pub enum Precision {
}
/// The number of dices rolled for a damage simulation
#[derive(EnumIter, Clone, Copy)]
#[derive(EnumIter, Clone, Copy, Display)]
#[allow(clippy::missing_docs_in_private_items)]
pub enum DiceNumber {
High,
Medium,
Low,
Many,
Average,
Few,
}
impl Precision {
@ -191,9 +206,9 @@ impl DiceNumber {
/// Associate a value to the different values
fn value(&self) -> usize {
match self {
DiceNumber::High => 7,
DiceNumber::Medium => 5,
DiceNumber::Low => 3,
DiceNumber::Many => 7,
DiceNumber::Average => 5,
DiceNumber::Few => 3,
}
}
}
@ -217,7 +232,7 @@ mod test {
let mat: DamageMatrix = DamageMatrix::from(&damage);
println!("{:#?}", damage);
println!("{:#?}", mat);
panic!()
println!("{}", mat);
}
#[test]