From 589047baef6d091a68176abfafdb8ebff6b02d35 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Wed, 8 May 2024 19:02:11 +0200 Subject: [PATCH] Draft of the functions --- src/main.rs | 6 ++++ src/stat_io.rs | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/stats.rs | 67 ++++++++++++++++++++++++++++++++++++ 3 files changed, 166 insertions(+) create mode 100644 src/stat_io.rs create mode 100644 src/stats.rs diff --git a/src/main.rs b/src/main.rs index 06d2a9a..2384a27 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,6 +6,8 @@ // #![allow(dead_code)] #![warn(missing_docs)] #![warn(clippy::missing_docs_in_private_items)] +mod stat_io; +mod stats; mod table_structs; mod table_types; mod tablegen; @@ -18,6 +20,7 @@ use std::{ use anyhow::{Context, Result}; use clap::{Args, Parser, Subcommand}; use serde::Deserialize; +use stats::{stat_solver, StatConfig}; use table_structs::Craft; use tablegen::table_gen; @@ -38,6 +41,8 @@ enum Commands { Tablegen(TableArgs), /// Show/Export config Config(ConfigArgs), + /// Handle stat repartition + Stats(StatConfig), } #[derive(Debug, Args)] @@ -82,6 +87,7 @@ fn main() -> Result<()> { match args.command { Commands::Tablegen(args) => table_gen(&args, &config), Commands::Config(args) => write_config(&args, &config, config_str), + Commands::Stats(args) => stat_solver(&args, &config), } } diff --git a/src/stat_io.rs b/src/stat_io.rs new file mode 100644 index 0000000..efc7b14 --- /dev/null +++ b/src/stat_io.rs @@ -0,0 +1,93 @@ +//! All the struct needed for IO purposes +#![allow(dead_code)] +#![allow(clippy::missing_docs_in_private_items)] +use std::{collections::HashMap, fs::File, path::Path}; + +use anyhow::Result; +use serde::{Deserialize, Serialize}; + +/// How to represent mathematically the affinity for a stat +type Affinity = f64; + +#[derive(Serialize, Deserialize)] +/// A row representing the creature affinity for a stat +struct CreatureCharacteristicsAffinity { + /// Strength + f: Affinity, + /// Agility + ag: Affinity, + /// Perception + per: Affinity, + /// Psychic power + psy: Affinity, + /// Intellect + int: Affinity, + /// Willpower + vol: Affinity, + /// Luck + chn: Affinity, + /// Charisma + chr: Affinity, +} + +#[repr(u8)] +/// The names of all affinities (essentialy a list of characteristics) +enum AffName { + F, + Ag, + Per, + Psy, + Int, + Vol, + Chn, + Chr, +} + +impl CreatureCharacteristicsAffinity { + // Create an affinity from a record +} + +/// The list of all creature and their associated affinities +struct CreaturesAffinity { + list_creatures: HashMap, + matrix: CharacCharMatrix, +} + +/// A matrix representing: List of characteristics and associated list of creatures +/// All math is done at this level to avoid cost +/// Right now the index of every creature is used in the matrix, but a references could be used instead +struct CharacCharMatrix { + inner: Vec>, +} +struct Creature { + affinities: CreatureCharacteristicsAffinity, + actives_affinities: Vec, + selected_affinities: Vec, +} + +impl Creature { + // Get most desired affinity + // Get list of selected affinities +} + +/// Load all the records in the csv +pub fn load_stat_records(filename: T) -> Result<()> +where + T: AsRef, +{ + let file = File::open(filename)?; + let mut rdr = csv::ReaderBuilder::new() + .has_headers(true) + .delimiter(b',') + .double_quote(false) + .escape(Some(b'\\')) + .flexible(true) + .comment(Some(b'#')) + .from_reader(file); + println!("{:?}", rdr); + println!("{:?}", rdr.headers().cloned()); + for rec in rdr.into_records() { + println!("{:?}", rec); + } + Ok(()) +} diff --git a/src/stats.rs b/src/stats.rs new file mode 100644 index 0000000..fff5506 --- /dev/null +++ b/src/stats.rs @@ -0,0 +1,67 @@ +//! A module to handle stats disparity between all origins +#![allow(dead_code)] +#![allow(clippy::missing_docs_in_private_items)] + +use anyhow::Result; +use clap::Args; + +use crate::{stat_io::load_stat_records, Config, ParserCLIArgs}; + +#[derive(Args, Debug)] +pub(crate) struct StatConfig { + // #[arg(default_value_t: "data/Book1.csv")] + config_path: String, +} + +/// Main solver function, in charge of selecting algorithms and handling all program flow +pub(crate) fn stat_solver(args: &StatConfig, config: &Config) -> Result<()> { + load_stat_records(&"data/Book1.csv"); + Ok(()) +} + +// struct DesiredStats {} + +// struct Creature { +// stats: DesiredStats, +// name: String, +// } + +// enum CharacEnum { +// F, +// Ag, +// } + +// struct CharacWeight { +// charac: CharacEnum, +// list_weights: Vec<(f64, Creature)>, +// } + +// // impl Creature{ +// // fn get_ +// // } + +// // The first Algorithm, creating all creatures from scratch + +// fn get_next_stat_to_grow() {} + +// fn get_greatest_consumer_of(c: CharacEnum) {} + +// fn assign_stat_to_creature(c: CharacEnum) {} + +// fn get_greatest_despiser_of(c: CharacEnum) {} + +// // The second algorithm, appending to an existing solution + +// // Serialize and Deserialize Solutions + +// fn try_getting_desired_stat() {} + +// fn find_swap_creature() {} + +// // Integrity check and disparity check + +// fn check_stats_integrity() {} + +// fn show_stats() {} + +// fn show_outliers() {}