Draft of the functions

This commit is contained in:
Dandaedre 2024-05-08 19:02:11 +02:00
parent fa5d8c9057
commit 589047baef
3 changed files with 166 additions and 0 deletions

View File

@ -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),
}
}

93
src/stat_io.rs Normal file
View File

@ -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<AffName, CreatureCharacteristicsAffinity>,
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<Vec<(usize, Affinity)>>,
}
struct Creature {
affinities: CreatureCharacteristicsAffinity,
actives_affinities: Vec<Affinity>,
selected_affinities: Vec<AffName>,
}
impl Creature {
// Get most desired affinity
// Get list of selected affinities
}
/// Load all the records in the csv
pub fn load_stat_records<T>(filename: T) -> Result<()>
where
T: AsRef<Path>,
{
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(())
}

67
src/stats.rs Normal file
View File

@ -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() {}