Implementation(Bindings) - Adds even more binding

This commit is contained in:
Dandaedre 2023-02-21 04:25:41 +01:00
parent bc28e51db4
commit 1ca2f23f31
4 changed files with 63 additions and 19 deletions

View File

@ -16,6 +16,7 @@ fn main() {
// Start timer
let now = Instant::now();
println!("Solving...");
// Solve from config
let (recipe,stats) = xiv_craft_solver::load_from_config(&args.recipe_name, &args.file_name, &args.character_name);
@ -31,19 +32,17 @@ fn main() {
}
// Show best result depending on selected value
println!("FAST {:?}",xiv_craft_solver::find_fast_route(&results));
println!("SAFE {:?}",xiv_craft_solver::find_safe_route(&results));
println!("QLTY {:?}",xiv_craft_solver::find_quality_route(&results));
println!("\n > SOLUTION [Least steps] <");
xiv_craft_solver::find_fast_route(&results).unwrap().pretty_print();
println!("\n > SOLUTION [Most durability] <");
xiv_craft_solver::find_safe_route(&results).unwrap().pretty_print();
println!("\n > SOLUTION [Most quality] < ");
xiv_craft_solver::find_quality_route(&results).unwrap().pretty_print();
#[cfg(feature = "verbose")]
if params.verbose>2{
println!("[F] Top route {:?}",results);
println!("[F] Top routes {:?}",results);
}
// {
// println!("Quality: {}/{}", results.quality, results.recipe.quality);
// println!("\t[{}]", results.join(", "));
// }
// Wait for user input
println!("\nProgram finished successfully in {}ms\nPress enter to exit...", t_final);

View File

@ -1,4 +1,3 @@
use crate::action::ACTIONS;
use std::fmt::{Debug, Formatter,Display};
use crate::action::Action;
use crate::specs::{Buff, BuffState, Recipe, Stats, Success};

View File

@ -55,6 +55,16 @@ pub struct SolverResult{
#[pyo3(get)]
pub durability: i32,
#[pyo3(get)]
pub cp:i32,
#[pyo3(get)]
pub total_cp:u32,
#[pyo3(get)]
pub total_progression:u32,
#[pyo3(get)]
pub total_quality:u32,
#[pyo3(get)]
pub total_durability:u32,
#[pyo3(get)]
pub actions: Vec<String>,
#[pyo3(get)]
pub step1_solutions: usize,
@ -72,6 +82,7 @@ impl Display for SolverResult{
}
}
// #[pymethods]
impl SolverResult{
pub fn from_craft(craft: & Craft,step1_solutions : usize,step2_solutions : usize, found_100_percent: bool)->SolverResult{
// Todo: recreate actions
@ -95,21 +106,38 @@ impl SolverResult{
step1_solutions,
step2_solutions,
found_100_percent,
total_progression:craft.recipe.progress,
total_quality:craft.recipe.quality,
total_durability:craft.recipe.durability,
cp: craft.cp,
total_cp : craft.stats.max_cp,
}
}
// #[new]
pub fn default()->Self{
Self{
steps:0,
progression: 0,
quality:0,
durability:0,
total_progression:0,
total_quality:0,
total_durability:0,
actions:vec!["Act1".to_string(),"Act2".to_string()],
step1_solutions:0,
step2_solutions:0,
found_100_percent:false,
cp:0,
total_cp:0,
}
}
pub fn pretty_print(&self){
println!("Quality: [{}/{}] | Durability: [{}/{}] | Cp : [{}/{}]",
self.quality, self.total_quality, self.durability, self.total_durability, self.cp, self.total_cp);
println!("{:?}", self.actions);
}
}
/// Python Bindings

View File

@ -174,20 +174,27 @@ pub fn print_routes<'a>(routes: Option<Vec<SolverResult>>){
}
}
// TODO: Fix it for not completed crafts
/// Find the route with the least amount of steps
pub fn find_fast_route(routes: &Option<Vec<SolverResult>>) -> Option<&SolverResult>{
let res = match routes {
Some(route) => route.iter().min_by_key(|key| key.steps),
None => None,
};
res
match routes {
Some(_routes) => {
if _routes.len()>0{
if _routes[0].found_100_percent {
_routes.iter().min_by_key(|key| key.steps)
} else {
// If the quality didn't reach 100% the fastest is meaningless
find_quality_route(routes)
}
} else { None }
},
None => None,
}
}
/// Find the route with the maximum amount of quality
pub fn find_quality_route(routes: &Option<Vec<SolverResult>>) -> Option<&SolverResult>{
match routes {
Some(route) => route.iter().max_by_key(|key| key.quality),
Some(_routes) => _routes.iter().max_by_key(|key| key.quality),
None => None,
}
}
@ -195,7 +202,18 @@ pub fn find_quality_route(routes: &Option<Vec<SolverResult>>) -> Option<&SolverR
/// Find the route with the maximum of durability left
pub fn find_safe_route(routes: &Option<Vec<SolverResult>>) -> Option<&SolverResult>{
match routes {
Some(route) => route.iter().min_by_key(|key| key.durability),
None => None,
Some(_routes) => {
if _routes.len()>0{
if _routes[0].found_100_percent{
_routes.iter().min_by_key(|key| key.durability)
} else {
// If the craft didn't reach 100% quality the durability is meaningless
find_quality_route(routes)
}
} else {
None
}
},
None => None,
}
}