Merge pull request 'danturin' (#2) from danturin into maturin
Reviewed-on: Dandaedre/rcraft_solver#2
This commit is contained in:
commit
fb2818c3f9
|
|
@ -17,6 +17,9 @@ threadpool = "1.8.1"
|
|||
# For python bindings TODO: make it optionnal
|
||||
pyo3 = { version = "0.18.0", features = ["extension-module"] }
|
||||
|
||||
# [target.'cfg(not(no_python))'.dependencies]
|
||||
# pyo3 = { version = "0.18.0", features = ["extension-module"] }
|
||||
|
||||
# [build]
|
||||
# target = ["x86_64-unknown-linux-gnu", "x86_64-unknown-windows-gnu"]
|
||||
|
||||
|
|
@ -24,11 +27,11 @@ pyo3 = { version = "0.18.0", features = ["extension-module"] }
|
|||
panic = 'abort'
|
||||
opt-level = 3
|
||||
lto = true
|
||||
vere0 = false
|
||||
|
||||
[features]
|
||||
default = []
|
||||
verbose = []
|
||||
no_python = []
|
||||
|
||||
[lib]
|
||||
name = "xiv_craft_solver"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,32 @@
|
|||
import xiv_craft_solver
|
||||
import rich
|
||||
|
||||
rich.inspect(xiv_craft_solver)
|
||||
rich.inspect(xiv_craft_solver.test_result)
|
||||
rich.inspect(xiv_craft_solver.test_result())
|
||||
rich.inspect(xiv_craft_solver.test_result())
|
||||
|
||||
|
||||
class feedMeDaddy:
|
||||
durability = 70
|
||||
progress = 3900
|
||||
quality = 10920
|
||||
progress_divider = 130
|
||||
quality_divider = 115
|
||||
progress_modifier = 80
|
||||
quality_modifier = 70
|
||||
craftsmanship = 4041
|
||||
control = 3959
|
||||
max_cp = 602
|
||||
|
||||
# Config
|
||||
depth=10
|
||||
byregot_step=10
|
||||
desperate=False
|
||||
threads=8
|
||||
verbose=0
|
||||
|
||||
|
||||
el_daddy=feedMeDaddy()
|
||||
rich.inspect(xiv_craft_solver.solve_from_python(el_daddy))
|
||||
|
||||
|
|
@ -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(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
// #![warn(missing_docs,unsafe_code,unstable_features,)]
|
||||
use std::time::{Instant};
|
||||
use clap::Parser;
|
||||
use xiv_craft_solver;
|
||||
|
||||
|
|
@ -6,15 +7,53 @@ use xiv_craft_solver;
|
|||
struct CustomError(String);
|
||||
|
||||
fn main() {
|
||||
let args = xiv_craft_solver::Args::parse();
|
||||
let params = xiv_craft_solver::Parameters{
|
||||
depth: args.depth,
|
||||
threads: args.threads,
|
||||
verbose: args.verbose,
|
||||
};
|
||||
let args = xiv_craft_solver::io::Args::parse();
|
||||
let params = xiv_craft_solver::io::Parameters::from_args(&args);
|
||||
|
||||
// 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);
|
||||
xiv_craft_solver::solve_craft(recipe,stats,params);
|
||||
let results = xiv_craft_solver::solve_craft(recipe,stats,params);
|
||||
|
||||
// Stop timer
|
||||
let t_final = now.elapsed().as_millis();
|
||||
|
||||
|
||||
|
||||
// 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] <");
|
||||
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 routes {:?}",results);
|
||||
// }
|
||||
|
||||
// Wait for user input
|
||||
println!("\nProgram finished successfully in {}ms\nPress enter to exit...", t_final);
|
||||
let mut input = String::new(); std::io::stdin().read_line(&mut input).unwrap();
|
||||
()
|
||||
}
|
||||
15
src/craft.rs
15
src/craft.rs
|
|
@ -3,7 +3,6 @@ use crate::action::Action;
|
|||
use crate::specs::{Buff, BuffState, Recipe, Stats, Success};
|
||||
use crate::Parameters;
|
||||
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Craft<'a> {
|
||||
pub recipe: Recipe,
|
||||
|
|
@ -70,6 +69,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> {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,225 @@
|
|||
use crate::Craft;
|
||||
use core::fmt::Display;
|
||||
use clap::Parser;
|
||||
|
||||
#[cfg(not(feature="no_python"))]
|
||||
use pyo3::prelude::*;
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Parameters {
|
||||
pub threads: usize,
|
||||
pub verbose: u8,
|
||||
pub depth: u32,
|
||||
pub desperate:bool,
|
||||
pub byregot_step: u8,
|
||||
}
|
||||
|
||||
#[derive(Parser, Debug, Clone)]
|
||||
#[command(author, version, about, long_about = None)]
|
||||
pub struct Args {
|
||||
/// Name of the receipe
|
||||
#[arg(short, long, default_value_t = String::from("default_recipe"))]
|
||||
pub recipe_name: String,
|
||||
|
||||
/// Name of the character
|
||||
#[arg(short, long, default_value_t = String::from("default_character"))]
|
||||
pub character_name: String,
|
||||
|
||||
/// The ml file name
|
||||
#[arg(short, long, default_value_t = String::from("craft.toml"))]
|
||||
pub file_name: String,
|
||||
|
||||
/// The verbose flag
|
||||
#[arg(short, long, action = clap::ArgAction::Count)]
|
||||
pub verbose: u8,
|
||||
|
||||
/// The depth of the first pass
|
||||
#[arg(short, long, default_value_t = 8)]
|
||||
pub depth: u32,
|
||||
|
||||
/// 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,
|
||||
}
|
||||
|
||||
|
||||
/// A final stripped down version of a craft
|
||||
/// used for final print and talking with python
|
||||
#[derive(Debug)]
|
||||
#[pyclass]
|
||||
pub struct SolverResult{
|
||||
#[pyo3(get)]
|
||||
pub steps: u32,
|
||||
#[pyo3(get)]
|
||||
pub quality: u32,
|
||||
#[pyo3(get)]
|
||||
pub progression: u32,
|
||||
#[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,
|
||||
#[pyo3(get)]
|
||||
pub step2_solutions: usize,
|
||||
#[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(())
|
||||
}
|
||||
}
|
||||
|
||||
//#[pymethods]
|
||||
impl 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|
|
||||
format!("{}",action.short_name)
|
||||
).collect::<Vec<String>>();
|
||||
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,
|
||||
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,
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#[pymethods]
|
||||
impl SolverResult{
|
||||
#[staticmethod]
|
||||
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 : [{}/{}] | 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.
|
||||
#[cfg(not(feature="no_python"))]
|
||||
#[pymodule]
|
||||
fn xiv_craft_solver(_py: Python, m: &PyModule) -> PyResult<()> {
|
||||
m.add_function(wrap_pyfunction!(test_result, m)?)?;
|
||||
m.add_function(wrap_pyfunction!(solve_from_python, m)?)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
///
|
||||
#[cfg(not(feature="no_python"))]
|
||||
#[pyfunction]
|
||||
pub fn test_result()-> SolverResult {
|
||||
SolverResult::default()
|
||||
}
|
||||
|
||||
/// Create a stat struct stats with the base values
|
||||
#[cfg(not(feature="no_python"))]
|
||||
use crate::{Recipe,Stats,solve_craft};
|
||||
|
||||
#[cfg(not(feature="no_python"))]
|
||||
#[pyfunction]
|
||||
pub fn solve_from_python(values : &PyAny)->PyResult<Option<Vec<SolverResult>>>{
|
||||
// // Create Recipe
|
||||
let recipe = Recipe{
|
||||
durability: values.getattr("durability")?.extract()?,
|
||||
progress: values.getattr("progress")?.extract()?,
|
||||
progress_divider: values.getattr("progress_divider")?.extract()?,
|
||||
progress_modifier: values.getattr("progress_modifier")?.extract()?,
|
||||
quality: values.getattr("quality")?.extract()?,
|
||||
quality_divider:values.getattr("quality_divider")?.extract()?,
|
||||
quality_modifier:values.getattr("quality_modifier")?.extract()?,
|
||||
};
|
||||
|
||||
// Create Stats
|
||||
let stats = Stats{
|
||||
craftsmanship: values.getattr("craftsmanship")?.extract()?,
|
||||
control: values.getattr("control")?.extract()?,
|
||||
max_cp: values.getattr("max_cp")?.extract()?,
|
||||
};
|
||||
|
||||
// Create parameters
|
||||
let param = Parameters{
|
||||
depth: values.getattr("depth")?.extract()?,
|
||||
byregot_step: values.getattr("byregot_step")?.extract()?,
|
||||
desperate: values.getattr("desperate")?.extract()?,
|
||||
threads: values.getattr("threads")?.extract()?,
|
||||
verbose: values.getattr("verbose")?.extract()?,
|
||||
};
|
||||
|
||||
// println!("{:?} len: {:?} ",values,values.getattr("len()"));
|
||||
let res = solve_craft(recipe, stats, param);
|
||||
Ok(res)
|
||||
}
|
||||
216
src/lib.rs
216
src/lib.rs
|
|
@ -1,72 +1,22 @@
|
|||
use crate::io::SolverResult;
|
||||
use crate::{
|
||||
craft::Craft,
|
||||
specs::{Recipe,Stats},
|
||||
io::Parameters,
|
||||
};
|
||||
use std::time::{Instant};
|
||||
use threadpool::ThreadPool;
|
||||
use std::sync::{Arc,Mutex};
|
||||
use clap::Parser;
|
||||
use pyo3::prelude::*;
|
||||
|
||||
mod solver;
|
||||
mod specs;
|
||||
pub mod action;
|
||||
pub mod craft;
|
||||
pub mod io;
|
||||
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Parameters {
|
||||
pub threads: usize,
|
||||
pub verbose: u8,
|
||||
pub depth: u32,
|
||||
}
|
||||
|
||||
#[derive(Parser, Debug, Clone)]
|
||||
#[command(author, version, about, long_about = None)]
|
||||
pub struct Args {
|
||||
/// Name of the receipe
|
||||
#[arg(short, long, default_value_t = String::from("default_recipe"))]
|
||||
pub recipe_name: String,
|
||||
|
||||
/// Name of the character
|
||||
#[arg(short, long, default_value_t = String::from("default_character"))]
|
||||
pub character_name: String,
|
||||
|
||||
/// The ml file name
|
||||
#[arg(short, long, default_value_t = String::from("craft.toml"))]
|
||||
pub file_name: String,
|
||||
|
||||
/// The verbose flag
|
||||
#[arg(short, long, action = clap::ArgAction::Count)]
|
||||
pub verbose: u8,
|
||||
|
||||
/// The depth of the first pass
|
||||
#[arg(short, long, default_value_t = 8)]
|
||||
pub depth: u32,
|
||||
|
||||
/// Thread counts, default is 4 (can you even run ff with less ?)
|
||||
#[arg(short, long, default_value_t = 4)]
|
||||
pub threads: usize,
|
||||
}
|
||||
|
||||
#[pyfunction]
|
||||
pub fn pouet()-> &'static str {
|
||||
return "pouet";
|
||||
}
|
||||
|
||||
/// A Python module implemented in Rust.
|
||||
#[pymodule]
|
||||
fn xiv_craft_solver(_py: Python, m: &PyModule) -> PyResult<()> {
|
||||
m.add_function(wrap_pyfunction!(pouet, m)?)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Solve the craft with given arguments
|
||||
pub fn solve_craft<'a>(recipe: Recipe, stats: Stats, params: Parameters) -> Option<Vec<Craft<'a>>>{
|
||||
/// 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<Vec<SolverResult>>{
|
||||
// Load the craft with given arguments
|
||||
let craft = Craft::new(recipe,stats,params);
|
||||
// Start timer
|
||||
let now = Instant::now();
|
||||
|
||||
// Start a threadpool
|
||||
let pool = ThreadPool::new(params.threads);
|
||||
|
|
@ -76,23 +26,18 @@ pub fn solve_craft<'a>(recipe: Recipe, stats: Stats, params: Parameters) -> Opti
|
|||
println!("Solving...\n");
|
||||
println!("[P1] Starting phase 1...");
|
||||
}
|
||||
|
||||
let phase1_routes = solver::generate_routes_phase1(craft);
|
||||
|
||||
let nb_p1 = phase1_routes.len();
|
||||
|
||||
#[cfg(feature = "verbose")]
|
||||
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.progression * 100 / r.recipe.progress,
|
||||
r.quality * 100 / r.recipe.quality,
|
||||
r.cp,
|
||||
r.durability,
|
||||
);
|
||||
};
|
||||
}
|
||||
if params.verbose>1{ for r in &phase1_routes{
|
||||
println!("[P1] {:?} p:{}% q:{}% c:{} d:{}",r.actions,r.progression,r.quality * 100 / r.recipe.quality,r.cp,r.durability);
|
||||
}}
|
||||
}
|
||||
|
||||
// Core algorithm, fill all found routes with the best route (doesn't branch, just replace)
|
||||
let arc_phase2_routes = Arc::new(Mutex::new(Vec::<Craft>::new()));
|
||||
|
||||
|
|
@ -109,83 +54,37 @@ pub fn solve_craft<'a>(recipe: Recipe, stats: Stats, params: Parameters) -> Opti
|
|||
|
||||
pool.join();
|
||||
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{
|
||||
println!("[P2] Found {} solutions, sorting",phase2_routes.len());
|
||||
|
||||
if params.verbose>1{
|
||||
for r in phase2_routes.iter(){
|
||||
println!("[P2] {:?} p:{}% q:{}% d:{}",
|
||||
r.actions,
|
||||
r.progression * 100 / r.recipe.progress,
|
||||
r.quality * 100 / r.recipe.quality,
|
||||
r.durability);
|
||||
};
|
||||
}
|
||||
if params.verbose>1{ for r in phase2_routes.iter(){
|
||||
println!("[P2] {:?} p:{}% q:{}% d:{}", r.actions, r.progression * 100 / r.recipe.progress, r.quality * 100 / r.recipe.quality, r.durability);
|
||||
}}
|
||||
}
|
||||
|
||||
// Copy the valid results for analysis, by default only the valid one are copied
|
||||
// Prune the results for analysis
|
||||
let mut valid_routes : Vec<Craft> = vec![];
|
||||
let mut valid_solutions: Vec<SolverResult> = 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,true));
|
||||
}
|
||||
}
|
||||
|
||||
if valid_routes.len()==0{
|
||||
for route in phase2_routes.iter(){valid_routes.push(route.clone())} // Deep copy through the mutex guard
|
||||
// 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,false));}
|
||||
}
|
||||
|
||||
|
||||
// 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;
|
||||
},
|
||||
};
|
||||
|
||||
// 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(", "));
|
||||
}
|
||||
|
||||
// Wait for enter TODO: Remove
|
||||
println!();
|
||||
println!("Program finished sucessfuly in {}ms and found {} solutions, [prog:{}]",
|
||||
now.elapsed().as_millis(),
|
||||
phase2_routes.len(),
|
||||
top_route.recipe.progress);
|
||||
println!("Press enter to exit...");
|
||||
let mut input = String::new();
|
||||
std::io::stdin().read_line(&mut input).unwrap();
|
||||
Some(valid_routes)
|
||||
Some(valid_solutions)
|
||||
}
|
||||
|
||||
/// Load the config from args and make a craft from it
|
||||
|
|
@ -254,6 +153,59 @@ pub fn load_from_config<'a>(recipe_name: &str, file_name: &str, character_name:
|
|||
(recipe,stats)
|
||||
}
|
||||
|
||||
// fn make_craft_from_values(){
|
||||
/// 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)
|
||||
}
|
||||
},
|
||||
None => println!("No routes to print")
|
||||
}
|
||||
}
|
||||
|
||||
// }
|
||||
/// Find the route with the least amount of steps
|
||||
pub fn find_fast_route(routes: &Option<Vec<SolverResult>>) -> Option<&SolverResult>{
|
||||
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(_routes) => _routes.iter().max_by_key(|key| key.quality),
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Find the route with the maximum of durability left
|
||||
pub fn find_safe_route(routes: &Option<Vec<SolverResult>>) -> Option<&SolverResult>{
|
||||
match routes {
|
||||
Some(_routes) => {
|
||||
if _routes.len()>0{
|
||||
//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)
|
||||
//}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
},
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
|
|
@ -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<Option<&'a Action>> {
|
||||
if craft.success != Success::Pending { return vec![None]; }
|
||||
let mut available_actions = Vec::<Option<&'a Action>>::new();
|
||||
|
|
@ -30,8 +31,10 @@ pub fn next_action_picker_1<'a>(craft: & Craft<'a>) -> Vec<Option<&'a Action>> {
|
|||
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<Option<&'a Action>> {
|
|||
result_actions
|
||||
}
|
||||
|
||||
|
||||
/// Find all routes that can finish in one more action
|
||||
pub fn generate_routes_phase1<'a>(craft: Craft<'a>) -> Vec<Craft<'a>> {
|
||||
let mut queue = Vec::new();
|
||||
queue.push(craft);
|
||||
|
|
@ -80,7 +85,6 @@ pub fn generate_routes_phase1<'a>(craft: Craft<'a>) -> Vec<Craft<'a>> {
|
|||
// 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<Craft<'a>> {
|
|||
}
|
||||
|
||||
|
||||
/// Find the list of authorised actions for this step
|
||||
pub fn next_action_phase_2<'a>(craft: & Craft<'a>) -> Vec<Option<&'a Action>> {
|
||||
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<Option<&'a Action>> {
|
|||
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<Option<&'a Action>> {
|
|||
}
|
||||
}
|
||||
let mut final_actions: Vec<Option<&Action>> = 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<Option<&'a Action>> {
|
|||
final_actions
|
||||
}
|
||||
|
||||
/// Apply all actions to the current route
|
||||
pub fn generate_routes_phase2<'a>(craft: Craft<'a>) -> Option<Craft<'a>> {
|
||||
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<Craft<'a>> = 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<Craft<'a>> {
|
|||
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);
|
||||
|
|
|
|||
|
|
@ -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,11 +98,11 @@ 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,
|
||||
}
|
||||
}
|
||||
|
||||
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; }
|
||||
|
|
|
|||
Reference in New Issue