Improvement(Bindings) - Good implementation so far
This commit is contained in:
parent
420256034d
commit
bc28e51db4
|
|
@ -1,5 +1,4 @@
|
|||
// #![warn(missing_docs,unsafe_code,unstable_features,)]
|
||||
use xiv_craft_solver::print_routes;
|
||||
use std::time::{Instant};
|
||||
use clap::Parser;
|
||||
use xiv_craft_solver;
|
||||
|
|
@ -22,9 +21,29 @@ fn main() {
|
|||
let (recipe,stats) = xiv_craft_solver::load_from_config(&args.recipe_name, &args.file_name, &args.character_name);
|
||||
let results = xiv_craft_solver::solve_craft(recipe,stats,params);
|
||||
|
||||
// Show results
|
||||
// Stop timer
|
||||
let t_final = now.elapsed().as_millis();
|
||||
print_routes(results);
|
||||
|
||||
// Show best results
|
||||
#[cfg(feature = "verbose")]
|
||||
if args.verbose>0{
|
||||
print_routes(results);
|
||||
}
|
||||
|
||||
// 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));
|
||||
|
||||
#[cfg(feature = "verbose")]
|
||||
if params.verbose>2{
|
||||
println!("[F] Top route {:?}",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);
|
||||
|
|
|
|||
31
src/io.rs
31
src/io.rs
|
|
@ -60,35 +60,20 @@ pub struct SolverResult{
|
|||
pub step1_solutions: usize,
|
||||
#[pyo3(get)]
|
||||
pub step2_solutions: usize,
|
||||
}
|
||||
|
||||
#[pyfunction]
|
||||
pub fn pouet()-> SolverResult {
|
||||
// return "pouet";
|
||||
SolverResult{
|
||||
steps:0,
|
||||
progression: 0,
|
||||
quality:0,
|
||||
durability:0,
|
||||
actions:vec!["BLLLL".to_string(),"WWWWW".to_string()],
|
||||
step1_solutions:0,
|
||||
step2_solutions:0,
|
||||
|
||||
}
|
||||
#[pyo3(get)]
|
||||
pub found_100_percent: bool,
|
||||
}
|
||||
|
||||
/// Pretty display for SolverResult
|
||||
impl Display for SolverResult{
|
||||
|
||||
fn fmt(&self, _f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
|
||||
println!("{:?}",self.actions);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl SolverResult{
|
||||
pub fn from_craft(craft: & Craft,step1_solutions : usize,step2_solutions : usize)->SolverResult{
|
||||
pub fn from_craft(craft: & Craft,step1_solutions : usize,step2_solutions : usize, found_100_percent: bool)->SolverResult{
|
||||
// Todo: recreate actions
|
||||
// Where steps ?
|
||||
let mut actions = craft.actions.iter().map(|action|
|
||||
|
|
@ -109,6 +94,7 @@ impl SolverResult{
|
|||
actions:actions,
|
||||
step1_solutions,
|
||||
step2_solutions,
|
||||
found_100_percent,
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -118,14 +104,14 @@ impl SolverResult{
|
|||
progression: 0,
|
||||
quality:0,
|
||||
durability:0,
|
||||
actions:vec!["BLLLL".to_string(),"WWWWW".to_string()],
|
||||
actions:vec!["Act1".to_string(),"Act2".to_string()],
|
||||
step1_solutions:0,
|
||||
step2_solutions:0,
|
||||
found_100_percent:false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Python Bindings
|
||||
|
||||
/// A Python module implemented in Rust.
|
||||
|
|
@ -136,6 +122,7 @@ fn xiv_craft_solver(_py: Python, m: &PyModule) -> PyResult<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn e(){
|
||||
|
||||
#[pyfunction]
|
||||
pub fn pouet()-> SolverResult {
|
||||
SolverResult::default()
|
||||
}
|
||||
84
src/lib.rs
84
src/lib.rs
|
|
@ -84,55 +84,14 @@ pub fn solve_craft<'a>(recipe: Recipe, stats: Stats, params: Parameters) -> Opti
|
|||
for route in phase2_routes.iter(){
|
||||
if route.quality>=route.recipe.quality{
|
||||
valid_routes.push(route.clone());
|
||||
valid_solutions.push(SolverResult::from_craft(route,nb_p1,nb_p2));
|
||||
valid_solutions.push(SolverResult::from_craft(route,nb_p1,nb_p2,true));
|
||||
}
|
||||
}
|
||||
// If no craft can make it to 100% HQ, fallback to base results
|
||||
if valid_solutions.len()==0{
|
||||
for route in phase2_routes.iter(){valid_solutions.push(SolverResult::from_craft(route,nb_p1,nb_p2));}
|
||||
for route in phase2_routes.iter(){valid_solutions.push(SolverResult::from_craft(route,nb_p1,nb_p2,false));}
|
||||
}
|
||||
|
||||
|
||||
//// Show best results
|
||||
// Select best route TODO: Seperate function
|
||||
// let top_route = match valid_routes.iter().max_by_key(|route| route.quality) {
|
||||
// Some(top) => top,
|
||||
// None => {
|
||||
// #[cfg(feature = "verbose")]
|
||||
// println!("[F] No route could finish the craft.\n[P2] Runtime {}ms. Now exiting...",now.elapsed().as_millis());
|
||||
// return None;
|
||||
// },
|
||||
// };
|
||||
|
||||
// Print best route TODO: Seperate function
|
||||
// let mut content = (&top_route.actions)
|
||||
// .iter()
|
||||
// .map(|action| {
|
||||
// format!("\"{}\"", action.short_name.clone())
|
||||
// })
|
||||
// .collect::<Vec<String>>();
|
||||
|
||||
// Setting something to print, adding the missing actions TODO: Change this behaviour and move to separate function
|
||||
// let arg = (top_route.recipe.progress as f32 - top_route.progression as f32) / top_route.get_base_progression() as f32;
|
||||
// if 0.0 < arg && arg < 1.2 { content.push("\"basicSynth2\"".to_string()); }
|
||||
// if 1.2 <= arg && arg < 1.8 { content.push("\"carefulSynthesis\"".to_string()); }
|
||||
// if 1.8 <= arg && arg < 2.0 {
|
||||
// content.push("\"observe\"".to_string());
|
||||
// content.push("\"focusedSynthesis\"".to_string());
|
||||
// }
|
||||
|
||||
// #[cfg(feature = "verbose")]
|
||||
// if params.verbose>2{
|
||||
// println!("[F] Top route {:?}",top_route);
|
||||
// }
|
||||
|
||||
// {
|
||||
// println!("Quality: {}/{}", top_route.quality, top_route.recipe.quality);
|
||||
// println!("\t[{}]", content.join(", "));
|
||||
// }
|
||||
|
||||
|
||||
|
||||
Some(valid_solutions)
|
||||
}
|
||||
|
||||
|
|
@ -202,20 +161,11 @@ pub fn load_from_config<'a>(recipe_name: &str, file_name: &str, character_name:
|
|||
(recipe,stats)
|
||||
}
|
||||
|
||||
// fn make_craft_from_values(){
|
||||
|
||||
// }
|
||||
|
||||
// /// Print results
|
||||
// enum SHOW_TYPE{
|
||||
// BEST,
|
||||
// SAFEST,
|
||||
// SHORTEST,
|
||||
// }
|
||||
|
||||
/// Print all routes in the vect, verbose
|
||||
pub fn print_routes<'a>(routes: Option<Vec<SolverResult>>){
|
||||
match routes{
|
||||
Some(r) => {
|
||||
println!("Showing {} routes",r.len());
|
||||
for c in r.iter(){
|
||||
println!("\n[{}¤][{}@][{}#] {:?} ",c.quality,c.durability,c.steps,c.actions)
|
||||
}
|
||||
|
|
@ -224,14 +174,28 @@ pub fn print_routes<'a>(routes: Option<Vec<SolverResult>>){
|
|||
}
|
||||
}
|
||||
|
||||
pub fn find_fast_route(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
|
||||
}
|
||||
|
||||
pub fn find_quality_route(routes: Option<Vec<SolverResult>>){
|
||||
|
||||
/// 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),
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn find_(routes: Option<Vec<SolverResult>>){
|
||||
|
||||
/// 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,
|
||||
}
|
||||
}
|
||||
Reference in New Issue