diff --git a/src/action.rs b/src/action.rs index 84c6d1a..513927c 100644 --- a/src/action.rs +++ b/src/action.rs @@ -179,6 +179,8 @@ pub struct ActionList { pub veneration: Action, pub great_strides: Action, pub innovation: Action, + //pub observe: Action, + //pub focused_synthesis: Action, } impl Default for ActionList { @@ -208,6 +210,10 @@ impl Default for ActionList { veneration: ActionBuilder::new("Veneration").cp(18).buff(Some((Buff::Veneration, 4))).build(), great_strides: ActionBuilder::new("Great Strides").cp(32).buff(Some((Buff::GreatStrides, 3))).build(), innovation: ActionBuilder::new("Innovation").cp(18).buff(Some((Buff::Innovation, 4))).build(), + + // Todo: Add back + //observe: ActionBuilder::new("observe").cp(18).buff(Some((Buff::Observe, 1))).build(), + //focused_synthesis: ActionBuilder::new("focused_synthesis").cp(18).quality(100).build(), } } } diff --git a/src/craft.rs b/src/craft.rs index 242d66e..577ffa0 100644 --- a/src/craft.rs +++ b/src/craft.rs @@ -1,3 +1,4 @@ +use crate::action::ACTIONS; use std::fmt::{Debug, Formatter,Display}; use crate::action::Action; use crate::specs::{Buff, BuffState, Recipe, Stats, Success}; @@ -70,6 +71,20 @@ impl<'a> Craft<'a> { self.actions.push(action); return self; } + + // Assumes the craft is finished and tries to add the last actions + // pub fn add_last_actions(&mut self)->&Self{ + // let arg = (self.recipe.progress as f32 - self.progression as f32) / self.get_base_progression() as f32; + // self.durability+=10; + // if 0.0 < arg && arg < 1.2 { self.run_action(&ACTIONS.basic_synthesis);} + // if 1.2 <= arg && arg < 1.8 { self.cp+=7; self.run_action(&ACTIONS.careful_synthesis); } + // if 1.8 <= arg && arg < 2.0 { + // self.cp+=12; + // self.run_action(&ACTIONS.observe); + // self.run_action(&ACTIONS.focused_synthesis); + // } + // self + // } } impl<'a> Debug for Craft<'a> { diff --git a/src/io.rs b/src/io.rs index 3fc6c9c..8e73d85 100644 --- a/src/io.rs +++ b/src/io.rs @@ -57,9 +57,9 @@ pub struct SolverResult{ #[pyo3(get)] pub actions: Vec, #[pyo3(get)] - pub step1_solutions: u32, + pub step1_solutions: usize, #[pyo3(get)] - pub step2_solutions: u32, + pub step2_solutions: usize, } #[pyfunction] @@ -79,6 +79,7 @@ pub fn pouet()-> SolverResult { /// Pretty display for SolverResult impl Display for SolverResult{ + fn fmt(&self, _f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { println!("{:?}",self.actions); Ok(()) @@ -87,21 +88,41 @@ impl Display for SolverResult{ impl SolverResult{ - pub fn from_craft(&self,craft: & Craft)->SolverResult{ + pub fn from_craft(craft: & Craft,step1_solutions : usize,step2_solutions : usize)->SolverResult{ // Todo: recreate actions // Where steps ? + let mut actions = craft.actions.iter().map(|action| + format!("{}",action.short_name) + ).collect::>(); + let arg = (craft.recipe.progress as f32 - craft.progression as f32) / craft.get_base_progression() as f32; + if 0.0 < arg && arg < 1.2 { actions.push("basicSynth2".to_string()); } + if 1.2 <= arg && arg < 1.8 { actions.push("carefulSynthesis".to_string()); } + if 1.8 <= arg && arg < 2.0 { + actions.push("observe".to_string()); + actions.push("focusedSynthesis".to_string()); + } SolverResult{ steps:craft.step_count, progression: craft.progression, quality:craft.quality, durability:craft.durability, + actions:actions, + step1_solutions, + step2_solutions, + } + + } + pub fn default()->Self{ + Self{ + steps:0, + progression: 0, + quality:0, + durability:0, actions:vec!["BLLLL".to_string(),"WWWWW".to_string()], step1_solutions:0, step2_solutions:0, } - } - } diff --git a/src/lib.rs b/src/lib.rs index 495058a..b87a64a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,4 @@ +use crate::io::SolverResult; use crate::{ craft::Craft, specs::{Recipe,Stats}, @@ -26,7 +27,7 @@ pub mod io; /// Solve the craft with given arguments, this functions calls threads and must own it's values -pub fn solve_craft<'a>(recipe: Recipe, stats: Stats, params: Parameters) -> Option>>{ +pub fn solve_craft<'a>(recipe: Recipe, stats: Stats, params: Parameters) -> Option>{ // Load the craft with given arguments let craft = Craft::new(recipe,stats,params); @@ -79,59 +80,60 @@ pub fn solve_craft<'a>(recipe: Recipe, stats: Stats, params: Parameters) -> Opti // Prune the results for analysis let mut valid_routes : Vec = vec![]; + let mut valid_solutions: Vec = vec![]; 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)); } } // If no craft can make it to 100% HQ, fallback to base results - if valid_routes.len()==0{ - for route in phase2_routes.iter(){valid_routes.push(route.clone())} // Deep copy through the mutex guard + if valid_solutions.len()==0{ + for route in phase2_routes.iter(){valid_solutions.push(SolverResult::from_craft(route,nb_p1,nb_p2));} } //// 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!("[P2] No route could finish the craft.\n[P2] Runtime {}ms. Now exiting...",now.elapsed().as_millis()); - return None; - }, - }; + // 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::>(); - + // let mut content = (&top_route.actions) + // .iter() + // .map(|action| { + // format!("\"{}\"", action.short_name.clone()) + // }) + // .collect::>(); // 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()); - } + // 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); - } + // #[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(", ")); - } + // { + // println!("Quality: {}/{}", top_route.quality, top_route.recipe.quality); + // println!("\t[{}]", content.join(", ")); + // } - Some(valid_routes) + Some(valid_solutions) } /// Load the config from args and make a craft from it @@ -210,9 +212,26 @@ pub fn load_from_config<'a>(recipe_name: &str, file_name: &str, character_name: // SAFEST, // SHORTEST, // } -pub fn print_routes<'a>(routes: Option>>){ + +pub fn print_routes<'a>(routes: Option>){ match routes{ - Some(r) => println!("{:?}",r), - None => println!("Noooooooooooooo") + Some(r) => { + for c in r.iter(){ + println!("\n[{}ยค][{}@][{}#] {:?} ",c.quality,c.durability,c.steps,c.actions) + } + }, + None => println!("No routes to print") } +} + +pub fn find_fast_route(routes: Option>){ + +} + +pub fn find_quality_route(routes: Option>){ + +} + +pub fn find_(routes: Option>){ + } \ No newline at end of file diff --git a/src/specs.rs b/src/specs.rs index cf5454e..ccfcd08 100644 --- a/src/specs.rs +++ b/src/specs.rs @@ -33,7 +33,7 @@ pub enum Buff { // v Hidden v BasicTouch, StandardTouch, - // Observe, + Observe, } #[derive(Debug, Clone, Copy)] @@ -47,6 +47,7 @@ pub struct BuffState { pub muscle_memory: u8, pub basic_touch: u8, pub standard_touch: u8, + pub observe: u8, } impl BuffState { @@ -61,6 +62,7 @@ impl BuffState { muscle_memory: 0, basic_touch: 0, standard_touch: 0, + observe: 0, } } @@ -75,6 +77,7 @@ impl BuffState { Buff::MuscleMemory => self.muscle_memory = 0, Buff::BasicTouch => self.basic_touch = 0, Buff::StandardTouch => self.standard_touch = 0, + Buff::Observe => self.observe = 0, } } @@ -95,6 +98,7 @@ impl BuffState { Buff::MuscleMemory => self.muscle_memory = value, Buff::BasicTouch => self.basic_touch = value, Buff::StandardTouch => self.standard_touch = value, + Buff::Observe => self.standard_touch = value, } }