Automation(Fix)
This commit is contained in:
parent
de0f279d92
commit
2883f14d71
|
|
@ -0,0 +1,37 @@
|
|||
[tasks.format]
|
||||
install_crate = "rustfmt"
|
||||
command = "cargo"
|
||||
args = ["fmt", "--", "--emit=files"]
|
||||
|
||||
[tasks.clean]
|
||||
command = "cargo"
|
||||
args = ["clean"]
|
||||
|
||||
[tasks.remove_tmp]
|
||||
script_runner = "@shell"
|
||||
script = '''
|
||||
rm -rf releases
|
||||
rm -rf python/build
|
||||
rm -rf python/dist
|
||||
'''
|
||||
|
||||
[tasks.build]
|
||||
command = "cargo"
|
||||
args = ["build","--release","-q"]
|
||||
dependencies = ["clean"]
|
||||
|
||||
[tasks.maturin]
|
||||
command = "maturin"
|
||||
args = ["develop", "--release", "-q"]
|
||||
|
||||
[tasks.rust]
|
||||
dependencies = ["build","maturin"]
|
||||
|
||||
|
||||
[tasks.my-flow]
|
||||
dependencies = [
|
||||
"format",
|
||||
"build",
|
||||
"test"
|
||||
]
|
||||
|
||||
151
src/action.rs
151
src/action.rs
|
|
@ -1,9 +1,8 @@
|
|||
#[allow(dead_code)]
|
||||
|
||||
use std::fmt::Debug;
|
||||
use lazy_static::lazy_static;
|
||||
use crate::craft::Craft;
|
||||
use crate::specs::{Buff, Success};
|
||||
use lazy_static::lazy_static;
|
||||
#[allow(dead_code)]
|
||||
use std::fmt::Debug;
|
||||
|
||||
pub struct Action {
|
||||
pub name: String,
|
||||
|
|
@ -25,9 +24,15 @@ impl ActionBuilder {
|
|||
short_name = short_name.replace("II", "2");
|
||||
short_name.retain(|c| !c.is_whitespace() && c != '\'');
|
||||
short_name[0..1].make_ascii_lowercase();
|
||||
if name == "Basic Synthesis" { short_name = "basicSynth2".to_string(); }
|
||||
if name == "Groundwork" { short_name = "groundwork".to_string(); }
|
||||
if name == "Careful Synthesis" { short_name = "carefulSynthesis".to_string(); }
|
||||
if name == "Basic Synthesis" {
|
||||
short_name = "basicSynth2".to_string();
|
||||
}
|
||||
if name == "Groundwork" {
|
||||
short_name = "groundwork".to_string();
|
||||
}
|
||||
if name == "Careful Synthesis" {
|
||||
short_name = "carefulSynthesis".to_string();
|
||||
}
|
||||
|
||||
Self {
|
||||
action: Action {
|
||||
|
|
@ -38,7 +43,7 @@ impl ActionBuilder {
|
|||
quality: 0,
|
||||
buff: None,
|
||||
short_name,
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
pub fn dur(mut self, dur: u32) -> Self {
|
||||
|
|
@ -68,7 +73,10 @@ impl ActionBuilder {
|
|||
|
||||
impl PartialEq for Action {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.cp == other.cp && self.dur == other.dur && self.progress == other.progress && self.quality == other.quality
|
||||
self.cp == other.cp
|
||||
&& self.dur == other.dur
|
||||
&& self.progress == other.progress
|
||||
&& self.quality == other.quality
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -77,12 +85,18 @@ impl Action {
|
|||
self.name.clone()
|
||||
}
|
||||
pub fn get_cp_cost(&self, _craft: &Craft) -> u32 {
|
||||
if self == &ACTIONS.standard_touch && _craft.buffs.basic_touch > 0 { return 18; };
|
||||
if self == &ACTIONS.advanced_touch && _craft.buffs.standard_touch > 0 { return 18; };
|
||||
if self == &ACTIONS.standard_touch && _craft.buffs.basic_touch > 0 {
|
||||
return 18;
|
||||
};
|
||||
if self == &ACTIONS.advanced_touch && _craft.buffs.standard_touch > 0 {
|
||||
return 18;
|
||||
};
|
||||
self.cp
|
||||
}
|
||||
pub fn get_durability_cost(&self, _craft: &Craft) -> u32 {
|
||||
if self == &ACTIONS.masters_mend { return 30; }
|
||||
if self == &ACTIONS.masters_mend {
|
||||
return 30;
|
||||
}
|
||||
if self.dur == 0 || self.progress == 0 && self.quality == 0 {
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -156,7 +170,6 @@ impl Debug for Action {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
pub struct ActionList {
|
||||
pub muscle_memory: Action,
|
||||
pub reflect: Action,
|
||||
|
|
@ -186,31 +199,99 @@ pub struct ActionList {
|
|||
impl Default for ActionList {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
muscle_memory: ActionBuilder::new("Muscle Memory").cp(6).progress(300).buff(Some((Buff::MuscleMemory, 5))).build(),
|
||||
reflect: ActionBuilder::new("Reflect").cp(6).quality(100).buff(Some((Buff::InnerQuiet, 1))).build(),
|
||||
muscle_memory: ActionBuilder::new("Muscle Memory")
|
||||
.cp(6)
|
||||
.progress(300)
|
||||
.buff(Some((Buff::MuscleMemory, 5)))
|
||||
.build(),
|
||||
reflect: ActionBuilder::new("Reflect")
|
||||
.cp(6)
|
||||
.quality(100)
|
||||
.buff(Some((Buff::InnerQuiet, 1)))
|
||||
.build(),
|
||||
|
||||
basic_synthesis: ActionBuilder::new("Basic Synthesis").progress(120).build(),
|
||||
careful_synthesis: ActionBuilder::new("Careful Synthesis").cp(7).progress(180).build(),
|
||||
groundwork: ActionBuilder::new("Groundwork").cp(18).dur(20).progress(360).build(),
|
||||
prudent_synthesis: ActionBuilder::new("Prudent Synthesis").cp(18).dur(5).progress(180).build(),
|
||||
delicate_synthesis: ActionBuilder::new("Delicate Synthesis").cp(32).progress(100).quality(100).build(),
|
||||
careful_synthesis: ActionBuilder::new("Careful Synthesis")
|
||||
.cp(7)
|
||||
.progress(180)
|
||||
.build(),
|
||||
groundwork: ActionBuilder::new("Groundwork")
|
||||
.cp(18)
|
||||
.dur(20)
|
||||
.progress(360)
|
||||
.build(),
|
||||
prudent_synthesis: ActionBuilder::new("Prudent Synthesis")
|
||||
.cp(18)
|
||||
.dur(5)
|
||||
.progress(180)
|
||||
.build(),
|
||||
delicate_synthesis: ActionBuilder::new("Delicate Synthesis")
|
||||
.cp(32)
|
||||
.progress(100)
|
||||
.quality(100)
|
||||
.build(),
|
||||
|
||||
basic_touch: ActionBuilder::new("Basic Touch").cp(18).quality(100).buff(Some((Buff::BasicTouch, 1))).build(),
|
||||
standard_touch: ActionBuilder::new("Standard Touch").quality(125).cp(32).buff(Some((Buff::StandardTouch, 1))).build(),
|
||||
byregot_blessing: ActionBuilder::new("Byregot's Blessing").cp(24).quality(100).buff(Some((Buff::InnerQuiet, 0))).build(),
|
||||
prudent_touch: ActionBuilder::new("Prudent Touch").cp(25).dur(5).quality(100).build(),
|
||||
preparatory_touch: ActionBuilder::new("Preparatory Touch").cp(40).dur(20).quality(200).buff(Some((Buff::InnerQuiet, 1))).build(),
|
||||
advanced_touch: ActionBuilder::new("Advanced Touch").quality(150).cp(46).build(),
|
||||
trained_finesse: ActionBuilder::new("Trained Finesse").cp(32).quality(100).dur(0).build(),
|
||||
basic_touch: ActionBuilder::new("Basic Touch")
|
||||
.cp(18)
|
||||
.quality(100)
|
||||
.buff(Some((Buff::BasicTouch, 1)))
|
||||
.build(),
|
||||
standard_touch: ActionBuilder::new("Standard Touch")
|
||||
.quality(125)
|
||||
.cp(32)
|
||||
.buff(Some((Buff::StandardTouch, 1)))
|
||||
.build(),
|
||||
byregot_blessing: ActionBuilder::new("Byregot's Blessing")
|
||||
.cp(24)
|
||||
.quality(100)
|
||||
.buff(Some((Buff::InnerQuiet, 0)))
|
||||
.build(),
|
||||
prudent_touch: ActionBuilder::new("Prudent Touch")
|
||||
.cp(25)
|
||||
.dur(5)
|
||||
.quality(100)
|
||||
.build(),
|
||||
preparatory_touch: ActionBuilder::new("Preparatory Touch")
|
||||
.cp(40)
|
||||
.dur(20)
|
||||
.quality(200)
|
||||
.buff(Some((Buff::InnerQuiet, 1)))
|
||||
.build(),
|
||||
advanced_touch: ActionBuilder::new("Advanced Touch")
|
||||
.quality(150)
|
||||
.cp(46)
|
||||
.build(),
|
||||
trained_finesse: ActionBuilder::new("Trained Finesse")
|
||||
.cp(32)
|
||||
.quality(100)
|
||||
.dur(0)
|
||||
.build(),
|
||||
|
||||
masters_mend: ActionBuilder::new("Master's Mend").cp(88).build(),
|
||||
waste_not: ActionBuilder::new("Waste Not").cp(56).buff(Some((Buff::WasteNot, 4))).build(),
|
||||
waste_not_ii: ActionBuilder::new("Waste Not II").cp(98).buff(Some((Buff::WasteNot, 8))).build(),
|
||||
manipulation: ActionBuilder::new("Manipulation").cp(96).buff(Some((Buff::Manipulation, 8))).build(),
|
||||
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(),
|
||||
|
||||
waste_not: ActionBuilder::new("Waste Not")
|
||||
.cp(56)
|
||||
.buff(Some((Buff::WasteNot, 4)))
|
||||
.build(),
|
||||
waste_not_ii: ActionBuilder::new("Waste Not II")
|
||||
.cp(98)
|
||||
.buff(Some((Buff::WasteNot, 8)))
|
||||
.build(),
|
||||
manipulation: ActionBuilder::new("Manipulation")
|
||||
.cp(96)
|
||||
.buff(Some((Buff::Manipulation, 8)))
|
||||
.build(),
|
||||
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(),
|
||||
|
|
@ -219,5 +300,5 @@ impl Default for ActionList {
|
|||
}
|
||||
|
||||
lazy_static! {
|
||||
pub static ref ACTIONS: ActionList = ActionList::default();
|
||||
}
|
||||
pub static ref ACTIONS: ActionList = ActionList::default();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// #![warn(missing_docs,unsafe_code,unstable_features,)]
|
||||
use std::time::{Instant};
|
||||
use clap::Parser;
|
||||
use std::time::Instant;
|
||||
use xiv_craft_solver;
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
@ -15,37 +15,48 @@ fn main() {
|
|||
println!("Solving...");
|
||||
|
||||
// Solve from config
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
// Stop timer
|
||||
let t_final = now.elapsed().as_millis();
|
||||
|
||||
|
||||
|
||||
// Show best result depending on selected value
|
||||
match results{
|
||||
match results {
|
||||
None => {
|
||||
println!("[Error] No solutions found for craft '{}' with crafter '{}' (ms)", args.recipe_name, args.character_name);
|
||||
return
|
||||
println!(
|
||||
"[Error] No solutions found for craft '{}' with crafter '{}' (ms)",
|
||||
args.recipe_name, args.character_name
|
||||
);
|
||||
return;
|
||||
}
|
||||
Some(ref res)=>{
|
||||
Some(ref res) => {
|
||||
// Show best results
|
||||
if args.verbose>0{
|
||||
println!("[Final] {} results were found:",res.len());
|
||||
if args.verbose > 0 {
|
||||
println!("[Final] {} results were found:", res.len());
|
||||
#[cfg(feature = "verbose")]
|
||||
if args.verbose>1{
|
||||
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();
|
||||
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();
|
||||
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();
|
||||
xiv_craft_solver::find_quality_route(&results)
|
||||
.unwrap()
|
||||
.pretty_print();
|
||||
|
||||
// #[cfg(feature = "verbose")]
|
||||
// if params.verbose>2{
|
||||
|
|
@ -53,7 +64,11 @@ fn main() {
|
|||
// }
|
||||
|
||||
// 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();
|
||||
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();
|
||||
()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
81
src/craft.rs
81
src/craft.rs
|
|
@ -1,12 +1,12 @@
|
|||
use std::fmt::{Debug, Formatter,Display};
|
||||
use crate::action::Action;
|
||||
use crate::specs::{Buff, BuffState, Recipe, Stats, Success};
|
||||
use crate::Parameters;
|
||||
use std::fmt::{Debug, Display, Formatter};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Craft<'a> {
|
||||
pub recipe: Recipe,
|
||||
pub stats: Stats,
|
||||
pub recipe: Recipe,
|
||||
pub stats: Stats,
|
||||
pub buffs: BuffState,
|
||||
pub step_count: u32,
|
||||
pub durability: i32,
|
||||
|
|
@ -19,7 +19,7 @@ pub struct Craft<'a> {
|
|||
}
|
||||
|
||||
impl<'a> Craft<'a> {
|
||||
pub fn new(recipe: Recipe, stats: Stats, params: Parameters) -> Craft<'a> {
|
||||
pub fn new(recipe: Recipe, stats: Stats, params: Parameters) -> Craft<'a> {
|
||||
Self {
|
||||
recipe,
|
||||
stats,
|
||||
|
|
@ -36,12 +36,16 @@ impl<'a> Craft<'a> {
|
|||
}
|
||||
|
||||
pub fn get_base_progression(&self) -> u32 {
|
||||
let base_value = (self.stats.craftsmanship as f64 / 10.0) / (self.recipe.progress_divider as f64 / 100.0) + 2.0;
|
||||
let base_value = (self.stats.craftsmanship as f64 / 10.0)
|
||||
/ (self.recipe.progress_divider as f64 / 100.0)
|
||||
+ 2.0;
|
||||
(base_value * (self.recipe.progress_modifier as f64 / 100.0) as f64).floor() as u32
|
||||
}
|
||||
|
||||
pub fn get_base_quality(&self) -> u32 {
|
||||
let base_value = (self.stats.control as f64 / 10.0) / (self.recipe.quality_divider as f64 / 100.0) + 35.0;
|
||||
let base_value = (self.stats.control as f64 / 10.0)
|
||||
/ (self.recipe.quality_divider as f64 / 100.0)
|
||||
+ 35.0;
|
||||
(base_value * (self.recipe.quality_modifier as f64 / 100.0) as f64).floor() as u32
|
||||
}
|
||||
|
||||
|
|
@ -53,18 +57,39 @@ impl<'a> Craft<'a> {
|
|||
self.step_count += 1;
|
||||
self.cp -= action.get_cp_cost(self) as i32;
|
||||
self.durability -= action.get_durability_cost(self) as i32;
|
||||
self.progression += (action.get_progress(self) as f64 * (self.get_base_progression() as f64 / 100.0)).floor() as u32;
|
||||
self.quality += (action.get_quality(self) as f64 * (self.get_base_quality() as f64 / 100.0)).floor() as u32;
|
||||
if self.progression >= self.recipe.progress { self.success = Success::Success; }
|
||||
if self.durability <= 0 { self.success = Success::Failure; }
|
||||
if self.buffs.manipulation > 0 { self.durability += 5; }
|
||||
if action.quality > 0 { self.buffs.inner_quiet += 1; }
|
||||
self.progression += (action.get_progress(self) as f64
|
||||
* (self.get_base_progression() as f64 / 100.0))
|
||||
.floor() as u32;
|
||||
self.quality += (action.get_quality(self) as f64 * (self.get_base_quality() as f64 / 100.0))
|
||||
.floor() as u32;
|
||||
if self.progression >= self.recipe.progress {
|
||||
self.success = Success::Success;
|
||||
}
|
||||
if self.durability <= 0 {
|
||||
self.success = Success::Failure;
|
||||
}
|
||||
if self.buffs.manipulation > 0 {
|
||||
self.durability += 5;
|
||||
}
|
||||
if action.quality > 0 {
|
||||
self.buffs.inner_quiet += 1;
|
||||
}
|
||||
self.buffs.tick();
|
||||
if action.progress > 0 { self.buffs.remove(Buff::MuscleMemory); }
|
||||
if action.quality > 0 { self.buffs.remove(Buff::GreatStrides); }
|
||||
if let Some((buff, duration)) = action.get_buff() { self.buffs.apply(buff, duration); }
|
||||
if self.durability > self.recipe.durability as i32 { self.durability = self.recipe.durability as i32; }
|
||||
if self.buffs.inner_quiet > 10 { self.buffs.inner_quiet = 10; }
|
||||
if action.progress > 0 {
|
||||
self.buffs.remove(Buff::MuscleMemory);
|
||||
}
|
||||
if action.quality > 0 {
|
||||
self.buffs.remove(Buff::GreatStrides);
|
||||
}
|
||||
if let Some((buff, duration)) = action.get_buff() {
|
||||
self.buffs.apply(buff, duration);
|
||||
}
|
||||
if self.durability > self.recipe.durability as i32 {
|
||||
self.durability = self.recipe.durability as i32;
|
||||
}
|
||||
if self.buffs.inner_quiet > 10 {
|
||||
self.buffs.inner_quiet = 10;
|
||||
}
|
||||
|
||||
self.actions.push(action);
|
||||
return self;
|
||||
|
|
@ -95,20 +120,28 @@ impl<'a> Debug for Craft<'a> {
|
|||
.field("durability", &format!("{:?}/{:?}", &self.durability, &self.recipe.durability))
|
||||
// .field("cp", &format!("{:?}/{:?}", &self.cp, &self.stats.max_cp))
|
||||
;
|
||||
binding.field("actions",&self.actions);
|
||||
binding.field("actions", &self.actions);
|
||||
binding.finish()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl<'a> Display for Craft<'a> {
|
||||
fn fmt(&self, f: &mut Formatter)-> std::fmt::Result {
|
||||
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
|
||||
f.debug_struct("Craft")
|
||||
.field("step_count", &self.step_count)
|
||||
.field("progression", &format!("{:?}/{:?}", &self.progression, &self.recipe.progress))
|
||||
.field("quality", &format!("{:?}/{:?}", &self.quality, &self.recipe.quality))
|
||||
.field("durability", &format!("{:?}/{:?}", &self.durability, &self.recipe.durability))
|
||||
.field(
|
||||
"progression",
|
||||
&format!("{:?}/{:?}", &self.progression, &self.recipe.progress),
|
||||
)
|
||||
.field(
|
||||
"quality",
|
||||
&format!("{:?}/{:?}", &self.quality, &self.recipe.quality),
|
||||
)
|
||||
.field(
|
||||
"durability",
|
||||
&format!("{:?}/{:?}", &self.durability, &self.recipe.durability),
|
||||
)
|
||||
.field("cp", &format!("{:?}/{:?}", &self.cp, &self.stats.max_cp))
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
162
src/io.rs
162
src/io.rs
|
|
@ -1,8 +1,8 @@
|
|||
use crate::Craft;
|
||||
use core::fmt::Display;
|
||||
use clap::Parser;
|
||||
use core::fmt::Display;
|
||||
|
||||
#[cfg(not(feature="no_python"))]
|
||||
#[cfg(not(feature = "no_python"))]
|
||||
use pyo3::prelude::*;
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
|
|
@ -10,7 +10,7 @@ pub struct Parameters {
|
|||
pub threads: usize,
|
||||
pub verbose: u8,
|
||||
pub depth: u32,
|
||||
pub desperate:bool,
|
||||
pub desperate: bool,
|
||||
pub byregot_step: u8,
|
||||
}
|
||||
|
||||
|
|
@ -28,7 +28,7 @@ pub struct Args {
|
|||
/// 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,
|
||||
|
|
@ -42,20 +42,19 @@ pub struct Args {
|
|||
pub threads: usize,
|
||||
|
||||
/// Desperate mode, will try to finish the craft above all
|
||||
#[arg(short='D', long, default_value_t = false)]
|
||||
#[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)]
|
||||
#[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{
|
||||
pub struct SolverResult {
|
||||
#[pyo3(get)]
|
||||
pub steps: u32,
|
||||
#[pyo3(get)]
|
||||
|
|
@ -65,15 +64,15 @@ pub struct SolverResult{
|
|||
#[pyo3(get)]
|
||||
pub durability: i32,
|
||||
#[pyo3(get)]
|
||||
pub cp:i32,
|
||||
pub cp: i32,
|
||||
#[pyo3(get)]
|
||||
pub total_cp:u32,
|
||||
pub total_cp: u32,
|
||||
#[pyo3(get)]
|
||||
pub total_progression:u32,
|
||||
pub total_progression: u32,
|
||||
#[pyo3(get)]
|
||||
pub total_quality:u32,
|
||||
pub total_quality: u32,
|
||||
#[pyo3(get)]
|
||||
pub total_durability:u32,
|
||||
pub total_durability: u32,
|
||||
#[pyo3(get)]
|
||||
pub actions: Vec<String>,
|
||||
#[pyo3(get)]
|
||||
|
|
@ -85,91 +84,108 @@ pub struct SolverResult{
|
|||
}
|
||||
|
||||
/// Pretty display for SolverResult
|
||||
impl Display for SolverResult{
|
||||
fn fmt(&self, _f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
|
||||
println!("{:?}",self.actions);
|
||||
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{
|
||||
|
||||
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()); }
|
||||
impl SolverResult {
|
||||
pub fn from_craft(
|
||||
craft: &Craft,
|
||||
step1_solutions: usize,
|
||||
step2_solutions: usize,
|
||||
found_100_percent: bool,
|
||||
) -> SolverResult {
|
||||
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,
|
||||
SolverResult {
|
||||
steps: craft.step_count,
|
||||
progression: craft.progression,
|
||||
quality:craft.quality,
|
||||
durability:craft.durability,
|
||||
actions:actions,
|
||||
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,
|
||||
total_progression: craft.recipe.progress,
|
||||
total_quality: craft.recipe.quality,
|
||||
total_durability: craft.recipe.durability,
|
||||
cp: craft.cp,
|
||||
total_cp : craft.stats.max_cp,
|
||||
total_cp: craft.stats.max_cp,
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#[pymethods]
|
||||
impl SolverResult{
|
||||
impl SolverResult {
|
||||
#[staticmethod]
|
||||
pub fn default()->Self{
|
||||
Self{
|
||||
steps:0,
|
||||
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,
|
||||
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);
|
||||
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{11}else{8},
|
||||
impl Parameters {
|
||||
pub fn from_args(args: &Args) -> Self {
|
||||
Self {
|
||||
depth: if args.desperate { 11 } else { 8 },
|
||||
threads: args.threads,
|
||||
verbose: args.verbose,
|
||||
desperate: args.desperate,
|
||||
byregot_step: if args.long{6}else{8}
|
||||
byregot_step: if args.long { 6 } else { 8 },
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////// Python Bindings //////
|
||||
|
||||
/// A Python module implemented in Rust.
|
||||
#[cfg(not(feature="no_python"))]
|
||||
#[cfg(not(feature = "no_python"))]
|
||||
#[pymodule]
|
||||
fn xiv_craft_solver(_py: Python, m: &PyModule) -> PyResult<()> {
|
||||
m.add_function(wrap_pyfunction!(test_result, m)?)?;
|
||||
|
|
@ -178,39 +194,39 @@ fn xiv_craft_solver(_py: Python, m: &PyModule) -> PyResult<()> {
|
|||
}
|
||||
|
||||
///
|
||||
#[cfg(not(feature="no_python"))]
|
||||
#[cfg(not(feature = "no_python"))]
|
||||
#[pyfunction]
|
||||
pub fn test_result()-> SolverResult {
|
||||
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"))]
|
||||
use crate::{solve_craft, Recipe, Stats};
|
||||
|
||||
#[cfg(not(feature="no_python"))]
|
||||
#[cfg(not(feature = "no_python"))]
|
||||
#[pyfunction]
|
||||
pub fn solve_from_python(values : &PyAny)->PyResult<Option<Vec<SolverResult>>>{
|
||||
pub fn solve_from_python(values: &PyAny) -> PyResult<Option<Vec<SolverResult>>> {
|
||||
// // Create Recipe
|
||||
let recipe = Recipe{
|
||||
let recipe = Recipe {
|
||||
durability: values.getattr("durability")?.extract()?,
|
||||
progress: values.getattr("progress")?.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()?,
|
||||
quality_divider: values.getattr("quality_divider")?.extract()?,
|
||||
quality_modifier: values.getattr("quality_modifier")?.extract()?,
|
||||
};
|
||||
|
||||
// Create Stats
|
||||
let stats = 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{
|
||||
let param = Parameters {
|
||||
depth: values.getattr("depth")?.extract()?,
|
||||
byregot_step: values.getattr("byregot_step")?.extract()?,
|
||||
desperate: values.getattr("desperate")?.extract()?,
|
||||
|
|
@ -221,4 +237,4 @@ pub fn solve_from_python(values : &PyAny)->PyResult<Option<Vec<SolverResult>>>{
|
|||
// println!("{:?} len: {:?} ",values,values.getattr("len()"));
|
||||
let res = solve_craft(recipe, stats, param);
|
||||
Ok(res)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
246
src/lib.rs
246
src/lib.rs
|
|
@ -1,28 +1,32 @@
|
|||
use crate::io::SolverResult;
|
||||
use crate::{
|
||||
craft::Craft,
|
||||
specs::{Recipe,Stats},
|
||||
io::Parameters,
|
||||
specs::{Recipe, Stats},
|
||||
};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use threadpool::ThreadPool;
|
||||
use std::sync::{Arc,Mutex};
|
||||
|
||||
mod solver;
|
||||
mod specs;
|
||||
pub mod action;
|
||||
pub mod craft;
|
||||
pub mod io;
|
||||
mod solver;
|
||||
mod specs;
|
||||
|
||||
/// 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>>{
|
||||
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);
|
||||
let craft = Craft::new(recipe, stats, params);
|
||||
|
||||
// Start a threadpool
|
||||
let pool = ThreadPool::new(params.threads);
|
||||
|
||||
#[cfg(feature = "verbose")]
|
||||
if params.verbose>0{
|
||||
if params.verbose > 0 {
|
||||
println!("[P1] Starting phase 1...");
|
||||
}
|
||||
|
||||
|
|
@ -30,11 +34,23 @@ pub fn solve_craft<'a>(recipe: Recipe, stats: Stats, params: Parameters) -> Opti
|
|||
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,r.quality * 100 / r.recipe.quality,r.cp,r.durability);
|
||||
}}
|
||||
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,
|
||||
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)
|
||||
|
|
@ -44,7 +60,7 @@ pub fn solve_craft<'a>(recipe: Recipe, stats: Stats, params: Parameters) -> Opti
|
|||
let _phase2_routes = Arc::clone(&arc_phase2_routes);
|
||||
|
||||
pool.execute(move || {
|
||||
if let Some(mut _route) = solver::generate_routes_phase2(route){
|
||||
if let Some(mut _route) = solver::generate_routes_phase2(route) {
|
||||
let mut shared = _phase2_routes.lock().unwrap();
|
||||
shared.append(&mut _route);
|
||||
};
|
||||
|
|
@ -56,145 +72,207 @@ pub fn solve_craft<'a>(recipe: Recipe, stats: Stats, params: Parameters) -> Opti
|
|||
let nb_p2 = phase2_routes.len();
|
||||
|
||||
// Drop on empty results
|
||||
if phase2_routes.len()==0{
|
||||
return None
|
||||
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 > 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
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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{
|
||||
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));
|
||||
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,false));}
|
||||
if valid_solutions.len() == 0 {
|
||||
for route in phase2_routes.iter() {
|
||||
valid_solutions.push(SolverResult::from_craft(route, nb_p1, nb_p2, false));
|
||||
}
|
||||
}
|
||||
|
||||
Some(valid_solutions)
|
||||
}
|
||||
|
||||
/// Load the config from args and make a craft from it
|
||||
pub fn load_from_config<'a>(recipe_name: &str, file_name: &str, character_name: &str) -> (Recipe,Stats) {
|
||||
pub fn load_from_config<'a>(
|
||||
recipe_name: &str,
|
||||
file_name: &str,
|
||||
character_name: &str,
|
||||
) -> (Recipe, Stats) {
|
||||
//read craft.toml
|
||||
let config: toml::Value = toml::from_str(
|
||||
&std::fs::read_to_string(file_name)
|
||||
.expect(&format!("Can't open {}",file_name))
|
||||
).unwrap();
|
||||
&std::fs::read_to_string(file_name).expect(&format!("Can't open {}", file_name)),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let recp = match config.get(recipe_name){
|
||||
let recp = match config.get(recipe_name) {
|
||||
Some(r) => r,
|
||||
None => panic!("Can't find value '{}' in '{}'",recipe_name, file_name)
|
||||
None => panic!("Can't find value '{}' in '{}'", recipe_name, file_name),
|
||||
};
|
||||
|
||||
// Load receipe values
|
||||
let recipe = Recipe {
|
||||
durability: recp
|
||||
.get("durability").expect(&format!("Can't find 'durability' in recipe '{}' on file '{}'",
|
||||
recipe_name,file_name))
|
||||
.as_integer().expect("Can't convert durability as an integer") as u32,
|
||||
.get("durability")
|
||||
.expect(&format!(
|
||||
"Can't find 'durability' in recipe '{}' on file '{}'",
|
||||
recipe_name, file_name
|
||||
))
|
||||
.as_integer()
|
||||
.expect("Can't convert durability as an integer") as u32,
|
||||
progress: recp
|
||||
.get("progress").expect(&format!("Can't find 'progress' in recipe '{}' on '{}'",
|
||||
recipe_name,file_name))
|
||||
.as_integer().expect("Can't convert progress as an integer") as u32,
|
||||
.get("progress")
|
||||
.expect(&format!(
|
||||
"Can't find 'progress' in recipe '{}' on '{}'",
|
||||
recipe_name, file_name
|
||||
))
|
||||
.as_integer()
|
||||
.expect("Can't convert progress as an integer") as u32,
|
||||
quality: recp
|
||||
.get("quality").expect(&format!("Can't find 'quality' in recipe '{}' on '{}'",
|
||||
recipe_name,file_name))
|
||||
.as_integer().expect("Can't convert quality as an integer") as u32,
|
||||
.get("quality")
|
||||
.expect(&format!(
|
||||
"Can't find 'quality' in recipe '{}' on '{}'",
|
||||
recipe_name, file_name
|
||||
))
|
||||
.as_integer()
|
||||
.expect("Can't convert quality as an integer") as u32,
|
||||
progress_divider: recp
|
||||
.get("progress_divider").expect(&format!("Can't find 'progress_divider' in recipe '{}' on '{}'",
|
||||
recipe_name,file_name))
|
||||
.as_integer().expect("Can't convert progress_divider as an integer") as u32,
|
||||
.get("progress_divider")
|
||||
.expect(&format!(
|
||||
"Can't find 'progress_divider' in recipe '{}' on '{}'",
|
||||
recipe_name, file_name
|
||||
))
|
||||
.as_integer()
|
||||
.expect("Can't convert progress_divider as an integer")
|
||||
as u32,
|
||||
quality_divider: recp
|
||||
.get("quality_divider").expect(&format!("Can't find 'quality_divider' in recipe '{}' on '{}'",
|
||||
recipe_name,file_name))
|
||||
.as_integer().expect("Can't convert quality_divider as an integer") as u32,
|
||||
.get("quality_divider")
|
||||
.expect(&format!(
|
||||
"Can't find 'quality_divider' in recipe '{}' on '{}'",
|
||||
recipe_name, file_name
|
||||
))
|
||||
.as_integer()
|
||||
.expect("Can't convert quality_divider as an integer") as u32,
|
||||
progress_modifier: recp
|
||||
.get("progress_modifier").expect(&format!("Can't find 'progress_modifier' in recipe '{}' on '{}'",
|
||||
recipe_name,file_name))
|
||||
.as_integer().expect("Can't convert progress_modifier as an integer") as u32,
|
||||
.get("progress_modifier")
|
||||
.expect(&format!(
|
||||
"Can't find 'progress_modifier' in recipe '{}' on '{}'",
|
||||
recipe_name, file_name
|
||||
))
|
||||
.as_integer()
|
||||
.expect("Can't convert progress_modifier as an integer")
|
||||
as u32,
|
||||
quality_modifier: recp
|
||||
.get("quality_modifier").expect(&format!("Can't find 'quality_modifier' in recipe '{}' on '{}'",
|
||||
recipe_name,file_name))
|
||||
.as_integer().expect("Can't convert quality_modifier as an integer") as u32,
|
||||
.get("quality_modifier")
|
||||
.expect(&format!(
|
||||
"Can't find 'quality_modifier' in recipe '{}' on '{}'",
|
||||
recipe_name, file_name
|
||||
))
|
||||
.as_integer()
|
||||
.expect("Can't convert quality_modifier as an integer")
|
||||
as u32,
|
||||
};
|
||||
|
||||
let cfg = match config.get(character_name){
|
||||
let cfg = match config.get(character_name) {
|
||||
Some(c) => c,
|
||||
None => panic!("Can't find '{}' in file '{}'",character_name,file_name),
|
||||
None => panic!("Can't find '{}' in file '{}'", character_name, file_name),
|
||||
};
|
||||
let stats = Stats {
|
||||
craftsmanship: cfg
|
||||
.get("craftsmanship").expect(&format!("Can't find 'craftsmanship' in character '{}' on file '{}'",
|
||||
character_name,file_name))
|
||||
.as_integer().expect("Can't convert craftsmanship as an integer") as u32,
|
||||
.get("craftsmanship")
|
||||
.expect(&format!(
|
||||
"Can't find 'craftsmanship' in character '{}' on file '{}'",
|
||||
character_name, file_name
|
||||
))
|
||||
.as_integer()
|
||||
.expect("Can't convert craftsmanship as an integer") as u32,
|
||||
control: cfg
|
||||
.get("control").expect(&format!("Can't find 'control' in character '{}' on file '{}'",
|
||||
character_name,file_name))
|
||||
.as_integer().expect("Can't convert control as an integer") as u32,
|
||||
.get("control")
|
||||
.expect(&format!(
|
||||
"Can't find 'control' in character '{}' on file '{}'",
|
||||
character_name, file_name
|
||||
))
|
||||
.as_integer()
|
||||
.expect("Can't convert control as an integer") as u32,
|
||||
max_cp: cfg
|
||||
.get("max_cp").expect(&format!("Can't find 'max_cp' in character '{}' on file '{}'",
|
||||
character_name,file_name))
|
||||
.as_integer().expect("Can't convert max_cp as an integer") as u32,
|
||||
.get("max_cp")
|
||||
.expect(&format!(
|
||||
"Can't find 'max_cp' in character '{}' on file '{}'",
|
||||
character_name, file_name
|
||||
))
|
||||
.as_integer()
|
||||
.expect("Can't convert max_cp as an integer") as u32,
|
||||
};
|
||||
(recipe,stats)
|
||||
(recipe, stats)
|
||||
}
|
||||
|
||||
/// Print all routes in the vect, verbose
|
||||
pub fn print_routes<'a>(routes: & Option<Vec<SolverResult>>){
|
||||
match routes{
|
||||
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)
|
||||
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")
|
||||
}
|
||||
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>{
|
||||
pub fn find_fast_route(routes: &Option<Vec<SolverResult>>) -> Option<&SolverResult> {
|
||||
match routes {
|
||||
Some(_routes) => {
|
||||
if _routes.len()>0{
|
||||
if _routes.len() > 0 {
|
||||
_routes.iter().min_by_key(|key| key.steps)
|
||||
} else { None }
|
||||
},
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// 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 {
|
||||
Some(_routes) => _routes.iter().max_by_key(|key| key.quality),
|
||||
None => None,
|
||||
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>{
|
||||
pub fn find_safe_route(routes: &Option<Vec<SolverResult>>) -> Option<&SolverResult> {
|
||||
match routes {
|
||||
Some(_routes) => {
|
||||
if _routes.len()>0{
|
||||
Some(_routes) => {
|
||||
if _routes.len() > 0 {
|
||||
_routes.iter().max_by_key(|key| key.durability)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
143
src/solver.rs
143
src/solver.rs
|
|
@ -1,47 +1,83 @@
|
|||
use std::collections::VecDeque;
|
||||
use std::ops::Not;
|
||||
use crate::action::{Action, ACTIONS};
|
||||
use crate::craft::Craft;
|
||||
use crate::specs::Success;
|
||||
use std::collections::VecDeque;
|
||||
use std::ops::Not;
|
||||
|
||||
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]; }
|
||||
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();
|
||||
let mut forbidden_actions = Vec::<Option<&'a Action>>::new();
|
||||
|
||||
// Optimize the first three steps for massive time save
|
||||
if craft.step_count == 0 { return action_vec![ACTIONS.muscle_memory]; }
|
||||
if craft.step_count == 1 { return action_vec![ACTIONS.manipulation]; }
|
||||
if craft.step_count == 0 {
|
||||
return action_vec![ACTIONS.muscle_memory];
|
||||
}
|
||||
if craft.step_count == 1 {
|
||||
return action_vec![ACTIONS.manipulation];
|
||||
}
|
||||
|
||||
// Prune some actions if not requested by --long
|
||||
if craft.step_count == 2 { return action_vec![/*ACTIONS.waste_not, ACTIONS.waste_not_ii, */ACTIONS.veneration]; }
|
||||
if craft.step_count == 3 { available_actions.append(&mut action_vec![ACTIONS.waste_not_ii/*,ACTIONS.waste_not*/]) }
|
||||
if craft.step_count == 2 {
|
||||
return action_vec![/*ACTIONS.waste_not, ACTIONS.waste_not_ii, */ ACTIONS.veneration];
|
||||
}
|
||||
if craft.step_count == 3 {
|
||||
available_actions.append(&mut action_vec![
|
||||
ACTIONS.waste_not_ii /*,ACTIONS.waste_not*/
|
||||
])
|
||||
}
|
||||
|
||||
// Groundwork mostly for wn / mm
|
||||
if craft.buffs.waste_not > 0 || craft.buffs.muscle_memory > 0 { available_actions.append(&mut action_vec![ACTIONS.groundwork]) }
|
||||
|
||||
if craft.buffs.waste_not > 0 || craft.buffs.muscle_memory > 0 {
|
||||
available_actions.append(&mut action_vec![ACTIONS.groundwork])
|
||||
}
|
||||
|
||||
// Forbidding actions depending on buffs
|
||||
if craft.buffs.muscle_memory > 0 { forbidden_actions.append(&mut action_vec![ACTIONS.basic_synthesis,ACTIONS.careful_synthesis,ACTIONS.prudent_synthesis,ACTIONS.delicate_synthesis]) }
|
||||
if craft.buffs.waste_not > 0 { forbidden_actions.append(&mut action_vec![ACTIONS.prudent_synthesis]) }
|
||||
available_actions.append(&mut action_vec![ACTIONS.basic_synthesis,ACTIONS.careful_synthesis,ACTIONS.prudent_synthesis,ACTIONS.delicate_synthesis]);
|
||||
|
||||
if craft.buffs.muscle_memory > 0 {
|
||||
forbidden_actions.append(&mut action_vec![
|
||||
ACTIONS.basic_synthesis,
|
||||
ACTIONS.careful_synthesis,
|
||||
ACTIONS.prudent_synthesis,
|
||||
ACTIONS.delicate_synthesis
|
||||
])
|
||||
}
|
||||
if craft.buffs.waste_not > 0 {
|
||||
forbidden_actions.append(&mut action_vec![ACTIONS.prudent_synthesis])
|
||||
}
|
||||
available_actions.append(&mut action_vec![
|
||||
ACTIONS.basic_synthesis,
|
||||
ACTIONS.careful_synthesis,
|
||||
ACTIONS.prudent_synthesis,
|
||||
ACTIONS.delicate_synthesis
|
||||
]);
|
||||
|
||||
// ACTIONS.groundwork for the --pls
|
||||
if craft.args.desperate{
|
||||
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])};
|
||||
if craft.step_count > 8 {
|
||||
available_actions.append(&mut action_vec![ACTIONS.waste_not_ii, ACTIONS.waste_not])
|
||||
};
|
||||
|
||||
// Pruning the actions with the forbidden ones
|
||||
let mut result_actions = Vec::<Option<&'a Action>>::new();
|
||||
for action in available_actions {
|
||||
if !forbidden_actions.contains(&action) && action.unwrap().can_use(&craft) && result_actions.iter().any(|x| x.unwrap() == action.unwrap()).not() {
|
||||
if !forbidden_actions.contains(&action)
|
||||
&& action.unwrap().can_use(&craft)
|
||||
&& result_actions
|
||||
.iter()
|
||||
.any(|x| x.unwrap() == action.unwrap())
|
||||
.not()
|
||||
{
|
||||
result_actions.push(action);
|
||||
}
|
||||
}
|
||||
|
|
@ -49,7 +85,6 @@ 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();
|
||||
|
|
@ -57,15 +92,16 @@ pub fn generate_routes_phase1<'a>(craft: Craft<'a>) -> Vec<Craft<'a>> {
|
|||
let mut routes = Vec::new();
|
||||
while !queue.is_empty() {
|
||||
let craft = queue.pop().unwrap();
|
||||
for action in next_action_picker_1(& craft) {
|
||||
for action in next_action_picker_1(&craft) {
|
||||
let mut craft = craft.clone();
|
||||
|
||||
match action{
|
||||
match action {
|
||||
Some(a) => craft.run_action(a),
|
||||
None => break,
|
||||
};
|
||||
|
||||
let remaining_prog = (craft.recipe.progress as f32 - craft.progression as f32) / craft.get_base_progression() as f32;
|
||||
let remaining_prog = (craft.recipe.progress as f32 - craft.progression as f32)
|
||||
/ craft.get_base_progression() as f32;
|
||||
if remaining_prog <= 2.0 {
|
||||
if remaining_prog <= 0.0 {
|
||||
continue;
|
||||
|
|
@ -85,33 +121,46 @@ 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
|
||||
if craft.step_count < craft.args.depth { queue.push(craft); }
|
||||
if craft.step_count < craft.args.depth {
|
||||
queue.push(craft);
|
||||
}
|
||||
}
|
||||
}
|
||||
routes
|
||||
}
|
||||
|
||||
|
||||
/// 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];
|
||||
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();
|
||||
if craft.success != Success::Pending { return vec![None]; }
|
||||
if craft.success != Success::Pending {
|
||||
return vec![None];
|
||||
}
|
||||
if craft.buffs.innovation > 0 {
|
||||
forbidden_actions.push(&ACTIONS.innovation);
|
||||
} else {
|
||||
if craft.buffs.inner_quiet >= 2 {
|
||||
forbidden_actions.append(&mut vec![&ACTIONS.basic_touch,
|
||||
&ACTIONS.standard_touch,
|
||||
&ACTIONS.advanced_touch,
|
||||
&ACTIONS.trained_finesse,
|
||||
&ACTIONS.prudent_touch,
|
||||
&ACTIONS.preparatory_touch,
|
||||
&ACTIONS.byregot_blessing]);
|
||||
forbidden_actions.append(&mut vec![
|
||||
&ACTIONS.basic_touch,
|
||||
&ACTIONS.standard_touch,
|
||||
&ACTIONS.advanced_touch,
|
||||
&ACTIONS.trained_finesse,
|
||||
&ACTIONS.prudent_touch,
|
||||
&ACTIONS.preparatory_touch,
|
||||
&ACTIONS.byregot_blessing,
|
||||
]);
|
||||
}
|
||||
available_actions.push(&ACTIONS.innovation);
|
||||
}
|
||||
if craft.buffs.manipulation == 0 && craft.buffs.basic_touch == 0 && craft.buffs.standard_touch == 0 && craft.buffs.inner_quiet < 8 {
|
||||
if craft.buffs.manipulation == 0
|
||||
&& craft.buffs.basic_touch == 0
|
||||
&& craft.buffs.standard_touch == 0
|
||||
&& craft.buffs.inner_quiet < 8
|
||||
{
|
||||
available_actions.push(&ACTIONS.manipulation);
|
||||
}
|
||||
if craft.buffs.waste_not > 0 {
|
||||
|
|
@ -130,7 +179,8 @@ pub fn next_action_phase_2<'a>(craft: & Craft<'a>) -> Vec<Option<&'a Action>> {
|
|||
forbidden_actions.push(&ACTIONS.basic_touch);
|
||||
}
|
||||
|
||||
if craft.buffs.inner_quiet >= craft.args.byregot_step { // 10
|
||||
if craft.buffs.inner_quiet >= craft.args.byregot_step {
|
||||
// 10
|
||||
available_actions.push(&ACTIONS.trained_finesse);
|
||||
available_actions.push(&ACTIONS.great_strides);
|
||||
}
|
||||
|
|
@ -142,9 +192,11 @@ pub fn next_action_phase_2<'a>(craft: & Craft<'a>) -> Vec<Option<&'a Action>> {
|
|||
}
|
||||
}
|
||||
let mut final_actions: Vec<Option<&Action>> = Vec::new();
|
||||
|
||||
|
||||
for action in available_actions {
|
||||
if !forbidden_actions.contains(&action) && !final_actions.iter().any(|a| a.unwrap() == action) {
|
||||
if !forbidden_actions.contains(&action)
|
||||
&& !final_actions.iter().any(|a| a.unwrap() == action)
|
||||
{
|
||||
final_actions.push(Some(action));
|
||||
}
|
||||
}
|
||||
|
|
@ -154,7 +206,7 @@ pub fn next_action_phase_2<'a>(craft: & Craft<'a>) -> Vec<Option<&'a Action>> {
|
|||
/// Apply all actions to the current route
|
||||
pub fn generate_routes_phase2<'a>(craft: Craft<'a>) -> Option<Vec<Craft<'a>>> {
|
||||
let mut queue = VecDeque::new();
|
||||
|
||||
|
||||
let mut top_route: Craft<'a> = craft.clone(); // Default route, no hq on that one
|
||||
let mut top_routes: Vec<Craft<'a>> = vec![];
|
||||
|
||||
|
|
@ -163,18 +215,21 @@ pub fn generate_routes_phase2<'a>(craft: Craft<'a>) -> Option<Vec<Craft<'a>>> {
|
|||
while !queue.is_empty() {
|
||||
let _craft = queue.pop_front().unwrap();
|
||||
for action in next_action_phase_2(&_craft) {
|
||||
if _craft.success != Success::Pending || action.is_none() || !action.unwrap().can_use(&_craft) {
|
||||
if _craft.success != Success::Pending
|
||||
|| action.is_none()
|
||||
|| !action.unwrap().can_use(&_craft)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
let mut craft = _craft.clone();
|
||||
craft.run_action(action.unwrap());
|
||||
if action.unwrap() == &ACTIONS.byregot_blessing {
|
||||
#[cfg(not(feature="fast"))]
|
||||
if top_route.quality>=craft.recipe.quality{
|
||||
top_routes.push(craft.clone()); // Me memory
|
||||
#[cfg(not(feature = "fast"))]
|
||||
if top_route.quality >= craft.recipe.quality {
|
||||
top_routes.push(craft.clone()); // Me memory
|
||||
}
|
||||
if top_route.quality < craft.quality {
|
||||
#[cfg(feature="fast")]
|
||||
#[cfg(feature = "fast")]
|
||||
top_routes.push(craft.clone());
|
||||
top_route = craft;
|
||||
}
|
||||
|
|
@ -186,4 +241,4 @@ pub fn generate_routes_phase2<'a>(craft: Craft<'a>) -> Option<Vec<Craft<'a>>> {
|
|||
// Let's not forget the best result
|
||||
top_routes.push(top_route);
|
||||
Some(top_routes)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
36
src/specs.rs
36
src/specs.rs
|
|
@ -1,7 +1,6 @@
|
|||
use std::fmt::{Debug};
|
||||
use std::fmt::Debug;
|
||||
use strum_macros::EnumIter;
|
||||
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Recipe {
|
||||
pub durability: u32,
|
||||
|
|
@ -13,7 +12,6 @@ pub struct Recipe {
|
|||
pub quality_modifier: u32,
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Stats {
|
||||
pub craftsmanship: u32,
|
||||
|
|
@ -103,14 +101,30 @@ 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; }
|
||||
if self.veneration > 0 { self.veneration -= 1; }
|
||||
if self.manipulation > 0 { self.manipulation -= 1; }
|
||||
if self.muscle_memory > 0 { self.muscle_memory -= 1; }
|
||||
if self.basic_touch > 0 { self.basic_touch -= 1; }
|
||||
if self.standard_touch > 0 { self.standard_touch -= 1; }
|
||||
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;
|
||||
}
|
||||
if self.veneration > 0 {
|
||||
self.veneration -= 1;
|
||||
}
|
||||
if self.manipulation > 0 {
|
||||
self.manipulation -= 1;
|
||||
}
|
||||
if self.muscle_memory > 0 {
|
||||
self.muscle_memory -= 1;
|
||||
}
|
||||
if self.basic_touch > 0 {
|
||||
self.basic_touch -= 1;
|
||||
}
|
||||
if self.standard_touch > 0 {
|
||||
self.standard_touch -= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Reference in New Issue