Implementation(Bindings) - Adds even more binding
This commit is contained in:
parent
bc28e51db4
commit
1ca2f23f31
|
|
@ -16,6 +16,7 @@ fn main() {
|
||||||
|
|
||||||
// Start timer
|
// Start timer
|
||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
|
println!("Solving...");
|
||||||
|
|
||||||
// Solve from config
|
// Solve from config
|
||||||
let (recipe,stats) = xiv_craft_solver::load_from_config(&args.recipe_name, &args.file_name, &args.character_name);
|
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
|
// Show best result depending on selected value
|
||||||
println!("FAST {:?}",xiv_craft_solver::find_fast_route(&results));
|
println!("\n > SOLUTION [Least steps] <");
|
||||||
println!("SAFE {:?}",xiv_craft_solver::find_safe_route(&results));
|
xiv_craft_solver::find_fast_route(&results).unwrap().pretty_print();
|
||||||
println!("QLTY {:?}",xiv_craft_solver::find_quality_route(&results));
|
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")]
|
#[cfg(feature = "verbose")]
|
||||||
if params.verbose>2{
|
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
|
// Wait for user input
|
||||||
println!("\nProgram finished successfully in {}ms\nPress enter to exit...", t_final);
|
println!("\nProgram finished successfully in {}ms\nPress enter to exit...", t_final);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
use crate::action::ACTIONS;
|
|
||||||
use std::fmt::{Debug, Formatter,Display};
|
use std::fmt::{Debug, Formatter,Display};
|
||||||
use crate::action::Action;
|
use crate::action::Action;
|
||||||
use crate::specs::{Buff, BuffState, Recipe, Stats, Success};
|
use crate::specs::{Buff, BuffState, Recipe, Stats, Success};
|
||||||
|
|
|
||||||
28
src/io.rs
28
src/io.rs
|
|
@ -55,6 +55,16 @@ pub struct SolverResult{
|
||||||
#[pyo3(get)]
|
#[pyo3(get)]
|
||||||
pub durability: i32,
|
pub durability: i32,
|
||||||
#[pyo3(get)]
|
#[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>,
|
pub actions: Vec<String>,
|
||||||
#[pyo3(get)]
|
#[pyo3(get)]
|
||||||
pub step1_solutions: usize,
|
pub step1_solutions: usize,
|
||||||
|
|
@ -72,6 +82,7 @@ impl Display for SolverResult{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// #[pymethods]
|
||||||
impl SolverResult{
|
impl SolverResult{
|
||||||
pub fn from_craft(craft: & Craft,step1_solutions : usize,step2_solutions : usize, found_100_percent: bool)->SolverResult{
|
pub fn from_craft(craft: & Craft,step1_solutions : usize,step2_solutions : usize, found_100_percent: bool)->SolverResult{
|
||||||
// Todo: recreate actions
|
// Todo: recreate actions
|
||||||
|
|
@ -95,21 +106,38 @@ impl SolverResult{
|
||||||
step1_solutions,
|
step1_solutions,
|
||||||
step2_solutions,
|
step2_solutions,
|
||||||
found_100_percent,
|
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{
|
pub fn default()->Self{
|
||||||
Self{
|
Self{
|
||||||
steps:0,
|
steps:0,
|
||||||
progression: 0,
|
progression: 0,
|
||||||
quality:0,
|
quality:0,
|
||||||
durability:0,
|
durability:0,
|
||||||
|
total_progression:0,
|
||||||
|
total_quality:0,
|
||||||
|
total_durability:0,
|
||||||
actions:vec!["Act1".to_string(),"Act2".to_string()],
|
actions:vec!["Act1".to_string(),"Act2".to_string()],
|
||||||
step1_solutions:0,
|
step1_solutions:0,
|
||||||
step2_solutions:0,
|
step2_solutions:0,
|
||||||
found_100_percent:false,
|
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
|
/// Python Bindings
|
||||||
|
|
|
||||||
36
src/lib.rs
36
src/lib.rs
|
|
@ -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
|
/// Find the route with the least amount of steps
|
||||||
pub fn find_fast_route(routes: &Option<Vec<SolverResult>>) -> Option<&SolverResult>{
|
pub fn find_fast_route(routes: &Option<Vec<SolverResult>>) -> Option<&SolverResult>{
|
||||||
let res = match routes {
|
match routes {
|
||||||
Some(route) => route.iter().min_by_key(|key| key.steps),
|
Some(_routes) => {
|
||||||
None => None,
|
if _routes.len()>0{
|
||||||
};
|
if _routes[0].found_100_percent {
|
||||||
res
|
_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
|
/// Find the route with the maximum amount of quality
|
||||||
pub fn find_quality_route(routes: &Option<Vec<SolverResult>>) -> Option<&SolverResult>{
|
pub fn find_quality_route(routes: &Option<Vec<SolverResult>>) -> Option<&SolverResult>{
|
||||||
match routes {
|
match routes {
|
||||||
Some(route) => route.iter().max_by_key(|key| key.quality),
|
Some(_routes) => _routes.iter().max_by_key(|key| key.quality),
|
||||||
None => None,
|
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
|
/// Find the route with the maximum of durability left
|
||||||
pub fn find_safe_route(routes: &Option<Vec<SolverResult>>) -> Option<&SolverResult>{
|
pub fn find_safe_route(routes: &Option<Vec<SolverResult>>) -> Option<&SolverResult>{
|
||||||
match routes {
|
match routes {
|
||||||
Some(route) => route.iter().min_by_key(|key| key.durability),
|
Some(_routes) => {
|
||||||
None => None,
|
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,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue