diff --git a/src/bin/ffcraft.rs b/src/bin/ffcraft.rs index 55416ba..586749e 100644 --- a/src/bin/ffcraft.rs +++ b/src/bin/ffcraft.rs @@ -8,11 +8,7 @@ struct CustomError(String); fn main() { let args = xiv_craft_solver::io::Args::parse(); - let params = xiv_craft_solver::io::Parameters{ - depth: args.depth, - threads: args.threads, - verbose: args.verbose, - }; + let params = xiv_craft_solver::io::Parameters::from_args(&args); // Start timer let now = Instant::now(); @@ -25,13 +21,25 @@ fn main() { // Stop timer let t_final = now.elapsed().as_millis(); - // Show best results - #[cfg(feature = "verbose")] - if args.verbose>0{ - print_routes(results); - } + // Show best result depending on selected value + match results{ + None => { + println!("[Error] No solutions found for craft '{}' with crafter '{}' (ms)", args.recipe_name, args.character_name); + return + } + Some(ref res)=>{ + // Show best results + if args.verbose>0{ + println!("[Final] {} results were found:",res.len()); + #[cfg(feature = "verbose")] + if args.verbose>1{ + xiv_craft_solver::print_routes(&results); + } + } + }, + } println!("\n > SOLUTION [Least steps] <"); xiv_craft_solver::find_fast_route(&results).unwrap().pretty_print(); println!("\n > SOLUTION [Most durability] <"); @@ -39,10 +47,10 @@ fn main() { 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 routes {:?}",results); - } + // #[cfg(feature = "verbose")] + // if params.verbose>2{ + // println!("[F] Top routes {:?}",results); + // } // Wait for user input println!("\nProgram finished successfully in {}ms\nPress enter to exit...", t_final); diff --git a/src/io.rs b/src/io.rs index 3296820..c931a61 100644 --- a/src/io.rs +++ b/src/io.rs @@ -10,6 +10,8 @@ pub struct Parameters { pub threads: usize, pub verbose: u8, pub depth: u32, + pub desperate:bool, + pub byregot_step: u8, } #[derive(Parser, Debug, Clone)] @@ -35,9 +37,17 @@ pub struct Args { #[arg(short, long, default_value_t = 8)] pub depth: u32, - /// Thread counts, default is 4 (can you even run ff with less ?) + /// Thread counts, default is 4 #[arg(short, long, default_value_t = 4)] pub threads: usize, + + /// Desperate mode, will try to finish the craft above all + #[arg(short='D', long, default_value_t = false)] + pub desperate: bool, + + /// Long mode, will try to find more solutions, at the expense of time + #[arg(short='l', long, default_value_t = false)] + pub long: bool, } @@ -134,12 +144,24 @@ impl SolverResult{ } 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!("Quality: [{}/{}] | Durability: [{}/{}] | Cp : [{}/{}] | Steps : {}", + self.quality, self.total_quality, self.durability, self.total_durability, self.cp, self.total_cp, self.steps); println!("{:?}", self.actions); } } +impl Parameters{ + pub fn from_args(args:& Args) -> Self{ + Self{ + depth: if args.desperate{10}else{8}, + threads: args.threads, + verbose: args.verbose, + desperate: args.desperate, + byregot_step: if args.long{8}else{10} + } + } +} + /// Python Bindings /// A Python module implemented in Rust. diff --git a/src/lib.rs b/src/lib.rs index e2d1172..d547da8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -47,7 +47,7 @@ pub fn solve_craft<'a>(recipe: Recipe, stats: Stats, params: Parameters) -> Opti if params.verbose>0{ println!("[P1] Found {} routes, testing them all...",phase1_routes.len()); if params.verbose>1{ for r in &phase1_routes{ - println!("[P1] {:?} p:{}% q:{}% c:{} d:{}",r.actions,r.quality * 100 / r.recipe.quality,r.cp,r.durability); + println!("[P1] {:?} p:{}% q:{}% c:{} d:{}",r.actions,r.progression,r.quality * 100 / r.recipe.quality,r.cp,r.durability); }} } @@ -69,6 +69,11 @@ pub fn solve_craft<'a>(recipe: Recipe, stats: Stats, params: Parameters) -> Opti let phase2_routes = arc_phase2_routes.lock().unwrap(); let nb_p2 = phase2_routes.len(); + // Drop on empty results + if phase2_routes.len()==0{ + return None + } + // Print the results if verbose #[cfg(feature = "verbose")] if params.verbose>0{ @@ -162,7 +167,7 @@ pub fn load_from_config<'a>(recipe_name: &str, file_name: &str, character_name: } /// Print all routes in the vect, verbose -pub fn print_routes<'a>(routes: Option>){ +pub fn print_routes<'a>(routes: & Option>){ match routes{ Some(r) => { println!("Showing {} routes",r.len()); @@ -179,12 +184,12 @@ pub fn find_fast_route(routes: &Option>) -> Option<&SolverResu match routes { Some(_routes) => { if _routes.len()>0{ - if _routes[0].found_100_percent { + //if _routes[0].found_100_percent { _routes.iter().min_by_key(|key| key.steps) - } else { + //} else { // If the quality didn't reach 100% the fastest is meaningless - find_quality_route(routes) - } + // find_quality_route(routes) + //} } else { None } }, None => None, @@ -204,12 +209,12 @@ pub fn find_safe_route(routes: &Option>) -> Option<&SolverResu match routes { Some(_routes) => { if _routes.len()>0{ - if _routes[0].found_100_percent{ - _routes.iter().min_by_key(|key| key.durability) - } else { + //if _routes[0].found_100_percent{ + _routes.iter().max_by_key(|key| key.durability) + //} else { // If the craft didn't reach 100% quality the durability is meaningless - find_quality_route(routes) - } + // find_quality_route(routes) + //} } else { None } diff --git a/src/solver.rs b/src/solver.rs index 2730936..876661a 100644 --- a/src/solver.rs +++ b/src/solver.rs @@ -8,6 +8,7 @@ macro_rules! action_vec { ($($tt:expr),*) => { vec![ $(Some(&$tt),)*]}; } +/// Find the next authorised action for this step of the craft pub fn next_action_picker_1<'a>(craft: & Craft<'a>) -> Vec> { if craft.success != Success::Pending { return vec![None]; } let mut available_actions = Vec::>::new(); @@ -30,8 +31,10 @@ pub fn next_action_picker_1<'a>(craft: & Craft<'a>) -> Vec> { available_actions.append(&mut action_vec![ACTIONS.basic_synthesis,ACTIONS.careful_synthesis,ACTIONS.prudent_synthesis,ACTIONS.delicate_synthesis]); // ACTIONS.groundwork for the --pls - // available_actions.append(&mut action_vec![ACTIONS.groundwork]); - + if craft.args.desperate{ + available_actions.append(&mut action_vec![ACTIONS.groundwork]); + } + // For long first run if craft.step_count > 8 {available_actions.append(&mut action_vec![ACTIONS.waste_not_ii, ACTIONS.waste_not])}; @@ -46,6 +49,8 @@ pub fn next_action_picker_1<'a>(craft: & Craft<'a>) -> Vec> { result_actions } + +/// Find all routes that can finish in one more action pub fn generate_routes_phase1<'a>(craft: Craft<'a>) -> Vec> { let mut queue = Vec::new(); queue.push(craft); @@ -80,7 +85,6 @@ pub fn generate_routes_phase1<'a>(craft: Craft<'a>) -> Vec> { // 8 Seemed to be a good initial guess with enouth to use a good amount of WN / WNII to get close // A higher value will yield more initial guesses with minimal benefits // A lover value will yield less initial guesses and might spent too much CP to get to the required progression - // TODO: Pass a flag to get more attempts if craft.step_count < craft.args.depth { queue.push(craft); } } } @@ -88,6 +92,7 @@ pub fn generate_routes_phase1<'a>(craft: Craft<'a>) -> Vec> { } +/// Find the list of authorised actions for this step pub fn next_action_phase_2<'a>(craft: & Craft<'a>) -> Vec> { let mut available_actions = vec![&ACTIONS.basic_touch, &ACTIONS.prudent_touch, &ACTIONS.preparatory_touch]; let mut forbidden_actions = Vec::new(); @@ -125,7 +130,7 @@ pub fn next_action_phase_2<'a>(craft: & Craft<'a>) -> Vec> { forbidden_actions.push(&ACTIONS.basic_touch); } // Todo, allow earlier byregot if the craft can be finished all the same (useless with always optimize on) - if craft.buffs.inner_quiet >= 8 { // 10 + if craft.buffs.inner_quiet >= 8 { //craft.args.byregot_step { // 10 available_actions.push(&ACTIONS.trained_finesse); available_actions.push(&ACTIONS.great_strides); } @@ -137,8 +142,7 @@ pub fn next_action_phase_2<'a>(craft: & Craft<'a>) -> Vec> { } } let mut final_actions: Vec> = Vec::new(); - //drop duplicates - + for action in available_actions { if !forbidden_actions.contains(&action) && !final_actions.iter().any(|a| a.unwrap() == action) { final_actions.push(Some(action)); @@ -147,10 +151,11 @@ pub fn next_action_phase_2<'a>(craft: & Craft<'a>) -> Vec> { final_actions } +/// Apply all actions to the current route pub fn generate_routes_phase2<'a>(craft: Craft<'a>) -> Option> { let mut queue = VecDeque::new(); - // println!("{}", ACTIONS.careful_synthesis.can_use(&craft)); + // Todo: Return a vec of relevant functions, instead of the most quality one let mut top_route: Option> = Some(craft.clone()); // Default route, no hq on that one queue.push_back(craft); @@ -166,8 +171,8 @@ pub fn generate_routes_phase2<'a>(craft: Craft<'a>) -> Option> { if action.unwrap() == &ACTIONS.byregot_blessing { if let Some(top_route) = &mut top_route { if top_route.quality < craft.quality { - // TODO: Should we erase the craft if the improvement is cosmetic (aka, already finished) - *top_route = craft; + // TODO: Return several routes, doing so will come at a big performance cost + *top_route = craft; } } else { top_route = Some(craft); diff --git a/src/specs.rs b/src/specs.rs index ccfcd08..8379d5f 100644 --- a/src/specs.rs +++ b/src/specs.rs @@ -103,7 +103,6 @@ impl BuffState { } pub fn tick(&mut self) { - if self.waste_not > 0 { self.waste_not -= 1; } if self.great_strides > 0 { self.great_strides -= 1; } if self.innovation > 0 { self.innovation -= 1; }