diff --git a/.gitignore b/.gitignore index 8634d9d..44bf683 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ expected_values.md releases/* .whl pyinstaller_log.txt +llvm/* # Byte-compiled / optimized / DLL files __pycache__/ diff --git a/Cargo.lock b/Cargo.lock index 7de9c2e..f5b5874 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -63,6 +63,22 @@ dependencies = [ "os_str_bytes", ] +[[package]] +name = "ctor" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d2301688392eb071b0bf1a37be05c469d3cc4dbbd95df672fe28ab021e6a096" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "diff" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" + [[package]] name = "errno" version = "0.2.8" @@ -192,6 +208,15 @@ version = "6.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee" +[[package]] +name = "output_vt100" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "628223faebab4e3e40667ee0b2336d34a5b960ff60ea743ddfdbcf7770bcfb66" +dependencies = [ + "winapi", +] + [[package]] name = "parking_lot" version = "0.12.1" @@ -215,6 +240,18 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "pretty_assertions" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a25e9bcb20aa780fd0bb16b72403a9064d6b3f22f026946029acb941a50af755" +dependencies = [ + "ctor", + "diff", + "output_vt100", + "yansi", +] + [[package]] name = "proc-macro-error" version = "1.0.4" @@ -553,13 +590,20 @@ checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd" [[package]] name = "xiv_csolver" -version = "0.1.5" +version = "0.2.0" dependencies = [ "clap", "lazy_static", + "pretty_assertions", "pyo3", "strum", "strum_macros", "threadpool", "toml", ] + +[[package]] +name = "yansi" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" diff --git a/Cargo.toml b/Cargo.toml index 1eaf085..c49e98e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,13 +1,13 @@ [package] name = "xiv_csolver" -version = "0.1.5" +version = "0.1.6" edition = "2021" authors = ["谭俊健","Dandaedre","Vkyfox"] description = "Small XIV solver library in rust, with python and rust bindings" homepage = "https://proxy.dandaedre.com/gitea/Dandaedre/xiv_csolver" documentation = "https://proxy.dandaedre.com/gitea/Dandaedre/xiv_csolver" repository = "https://proxy.dandaedre.com/gitea/Dandaedre/xiv_csolver.git" -license = "MIT OR Apache-2.0" +license = "Apache-2.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -27,6 +27,9 @@ pyo3 = { version = "0.18.0", features = ["extension-module"] } # [build] # target = ["x86_64-unknown-linux-gnu", "x86_64-unknown-windows-gnu"] +[dev-dependencies] +pretty_assertions = "1" + [profile.release] panic = 'abort' opt-level = 3 @@ -39,13 +42,10 @@ no_python = [] # Removes the python bindings fast = [] # Remove some under optimisations that try to find other routes [lib] -name = "xiv_csolver_lib" # Pending rename xiv_csolver_lib +name = "xiv_csolver_lib" path = "src/lib.rs" crate-type = ["cdylib","rlib"] [[bin]] name = "xiv_csolver_cli" -path = "src/bin/xiv_csolver.rs" - -[tool.maturin] -python-source = "python" \ No newline at end of file +path = "src/bin/xiv_csolver.rs" \ No newline at end of file diff --git a/Makefile.toml b/Makefile.toml index c53db5e..cf4c53b 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -23,6 +23,16 @@ install_crate = "rustfmt" command = "cargo" args = ["fmt", "--", "--emit=files"] +[tasks.testcov] +script_runner = "@shell" +ignore_errors = true +script = [ +"mkdir -p coverage", +"mkdir -p coverage/html", +"CARGO_INCREMENTAL=0 RUSTFLAGS='-Cinstrument-coverage' LLVM_PROFILE_FILE='llvm/cargo-test-%p-%m.profraw' cargo test", +"grcov . --binary-path ./target/debug/deps/ -s . -t html --branch --ignore-not-existing --ignore '../*' --ignore '/*' -o coverage/html/" +] + [tasks.clean] command = "cargo" args = ["clean"] diff --git a/README.md b/README.md index 48fafde..fb2e1c4 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,9 @@ A rust program for solving FFXIV craft recipe. Originaly written by [RikaKagurasaka](https://github.com/RikaKagurasaka/xiv_craft_solver), it now is widely improved and provides python bindings for a GUI (or anything else really) + +![coverage/html/badges/flat.svg](coverage/html/badges/flat.svg) + ### Basic RUST CLI Usage Everything is done through the regular cargo interface 1. Download the latest release. @@ -43,6 +46,7 @@ Options: -V, --version Print version ``` + ## Developpement Please remember to set and use a venv before building While not mandatory, using ``cargo-make`` will provide you with the commands: diff --git a/Todo.md b/Todo.md index 567f72f..e875a41 100644 --- a/Todo.md +++ b/Todo.md @@ -12,8 +12,10 @@ ✅ (PKG) Have cargo-make setup for release/cleanup/build ✅ (PKG) Merge latest pre-release for the GUI ✅ (PKG) Have a rebuild function + 🟩 (CLI) Rework the parameters and return structs to only have one ref each ### Features 🟩 (GUI) Refactor code + 🟩 (GUI) Restore GUI state # Roadmap ## v1.0.0 diff --git a/coverage/html/badges/flat.svg b/coverage/html/badges/flat.svg new file mode 100644 index 0000000..ca7e6f8 --- /dev/null +++ b/coverage/html/badges/flat.svg @@ -0,0 +1,23 @@ + + coverage: 10% + + + + + + + + + + + + + + + coverage + + 10% + + + \ No newline at end of file diff --git a/coverage/html/badges/flat_square.svg b/coverage/html/badges/flat_square.svg new file mode 100644 index 0000000..9f2ccbb --- /dev/null +++ b/coverage/html/badges/flat_square.svg @@ -0,0 +1,13 @@ + + coverage: 10% + + + + + + coverage + 10% + + + \ No newline at end of file diff --git a/coverage/html/badges/for_the_badge.svg b/coverage/html/badges/for_the_badge.svg new file mode 100644 index 0000000..17ec9e4 --- /dev/null +++ b/coverage/html/badges/for_the_badge.svg @@ -0,0 +1,13 @@ + + COVERAGE: 10% + + + + + + COVERAGE + 10% + + + \ No newline at end of file diff --git a/coverage/html/badges/plastic.svg b/coverage/html/badges/plastic.svg new file mode 100644 index 0000000..a127f7c --- /dev/null +++ b/coverage/html/badges/plastic.svg @@ -0,0 +1,25 @@ + + coverage: 10% + + + + + + + + + + + + + + + + + coverage + + 10% + + + \ No newline at end of file diff --git a/coverage/html/badges/social.svg b/coverage/html/badges/social.svg new file mode 100644 index 0000000..81f5278 --- /dev/null +++ b/coverage/html/badges/social.svg @@ -0,0 +1,27 @@ + + Coverage: 10% + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/coverage/html/coverage.json b/coverage/html/coverage.json new file mode 100644 index 0000000..b3f9229 --- /dev/null +++ b/coverage/html/coverage.json @@ -0,0 +1 @@ +{"schemaVersion":1,"label":"coverage","message":"10%","color":"red"} \ No newline at end of file diff --git a/coverage/html/index.html b/coverage/html/index.html new file mode 100644 index 0000000..efa6e0b --- /dev/null +++ b/coverage/html/index.html @@ -0,0 +1,129 @@ + + + + + Grcov report - top_level + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
DirectoryLine CoverageFunctionsBranches
src + + 10.84% + + + 10.84% + + 115 / 1061 + 8.53%29 / 340 100%0 / 0
src/bin + + 1.64% + + + 1.64% + + 1 / 61 + 20%1 / 5 100%0 / 0
tests + + 100% + + + 100% + + 2 / 2 + 100%2 / 2 100%0 / 0
+ + + diff --git a/coverage/html/src/action.rs.html b/coverage/html/src/action.rs.html new file mode 100644 index 0000000..f402e3a --- /dev/null +++ b/coverage/html/src/action.rs.html @@ -0,0 +1,4912 @@ + + + + + Grcov report - action.rs + + +
+ + + +
+
+ 1 +
+
+ +
+
+
use crate::craft::Craft;
+
+
+
+ 2 +
+
+ +
+
+
use crate::specs::{Buff, Success};
+
+
+
+ 3 +
+
+ +
+
+
use lazy_static::lazy_static;
+
+
+
+ 4 +
+
+ +
+
+
#[allow(dead_code)]
+
+
+
+ 5 +
+
+ +
+
+
use std::fmt::Debug;
+
+
+
+ 6 +
+
+ +
+
+

+            
+
+
+ 7 +
+
+ +
+
+
pub struct Action {
+
+
+
+ 8 +
+
+ +
+
+
    pub name: String,
+
+
+
+ 9 +
+
+ +
+
+
    pub dur: u32,
+
+
+
+ 10 +
+
+ +
+
+
    pub cp: u32,
+
+
+
+ 11 +
+
+ +
+
+
    pub progress: u32,
+
+
+
+ 12 +
+
+ +
+
+
    pub quality: u32,
+
+
+
+ 13 +
+
+ +
+
+
    pub buff: Option<(Buff, u8)>,
+
+
+
+ 14 +
+
+ +
+
+
    pub short_name: String,
+
+
+
+ 15 +
+
+ +
+
+
}
+
+
+
+ 16 +
+
+ +
+
+

+            
+
+
+ 17 +
+
+ +
+
+
pub struct ActionBuilder {
+
+
+
+ 18 +
+
+ +
+
+
    action: Action,
+
+
+
+ 19 +
+
+ +
+
+
}
+
+
+
+ 20 +
+
+ +
+
+

+            
+
+
+ 21 +
+
+ +
+
+
impl ActionBuilder {
+
+
+
+ 22 +
+
+ +
+
+
    pub fn new(name: &str) -> Self {
+
+
+
+ 23 +
+
+ +
+
+
        let mut short_name = name.to_string();
+
+
+
+ 24 +
+
+ +
+
+
        short_name = short_name.replace("II", "2");
+
+
+
+ 25 +
+
+ +
+
+
        short_name.retain(|c| !c.is_whitespace() && c != '\'');
+
+
+
+ 26 +
+
+ +
+
+
        short_name[0..1].make_ascii_lowercase();
+
+
+
+ 27 +
+
+ +
+
+
        if name == "Basic Synthesis" {
+
+
+
+ 28 +
+
+ +
+
+
            short_name = "basicSynth2".to_string();
+
+
+
+ 29 +
+
+ +
+
+
        }
+
+
+
+ 30 +
+
+ +
+
+
        if name == "Groundwork" {
+
+
+
+ 31 +
+
+ +
+
+
            short_name = "groundwork".to_string();
+
+
+
+ 32 +
+
+ +
+
+
        }
+
+
+
+ 33 +
+
+ +
+
+
        if name == "Careful Synthesis" {
+
+
+
+ 34 +
+
+ +
+
+
            short_name = "carefulSynthesis".to_string();
+
+
+
+ 35 +
+
+ +
+
+
        }
+
+
+
+ 36 +
+
+ +
+
+

+            
+
+
+ 37 +
+
+ +
+
+
        Self {
+
+
+
+ 38 +
+
+ +
+
+
            action: Action {
+
+
+
+ 39 +
+
+ +
+
+
                name: name.to_string(),
+
+
+
+ 40 +
+
+ +
+
+
                dur: 10,
+
+
+
+ 41 +
+
+ +
+
+
                cp: 0,
+
+
+
+ 42 +
+
+ +
+
+
                progress: 0,
+
+
+
+ 43 +
+
+ +
+
+
                quality: 0,
+
+
+
+ 44 +
+
+ +
+
+
                buff: None,
+
+
+
+ 45 +
+
+ +
+
+
                short_name,
+
+
+
+ 46 +
+
+ +
+
+
            },
+
+
+
+ 47 +
+
+ +
+
+
        }
+
+
+
+ 48 +
+
+ +
+
+
    }
+
+
+
+ 49 +
+
+ +
+
+
    pub fn dur(mut self, dur: u32) -> Self {
+
+
+
+ 50 +
+
+ +
+
+
        self.action.dur = dur;
+
+
+
+ 51 +
+
+ +
+
+
        self
+
+
+
+ 52 +
+
+ +
+
+
    }
+
+
+
+ 53 +
+
+ +
+
+
    pub fn cp(mut self, cp: u32) -> Self {
+
+
+
+ 54 +
+
+ +
+
+
        self.action.cp = cp;
+
+
+
+ 55 +
+
+ +
+
+
        self
+
+
+
+ 56 +
+
+ +
+
+
    }
+
+
+
+ 57 +
+
+ +
+
+
    pub fn progress(mut self, progress: u32) -> Self {
+
+
+
+ 58 +
+
+ +
+
+
        self.action.progress = progress;
+
+
+
+ 59 +
+
+ +
+
+
        self
+
+
+
+ 60 +
+
+ +
+
+
    }
+
+
+
+ 61 +
+
+ +
+
+
    pub fn quality(mut self, quality: u32) -> Self {
+
+
+
+ 62 +
+
+ +
+
+
        self.action.quality = quality;
+
+
+
+ 63 +
+
+ +
+
+
        self
+
+
+
+ 64 +
+
+ +
+
+
    }
+
+
+
+ 65 +
+
+ +
+
+
    pub fn buff(mut self, buff: Option<(Buff, u8)>) -> Self {
+
+
+
+ 66 +
+
+ +
+
+
        self.action.buff = buff;
+
+
+
+ 67 +
+
+ +
+
+
        self
+
+
+
+ 68 +
+
+ +
+
+
    }
+
+
+
+ 69 +
+
+ +
+
+
    pub fn build(self) -> Action {
+
+
+
+ 70 +
+
+ +
+
+
        self.action
+
+
+
+ 71 +
+
+ +
+
+
    }
+
+
+
+ 72 +
+
+ +
+
+
}
+
+
+
+ 73 +
+
+ +
+
+

+            
+
+
+ 74 +
+
+ +
+
+
impl PartialEq for Action {
+
+
+
+ 75 +
+
+ +
+
+
    fn eq(&self, other: &Self) -> bool {
+
+
+
+ 76 +
+
+ +
+
+
        self.cp == other.cp
+
+
+
+ 77 +
+
+ +
+
+
            && self.dur == other.dur
+
+
+
+ 78 +
+
+ +
+
+
            && self.progress == other.progress
+
+
+
+ 79 +
+
+ +
+
+
            && self.quality == other.quality
+
+
+
+ 80 +
+
+ +
+
+
    }
+
+
+
+ 81 +
+
+ +
+
+
}
+
+
+
+ 82 +
+
+ +
+
+

+            
+
+
+ 83 +
+
+ +
+
+
impl Action {
+
+
+
+ 84 +
+
+ +
+
+
    pub fn get_name(&self) -> String {
+
+
+
+ 85 +
+
+ +
+
+
        self.name.clone()
+
+
+
+ 86 +
+
+ +
+
+
    }
+
+
+
+ 87 +
+
+ +
+
+
    pub fn get_cp_cost(&self, _craft: &Craft) -> u32 {
+
+
+
+ 88 +
+
+ +
+
+
        if self == &ACTIONS.standard_touch && _craft.buffs.basic_touch > 0 {
+
+
+
+ 89 +
+
+ +
+
+
            return 18;
+
+
+
+ 90 +
+
+ +
+
+
        };
+
+
+
+ 91 +
+
+ +
+
+
        if self == &ACTIONS.advanced_touch && _craft.buffs.standard_touch > 0 {
+
+
+
+ 92 +
+
+ +
+
+
            return 18;
+
+
+
+ 93 +
+
+ +
+
+
        };
+
+
+
+ 94 +
+
+ +
+
+
        self.cp
+
+
+
+ 95 +
+
+ +
+
+
    }
+
+
+
+ 96 +
+
+ +
+
+
    pub fn get_durability_cost(&self, _craft: &Craft) -> u32 {
+
+
+
+ 97 +
+
+ +
+
+
        if self == &ACTIONS.masters_mend {
+
+
+
+ 98 +
+
+ +
+
+
            return 30;
+
+
+
+ 99 +
+
+ +
+
+
        }
+
+
+
+ 100 +
+
+ +
+
+
        if self.dur == 0 || self.progress == 0 && self.quality == 0 {
+
+
+
+ 101 +
+
+ +
+
+
            return 0;
+
+
+
+ 102 +
+
+ +
+
+
        }
+
+
+
+ 103 +
+
+ +
+
+
        let mut dur = self.dur;
+
+
+
+ 104 +
+
+ +
+
+
        if _craft.buffs.waste_not > 0 {
+
+
+
+ 105 +
+
+ +
+
+
            dur /= 2;
+
+
+
+ 106 +
+
+ +
+
+
        }
+
+
+
+ 107 +
+
+ +
+
+
        if dur < 5 {
+
+
+
+ 108 +
+
+ +
+
+
            dur = 5;
+
+
+
+ 109 +
+
+ +
+
+
        }
+
+
+
+ 110 +
+
+ +
+
+
        dur
+
+
+
+ 111 +
+
+ +
+
+
    }
+
+
+
+ 112 +
+
+ +
+
+
    pub fn get_progress(&self, _craft: &Craft) -> u32 {
+
+
+
+ 113 +
+
+ +
+
+
        let mut prog = self.progress as f64;
+
+
+
+ 114 +
+
+ +
+
+
        if self.dur == 20 && _craft.durability < self.get_durability_cost(_craft) as i32 {
+
+
+
+ 115 +
+
+ +
+
+
            prog /= 2.0;
+
+
+
+ 116 +
+
+ +
+
+
        }
+
+
+
+ 117 +
+
+ +
+
+
        let mut mult = 1.0;
+
+
+
+ 118 +
+
+ +
+
+
        if _craft.buffs.muscle_memory > 0 {
+
+
+
+ 119 +
+
+ +
+
+
            mult += 1.0;
+
+
+
+ 120 +
+
+ +
+
+
        }
+
+
+
+ 121 +
+
+ +
+
+
        if _craft.buffs.veneration > 0 {
+
+
+
+ 122 +
+
+ +
+
+
            mult += 0.5;
+
+
+
+ 123 +
+
+ +
+
+
        }
+
+
+
+ 124 +
+
+ +
+
+
        (prog * mult).floor() as u32
+
+
+
+ 125 +
+
+ +
+
+
    }
+
+
+
+ 126 +
+
+ +
+
+
    pub fn get_quality(&self, _craft: &Craft) -> u32 {
+
+
+
+ 127 +
+
+ +
+
+
        let mut qual = self.quality as f64;
+
+
+
+ 128 +
+
+ +
+
+
        if self == &ACTIONS.byregot_blessing {
+
+
+
+ 129 +
+
+ +
+
+
            qual = (100 + 20 * _craft.buffs.inner_quiet as u32) as f64;
+
+
+
+ 130 +
+
+ +
+
+
        }
+
+
+
+ 131 +
+
+ +
+
+
        if self.dur == 20 && _craft.durability < self.get_durability_cost(_craft) as i32 {
+
+
+
+ 132 +
+
+ +
+
+
            qual /= 2.0;
+
+
+
+ 133 +
+
+ +
+
+
        }
+
+
+
+ 134 +
+
+ +
+
+
        let mut mult = 1.0;
+
+
+
+ 135 +
+
+ +
+
+
        if _craft.buffs.great_strides > 0 {
+
+
+
+ 136 +
+
+ +
+
+
            mult += 1.0;
+
+
+
+ 137 +
+
+ +
+
+
        }
+
+
+
+ 138 +
+
+ +
+
+
        if _craft.buffs.innovation > 0 {
+
+
+
+ 139 +
+
+ +
+
+
            mult += 0.5;
+
+
+
+ 140 +
+
+ +
+
+
        }
+
+
+
+ 141 +
+
+ +
+
+
        let iq_mult = (_craft.buffs.inner_quiet as f64 * 0.1) + 1.0;
+
+
+
+ 142 +
+
+ +
+
+
        (qual * mult * iq_mult).floor() as u32
+
+
+
+ 143 +
+
+ +
+
+
    }
+
+
+
+ 144 +
+
+ +
+
+
    pub fn get_buff(&self) -> Option<(Buff, u8)> {
+
+
+
+ 145 +
+
+ +
+
+
        self.buff
+
+
+
+ 146 +
+
+ +
+
+
    }
+
+
+
+ 147 +
+
+ +
+
+
    pub fn can_use(&self, _craft: &Craft) -> bool {
+
+
+
+ 148 +
+
+ +
+
+
        if self.get_cp_cost(_craft) > _craft.cp as u32 {
+
+
+
+ 149 +
+
+ +
+
+
            return false;
+
+
+
+ 150 +
+
+ +
+
+
        }
+
+
+
+ 151 +
+
+ +
+
+
        if _craft.success != Success::Pending {
+
+
+
+ 152 +
+
+ +
+
+
            return false;
+
+
+
+ 153 +
+
+ +
+
+
        }
+
+
+
+ 154 +
+
+ +
+
+
        if self == &ACTIONS.byregot_blessing {
+
+
+
+ 155 +
+
+ +
+
+
            return _craft.buffs.inner_quiet > 0;
+
+
+
+ 156 +
+
+ +
+
+
        }
+
+
+
+ 157 +
+
+ +
+
+
        if self == &ACTIONS.muscle_memory || self == &ACTIONS.reflect {
+
+
+
+ 158 +
+
+ +
+
+
            return _craft.step_count == 0;
+
+
+
+ 159 +
+
+ +
+
+
        }
+
+
+
+ 160 +
+
+ +
+
+
        if self == &ACTIONS.trained_finesse {
+
+
+
+ 161 +
+
+ +
+
+
            return _craft.buffs.inner_quiet >= 10;
+
+
+
+ 162 +
+
+ +
+
+
        }
+
+
+
+ 163 +
+
+ +
+
+
        true
+
+
+
+ 164 +
+
+ +
+
+
    }
+
+
+
+ 165 +
+
+ +
+
+
}
+
+
+
+ 166 +
+
+ +
+
+

+            
+
+
+ 167 +
+
+ +
+
+
impl Debug for Action {
+
+
+
+ 168 +
+
+ +
+
+
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+
+
+
+ 169 +
+
+ +
+
+
        f.write_str(&self.name)
+
+
+
+ 170 +
+
+ +
+
+
    }
+
+
+
+ 171 +
+
+ +
+
+
}
+
+
+
+ 172 +
+
+ +
+
+

+            
+
+
+ 173 +
+
+ +
+
+
pub struct ActionList {
+
+
+
+ 174 +
+
+ +
+
+
    pub muscle_memory: Action,
+
+
+
+ 175 +
+
+ +
+
+
    pub reflect: Action,
+
+
+
+ 176 +
+
+ +
+
+
    pub basic_synthesis: Action,
+
+
+
+ 177 +
+
+ +
+
+
    pub careful_synthesis: Action,
+
+
+
+ 178 +
+
+ +
+
+
    pub groundwork: Action,
+
+
+
+ 179 +
+
+ +
+
+
    pub prudent_synthesis: Action,
+
+
+
+ 180 +
+
+ +
+
+
    pub delicate_synthesis: Action,
+
+
+
+ 181 +
+
+ +
+
+
    pub basic_touch: Action,
+
+
+
+ 182 +
+
+ +
+
+
    pub standard_touch: Action,
+
+
+
+ 183 +
+
+ +
+
+
    pub byregot_blessing: Action,
+
+
+
+ 184 +
+
+ +
+
+
    pub prudent_touch: Action,
+
+
+
+ 185 +
+
+ +
+
+
    pub preparatory_touch: Action,
+
+
+
+ 186 +
+
+ +
+
+
    pub advanced_touch: Action,
+
+
+
+ 187 +
+
+ +
+
+
    pub trained_finesse: Action,
+
+
+
+ 188 +
+
+ +
+
+
    pub masters_mend: Action,
+
+
+
+ 189 +
+
+ +
+
+
    pub waste_not: Action,
+
+
+
+ 190 +
+
+ +
+
+
    pub waste_not_ii: Action,
+
+
+
+ 191 +
+
+ +
+
+
    pub manipulation: Action,
+
+
+
+ 192 +
+
+ +
+
+
    pub veneration: Action,
+
+
+
+ 193 +
+
+ +
+
+
    pub great_strides: Action,
+
+
+
+ 194 +
+
+ +
+
+
    pub innovation: Action,
+
+
+
+ 195 +
+
+ +
+
+
    //pub observe: Action,
+
+
+
+ 196 +
+
+ +
+
+
    //pub focused_synthesis: Action,
+
+
+
+ 197 +
+
+ +
+
+
}
+
+
+
+ 198 +
+
+ +
+
+

+            
+
+
+ 199 +
+
+ +
+
+
impl Default for ActionList {
+
+
+
+ 200 +
+
+ +
+
+
    fn default() -> Self {
+
+
+
+ 201 +
+
+ +
+
+
        Self {
+
+
+
+ 202 +
+
+ +
+
+
            muscle_memory: ActionBuilder::new("Muscle Memory")
+
+
+
+ 203 +
+
+ +
+
+
                .cp(6)
+
+
+
+ 204 +
+
+ +
+
+
                .progress(300)
+
+
+
+ 205 +
+
+ +
+
+
                .buff(Some((Buff::MuscleMemory, 5)))
+
+
+
+ 206 +
+
+ +
+
+
                .build(),
+
+
+
+ 207 +
+
+ +
+
+
            reflect: ActionBuilder::new("Reflect")
+
+
+
+ 208 +
+
+ +
+
+
                .cp(6)
+
+
+
+ 209 +
+
+ +
+
+
                .quality(100)
+
+
+
+ 210 +
+
+ +
+
+
                .buff(Some((Buff::InnerQuiet, 1)))
+
+
+
+ 211 +
+
+ +
+
+
                .build(),
+
+
+
+ 212 +
+
+ +
+
+

+            
+
+
+ 213 +
+
+ +
+
+
            basic_synthesis: ActionBuilder::new("Basic Synthesis").progress(120).build(),
+
+
+
+ 214 +
+
+ +
+
+
            careful_synthesis: ActionBuilder::new("Careful Synthesis")
+
+
+
+ 215 +
+
+ +
+
+
                .cp(7)
+
+
+
+ 216 +
+
+ +
+
+
                .progress(180)
+
+
+
+ 217 +
+
+ +
+
+
                .build(),
+
+
+
+ 218 +
+
+ +
+
+
            groundwork: ActionBuilder::new("Groundwork")
+
+
+
+ 219 +
+
+ +
+
+
                .cp(18)
+
+
+
+ 220 +
+
+ +
+
+
                .dur(20)
+
+
+
+ 221 +
+
+ +
+
+
                .progress(360)
+
+
+
+ 222 +
+
+ +
+
+
                .build(),
+
+
+
+ 223 +
+
+ +
+
+
            prudent_synthesis: ActionBuilder::new("Prudent Synthesis")
+
+
+
+ 224 +
+
+ +
+
+
                .cp(18)
+
+
+
+ 225 +
+
+ +
+
+
                .dur(5)
+
+
+
+ 226 +
+
+ +
+
+
                .progress(180)
+
+
+
+ 227 +
+
+ +
+
+
                .build(),
+
+
+
+ 228 +
+
+ +
+
+
            delicate_synthesis: ActionBuilder::new("Delicate Synthesis")
+
+
+
+ 229 +
+
+ +
+
+
                .cp(32)
+
+
+
+ 230 +
+
+ +
+
+
                .progress(100)
+
+
+
+ 231 +
+
+ +
+
+
                .quality(100)
+
+
+
+ 232 +
+
+ +
+
+
                .build(),
+
+
+
+ 233 +
+
+ +
+
+

+            
+
+
+ 234 +
+
+ +
+
+
            basic_touch: ActionBuilder::new("Basic Touch")
+
+
+
+ 235 +
+
+ +
+
+
                .cp(18)
+
+
+
+ 236 +
+
+ +
+
+
                .quality(100)
+
+
+
+ 237 +
+
+ +
+
+
                .buff(Some((Buff::BasicTouch, 1)))
+
+
+
+ 238 +
+
+ +
+
+
                .build(),
+
+
+
+ 239 +
+
+ +
+
+
            standard_touch: ActionBuilder::new("Standard Touch")
+
+
+
+ 240 +
+
+ +
+
+
                .quality(125)
+
+
+
+ 241 +
+
+ +
+
+
                .cp(32)
+
+
+
+ 242 +
+
+ +
+
+
                .buff(Some((Buff::StandardTouch, 1)))
+
+
+
+ 243 +
+
+ +
+
+
                .build(),
+
+
+
+ 244 +
+
+ +
+
+
            byregot_blessing: ActionBuilder::new("Byregot's Blessing")
+
+
+
+ 245 +
+
+ +
+
+
                .cp(24)
+
+
+
+ 246 +
+
+ +
+
+
                .quality(100)
+
+
+
+ 247 +
+
+ +
+
+
                .buff(Some((Buff::InnerQuiet, 0)))
+
+
+
+ 248 +
+
+ +
+
+
                .build(),
+
+
+
+ 249 +
+
+ +
+
+
            prudent_touch: ActionBuilder::new("Prudent Touch")
+
+
+
+ 250 +
+
+ +
+
+
                .cp(25)
+
+
+
+ 251 +
+
+ +
+
+
                .dur(5)
+
+
+
+ 252 +
+
+ +
+
+
                .quality(100)
+
+
+
+ 253 +
+
+ +
+
+
                .build(),
+
+
+
+ 254 +
+
+ +
+
+
            preparatory_touch: ActionBuilder::new("Preparatory Touch")
+
+
+
+ 255 +
+
+ +
+
+
                .cp(40)
+
+
+
+ 256 +
+
+ +
+
+
                .dur(20)
+
+
+
+ 257 +
+
+ +
+
+
                .quality(200)
+
+
+
+ 258 +
+
+ +
+
+
                .buff(Some((Buff::InnerQuiet, 1)))
+
+
+
+ 259 +
+
+ +
+
+
                .build(),
+
+
+
+ 260 +
+
+ +
+
+
            advanced_touch: ActionBuilder::new("Advanced Touch")
+
+
+
+ 261 +
+
+ +
+
+
                .quality(150)
+
+
+
+ 262 +
+
+ +
+
+
                .cp(46)
+
+
+
+ 263 +
+
+ +
+
+
                .build(),
+
+
+
+ 264 +
+
+ +
+
+
            trained_finesse: ActionBuilder::new("Trained Finesse")
+
+
+
+ 265 +
+
+ +
+
+
                .cp(32)
+
+
+
+ 266 +
+
+ +
+
+
                .quality(100)
+
+
+
+ 267 +
+
+ +
+
+
                .dur(0)
+
+
+
+ 268 +
+
+ +
+
+
                .build(),
+
+
+
+ 269 +
+
+ +
+
+

+            
+
+
+ 270 +
+
+ +
+
+
            masters_mend: ActionBuilder::new("Master's Mend").cp(88).build(),
+
+
+
+ 271 +
+
+ +
+
+
            waste_not: ActionBuilder::new("Waste Not")
+
+
+
+ 272 +
+
+ +
+
+
                .cp(56)
+
+
+
+ 273 +
+
+ +
+
+
                .buff(Some((Buff::WasteNot, 4)))
+
+
+
+ 274 +
+
+ +
+
+
                .build(),
+
+
+
+ 275 +
+
+ +
+
+
            waste_not_ii: ActionBuilder::new("Waste Not II")
+
+
+
+ 276 +
+
+ +
+
+
                .cp(98)
+
+
+
+ 277 +
+
+ +
+
+
                .buff(Some((Buff::WasteNot, 8)))
+
+
+
+ 278 +
+
+ +
+
+
                .build(),
+
+
+
+ 279 +
+
+ +
+
+
            manipulation: ActionBuilder::new("Manipulation")
+
+
+
+ 280 +
+
+ +
+
+
                .cp(96)
+
+
+
+ 281 +
+
+ +
+
+
                .buff(Some((Buff::Manipulation, 8)))
+
+
+
+ 282 +
+
+ +
+
+
                .build(),
+
+
+
+ 283 +
+
+ +
+
+
            veneration: ActionBuilder::new("Veneration")
+
+
+
+ 284 +
+
+ +
+
+
                .cp(18)
+
+
+
+ 285 +
+
+ +
+
+
                .buff(Some((Buff::Veneration, 4)))
+
+
+
+ 286 +
+
+ +
+
+
                .build(),
+
+
+
+ 287 +
+
+ +
+
+
            great_strides: ActionBuilder::new("Great Strides")
+
+
+
+ 288 +
+
+ +
+
+
                .cp(32)
+
+
+
+ 289 +
+
+ +
+
+
                .buff(Some((Buff::GreatStrides, 3)))
+
+
+
+ 290 +
+
+ +
+
+
                .build(),
+
+
+
+ 291 +
+
+ +
+
+
            innovation: ActionBuilder::new("Innovation")
+
+
+
+ 292 +
+
+ +
+
+
                .cp(18)
+
+
+
+ 293 +
+
+ +
+
+
                .buff(Some((Buff::Innovation, 4)))
+
+
+
+ 294 +
+
+ +
+
+
                .build(),
+
+
+
+ 295 +
+
+ +
+
+
            // Todo: Add back
+
+
+
+ 296 +
+
+ +
+
+
            //observe: ActionBuilder::new("observe").cp(18).buff(Some((Buff::Observe, 1))).build(),
+
+
+
+ 297 +
+
+ +
+
+
            //focused_synthesis: ActionBuilder::new("focused_synthesis").cp(18).quality(100).build(),
+
+
+
+ 298 +
+
+ +
+
+
        }
+
+
+
+ 299 +
+
+ +
+
+
    }
+
+
+
+ 300 +
+
+ +
+
+
}
+
+
+
+ 301 +
+
+ +
+
+

+            
+
+
+ 302 +
+
+ +
+
+
lazy_static! {
+
+
+
+ 303 +
+
+ +
+
+
    pub static ref ACTIONS: ActionList = ActionList::default();
+
+
+
+ 304 +
+
+ +
+
+
}
+
+
+
+ + + diff --git a/coverage/html/src/bin/index.html b/coverage/html/src/bin/index.html new file mode 100644 index 0000000..1c5c163 --- /dev/null +++ b/coverage/html/src/bin/index.html @@ -0,0 +1,81 @@ + + + + + Grcov report - src/bin + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
FileLine CoverageFunctionsBranches
xiv_csolver.rs + + 1.64% + + + 1.64% + + 1 / 61 + 20%1 / 5 100%0 / 0
+ + + diff --git a/coverage/html/src/bin/xiv_csolver.rs.html b/coverage/html/src/bin/xiv_csolver.rs.html new file mode 100644 index 0000000..07f2639 --- /dev/null +++ b/coverage/html/src/bin/xiv_csolver.rs.html @@ -0,0 +1,1232 @@ + + + + + Grcov report - xiv_csolver.rs + + +
+ + + +
+
+ 1 +
+
+ 11 +
+
+
// #![warn(missing_docs,unsafe_code,unstable_features,)]
+
+
+
+ 2 +
+
+ +
+
+
// #![feature(no_coverage)]
+
+
+
+ 3 +
+
+ +
+
+
// #![warn(missing_docs)]
+
+
+
+ 4 +
+
+ +
+
+

+            
+
+
+ 5 +
+
+ +
+
+
use clap::Parser;
+
+
+
+ 6 +
+
+ +
+
+
use std::time::Instant;
+
+
+
+ 7 +
+
+ +
+
+
use xiv_csolver_lib;
+
+
+
+ 8 +
+
+ +
+
+

+            
+
+
+ 9 +
+
+ +
+
+
#[derive(Debug)]
+
+
+
+ 10 +
+
+ +
+
+
struct CustomError(String);
+
+
+
+ 11 +
+
+ +
+
+

+            
+
+
+ 12 +
+
+ +
+
+
fn main() {
+
+
+
+ 13 +
+
+ +
+
+
    let args = xiv_csolver_lib::io::Args::parse();
+
+
+
+ 14 +
+
+ +
+
+
    let params = xiv_csolver_lib::io::Parameters::from_args(&args);
+
+
+
+ 15 +
+
+ +
+
+

+            
+
+
+ 16 +
+
+ +
+
+
    // Start timer
+
+
+
+ 17 +
+
+ +
+
+
    let now = Instant::now();
+
+
+
+ 18 +
+
+ +
+
+
    println!("Solving...");
+
+
+
+ 19 +
+
+ +
+
+

+            
+
+
+ 20 +
+
+ +
+
+
    // Solve from config
+
+
+
+ 21 +
+
+ +
+
+
    let (recipe, stats) =
+
+
+
+ 22 +
+
+ +
+
+
        xiv_csolver_lib::load_from_config(&args.recipe_name, &args.file_name, &args.character_name);
+
+
+
+ 23 +
+
+ +
+
+
    let results = xiv_csolver_lib::solve_craft(recipe, stats, params);
+
+
+
+ 24 +
+
+ +
+
+

+            
+
+
+ 25 +
+
+ +
+
+
    // Stop timer
+
+
+
+ 26 +
+
+ +
+
+
    let t_final = now.elapsed().as_millis();
+
+
+
+ 27 +
+
+ +
+
+

+            
+
+
+ 28 +
+
+ +
+
+
    // Show best result depending on selected value
+
+
+
+ 29 +
+
+ +
+
+
    match results {
+
+
+
+ 30 +
+
+ +
+
+
        None => {
+
+
+
+ 31 +
+
+ +
+
+
            println!(
+
+
+
+ 32 +
+
+ +
+
+
                "[Error] No solutions found for craft '{}' with crafter '{}' (ms)",
+
+
+
+ 33 +
+
+ +
+
+
                args.recipe_name, args.character_name
+
+
+
+ 34 +
+
+ +
+
+
            );
+
+
+
+ 35 +
+
+ +
+
+
            return;
+
+
+
+ 36 +
+
+ +
+
+
        }
+
+
+
+ 37 +
+
+ +
+
+
        Some(ref res) => {
+
+
+
+ 38 +
+
+ +
+
+
            // Show best results
+
+
+
+ 39 +
+
+ +
+
+
            if args.verbose > 0 {
+
+
+
+ 40 +
+
+ +
+
+
                println!("[Final] {} results were found:", res.len());
+
+
+
+ 41 +
+
+ +
+
+
                #[cfg(feature = "verbose")]
+
+
+
+ 42 +
+
+ +
+
+
                if args.verbose > 1 {
+
+
+
+ 43 +
+
+ +
+
+
                    xiv_csolver_lib::print_routes(&results);
+
+
+
+ 44 +
+
+ +
+
+
                }
+
+
+
+ 45 +
+
+ +
+
+
            }
+
+
+
+ 46 +
+
+ +
+
+
        }
+
+
+
+ 47 +
+
+ +
+
+
    }
+
+
+
+ 48 +
+
+ +
+
+
    println!("\n > SOLUTION [Least steps] <");
+
+
+
+ 49 +
+
+ +
+
+
    xiv_csolver_lib::find_fast_route(&results)
+
+
+
+ 50 +
+
+ +
+
+
        .unwrap()
+
+
+
+ 51 +
+
+ +
+
+
        .pretty_print();
+
+
+
+ 52 +
+
+ +
+
+
    println!("\n > SOLUTION [Most durability] <");
+
+
+
+ 53 +
+
+ +
+
+
    xiv_csolver_lib::find_safe_route(&results)
+
+
+
+ 54 +
+
+ +
+
+
        .unwrap()
+
+
+
+ 55 +
+
+ +
+
+
        .pretty_print();
+
+
+
+ 56 +
+
+ +
+
+
    println!("\n > SOLUTION [Most quality] < ");
+
+
+
+ 57 +
+
+ +
+
+
    xiv_csolver_lib::find_quality_route(&results)
+
+
+
+ 58 +
+
+ +
+
+
        .unwrap()
+
+
+
+ 59 +
+
+ +
+
+
        .pretty_print();
+
+
+
+ 60 +
+
+ +
+
+

+            
+
+
+ 61 +
+
+ +
+
+
    // #[cfg(feature = "verbose")]
+
+
+
+ 62 +
+
+ +
+
+
    // if params.verbose>2{
+
+
+
+ 63 +
+
+ +
+
+
    //     println!("[F] Top routes {:?}",results);
+
+
+
+ 64 +
+
+ +
+
+
    // }
+
+
+
+ 65 +
+
+ +
+
+

+            
+
+
+ 66 +
+
+ +
+
+
    // Wait for user input
+
+
+
+ 67 +
+
+ +
+
+
    println!(
+
+
+
+ 68 +
+
+ +
+
+
        "\nProgram finished successfully in {}ms\nPress enter to exit...",
+
+
+
+ 69 +
+
+ +
+
+
        t_final
+
+
+
+ 70 +
+
+ +
+
+
    );
+
+
+
+ 71 +
+
+ +
+
+
    let mut input = String::new();
+
+
+
+ 72 +
+
+ +
+
+
    std::io::stdin().read_line(&mut input).unwrap();
+
+
+
+ 73 +
+
+ +
+
+
    ()
+
+
+
+ 74 +
+
+ +
+
+
}
+
+
+
+ + + diff --git a/coverage/html/src/craft.rs.html b/coverage/html/src/craft.rs.html new file mode 100644 index 0000000..d3e70e2 --- /dev/null +++ b/coverage/html/src/craft.rs.html @@ -0,0 +1,2400 @@ + + + + + Grcov report - craft.rs + + +
+ + + +
+
+ 1 +
+
+ +
+
+
use crate::action::Action;
+
+
+
+ 2 +
+
+ +
+
+
use crate::specs::{Buff, BuffState, Recipe, Stats, Success};
+
+
+
+ 3 +
+
+ +
+
+
use crate::Parameters;
+
+
+
+ 4 +
+
+ +
+
+
use std::fmt::{Debug, Display, Formatter};
+
+
+
+ 5 +
+
+ +
+
+

+            
+
+
+ 6 +
+
+ +
+
+
#[derive(Clone)]
+
+
+
+ 7 +
+
+ +
+
+
pub struct Craft<'a> {
+
+
+
+ 8 +
+
+ +
+
+
    pub recipe: Recipe,
+
+
+
+ 9 +
+
+ +
+
+
    pub stats: Stats,
+
+
+
+ 10 +
+
+ +
+
+
    pub buffs: BuffState,
+
+
+
+ 11 +
+
+ +
+
+
    pub step_count: u32,
+
+
+
+ 12 +
+
+ +
+
+
    pub durability: i32,
+
+
+
+ 13 +
+
+ +
+
+
    pub progression: u32,
+
+
+
+ 14 +
+
+ +
+
+
    pub quality: u32,
+
+
+
+ 15 +
+
+ +
+
+
    pub cp: i32,
+
+
+
+ 16 +
+
+ +
+
+
    pub success: Success,
+
+
+
+ 17 +
+
+ +
+
+
    pub actions: Vec<&'a Action>,
+
+
+
+ 18 +
+
+ +
+
+
    pub args: Parameters,
+
+
+
+ 19 +
+
+ +
+
+
}
+
+
+
+ 20 +
+
+ +
+
+

+            
+
+
+ 21 +
+
+ +
+
+
impl<'a> Craft<'a> {
+
+
+
+ 22 +
+
+ +
+
+
    pub fn new(recipe: Recipe, stats: Stats, params: Parameters) -> Craft<'a> {
+
+
+
+ 23 +
+
+ +
+
+
        Self {
+
+
+
+ 24 +
+
+ +
+
+
            recipe,
+
+
+
+ 25 +
+
+ +
+
+
            stats,
+
+
+
+ 26 +
+
+ +
+
+
            buffs: BuffState::default(),
+
+
+
+ 27 +
+
+ +
+
+
            step_count: 0,
+
+
+
+ 28 +
+
+ +
+
+
            durability: recipe.durability as i32,
+
+
+
+ 29 +
+
+ +
+
+
            progression: 0,
+
+
+
+ 30 +
+
+ +
+
+
            quality: 0,
+
+
+
+ 31 +
+
+ +
+
+
            cp: stats.max_cp as i32,
+
+
+
+ 32 +
+
+ +
+
+
            success: Success::Pending,
+
+
+
+ 33 +
+
+ +
+
+
            actions: Vec::new(),
+
+
+
+ 34 +
+
+ +
+
+
            args: params,
+
+
+
+ 35 +
+
+ +
+
+
        }
+
+
+
+ 36 +
+
+ +
+
+
    }
+
+
+
+ 37 +
+
+ +
+
+

+            
+
+
+ 38 +
+
+ +
+
+
    pub fn get_base_progression(&self) -> u32 {
+
+
+
+ 39 +
+
+ +
+
+
        let base_value = (self.stats.craftsmanship as f64 / 10.0)
+
+
+
+ 40 +
+
+ +
+
+
            / (self.recipe.progress_divider as f64 / 100.0)
+
+
+
+ 41 +
+
+ +
+
+
            + 2.0;
+
+
+
+ 42 +
+
+ +
+
+
        (base_value * (self.recipe.progress_modifier as f64 / 100.0) as f64).floor() as u32
+
+
+
+ 43 +
+
+ +
+
+
    }
+
+
+
+ 44 +
+
+ +
+
+

+            
+
+
+ 45 +
+
+ +
+
+
    pub fn get_base_quality(&self) -> u32 {
+
+
+
+ 46 +
+
+ +
+
+
        let base_value = (self.stats.control as f64 / 10.0)
+
+
+
+ 47 +
+
+ +
+
+
            / (self.recipe.quality_divider as f64 / 100.0)
+
+
+
+ 48 +
+
+ +
+
+
            + 35.0;
+
+
+
+ 49 +
+
+ +
+
+
        (base_value * (self.recipe.quality_modifier as f64 / 100.0) as f64).floor() as u32
+
+
+
+ 50 +
+
+ +
+
+
    }
+
+
+
+ 51 +
+
+ +
+
+

+            
+
+
+ 52 +
+
+ +
+
+
    pub fn run_action(&mut self, action: &'a Action) -> &mut Craft<'a> {
+
+
+
+ 53 +
+
+ +
+
+
        if !action.can_use(self) {
+
+
+
+ 54 +
+
+ +
+
+
            self.success = Success::Failure;
+
+
+
+ 55 +
+
+ +
+
+
            return self;
+
+
+
+ 56 +
+
+ +
+
+
        }
+
+
+
+ 57 +
+
+ +
+
+
        self.step_count += 1;
+
+
+
+ 58 +
+
+ +
+
+
        self.cp -= action.get_cp_cost(self) as i32;
+
+
+
+ 59 +
+
+ +
+
+
        self.durability -= action.get_durability_cost(self) as i32;
+
+
+
+ 60 +
+
+ +
+
+
        self.progression += (action.get_progress(self) as f64
+
+
+
+ 61 +
+
+ +
+
+
            * (self.get_base_progression() as f64 / 100.0))
+
+
+
+ 62 +
+
+ +
+
+
            .floor() as u32;
+
+
+
+ 63 +
+
+ +
+
+
        self.quality += (action.get_quality(self) as f64 * (self.get_base_quality() as f64 / 100.0))
+
+
+
+ 64 +
+
+ +
+
+
            .floor() as u32;
+
+
+
+ 65 +
+
+ +
+
+
        if self.progression >= self.recipe.progress {
+
+
+
+ 66 +
+
+ +
+
+
            self.success = Success::Success;
+
+
+
+ 67 +
+
+ +
+
+
        }
+
+
+
+ 68 +
+
+ +
+
+
        if self.durability <= 0 {
+
+
+
+ 69 +
+
+ +
+
+
            self.success = Success::Failure;
+
+
+
+ 70 +
+
+ +
+
+
        }
+
+
+
+ 71 +
+
+ +
+
+
        if self.buffs.manipulation > 0 {
+
+
+
+ 72 +
+
+ +
+
+
            self.durability += 5;
+
+
+
+ 73 +
+
+ +
+
+
        }
+
+
+
+ 74 +
+
+ +
+
+
        if action.quality > 0 {
+
+
+
+ 75 +
+
+ +
+
+
            self.buffs.inner_quiet += 1;
+
+
+
+ 76 +
+
+ +
+
+
        }
+
+
+
+ 77 +
+
+ +
+
+
        self.buffs.tick();
+
+
+
+ 78 +
+
+ +
+
+
        if action.progress > 0 {
+
+
+
+ 79 +
+
+ +
+
+
            self.buffs.remove(Buff::MuscleMemory);
+
+
+
+ 80 +
+
+ +
+
+
        }
+
+
+
+ 81 +
+
+ +
+
+
        if action.quality > 0 {
+
+
+
+ 82 +
+
+ +
+
+
            self.buffs.remove(Buff::GreatStrides);
+
+
+
+ 83 +
+
+ +
+
+
        }
+
+
+
+ 84 +
+
+ +
+
+
        if let Some((buff, duration)) = action.get_buff() {
+
+
+
+ 85 +
+
+ +
+
+
            self.buffs.apply(buff, duration);
+
+
+
+ 86 +
+
+ +
+
+
        }
+
+
+
+ 87 +
+
+ +
+
+
        if self.durability > self.recipe.durability as i32 {
+
+
+
+ 88 +
+
+ +
+
+
            self.durability = self.recipe.durability as i32;
+
+
+
+ 89 +
+
+ +
+
+
        }
+
+
+
+ 90 +
+
+ +
+
+
        if self.buffs.inner_quiet > 10 {
+
+
+
+ 91 +
+
+ +
+
+
            self.buffs.inner_quiet = 10;
+
+
+
+ 92 +
+
+ +
+
+
        }
+
+
+
+ 93 +
+
+ +
+
+

+            
+
+
+ 94 +
+
+ +
+
+
        self.actions.push(action);
+
+
+
+ 95 +
+
+ +
+
+
        return self;
+
+
+
+ 96 +
+
+ +
+
+
    }
+
+
+
+ 97 +
+
+ +
+
+

+            
+
+
+ 98 +
+
+ +
+
+
    // Assumes the craft is finished and tries to add the last actions
+
+
+
+ 99 +
+
+ +
+
+
    // pub fn add_last_actions(&mut self)->&Self{
+
+
+
+ 100 +
+
+ +
+
+
    //     let arg = (self.recipe.progress as f32 - self.progression as f32) / self.get_base_progression() as f32;
+
+
+
+ 101 +
+
+ +
+
+
    //     self.durability+=10;
+
+
+
+ 102 +
+
+ +
+
+
    //     if 0.0 < arg && arg < 1.2 { self.run_action(&ACTIONS.basic_synthesis);}
+
+
+
+ 103 +
+
+ +
+
+
    //     if 1.2 <= arg && arg < 1.8 { self.cp+=7; self.run_action(&ACTIONS.careful_synthesis); }
+
+
+
+ 104 +
+
+ +
+
+
    //     if 1.8 <= arg && arg < 2.0 {
+
+
+
+ 105 +
+
+ +
+
+
    //         self.cp+=12;
+
+
+
+ 106 +
+
+ +
+
+
    //         self.run_action(&ACTIONS.observe);
+
+
+
+ 107 +
+
+ +
+
+
    //         self.run_action(&ACTIONS.focused_synthesis);
+
+
+
+ 108 +
+
+ +
+
+
    //     }
+
+
+
+ 109 +
+
+ +
+
+
    //     self
+
+
+
+ 110 +
+
+ +
+
+
    // }
+
+
+
+ 111 +
+
+ +
+
+
}
+
+
+
+ 112 +
+
+ +
+
+

+            
+
+
+ 113 +
+
+ +
+
+
impl<'a> Debug for Craft<'a> {
+
+
+
+ 114 +
+
+ +
+
+
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
+
+
+
+ 115 +
+
+ +
+
+
        let mut binding = f.debug_struct("");
+
+
+
+ 116 +
+
+ +
+
+
        binding
+
+
+
+ 117 +
+
+ +
+
+
            .field("step_count", &self.step_count)
+
+
+
+ 118 +
+
+ +
+
+
            .field("progression", &format!("{:?}/{:?}", &self.progression, &self.recipe.progress))
+
+
+
+ 119 +
+
+ +
+
+
            .field("quality", &format!("{:?}/{:?}", &self.quality, &self.recipe.quality))
+
+
+
+ 120 +
+
+ +
+
+
            .field("durability", &format!("{:?}/{:?}", &self.durability, &self.recipe.durability))
+
+
+
+ 121 +
+
+ +
+
+
            // .field("cp", &format!("{:?}/{:?}", &self.cp, &self.stats.max_cp))
+
+
+
+ 122 +
+
+ +
+
+
        ;
+
+
+
+ 123 +
+
+ +
+
+
        binding.field("actions", &self.actions);
+
+
+
+ 124 +
+
+ +
+
+
        binding.finish()
+
+
+
+ 125 +
+
+ +
+
+
    }
+
+
+
+ 126 +
+
+ +
+
+
}
+
+
+
+ 127 +
+
+ +
+
+

+            
+
+
+ 128 +
+
+ +
+
+
impl<'a> Display for Craft<'a> {
+
+
+
+ 129 +
+
+ +
+
+
    fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
+
+
+
+ 130 +
+
+ +
+
+
        f.debug_struct("Craft")
+
+
+
+ 131 +
+
+ +
+
+
            .field("step_count", &self.step_count)
+
+
+
+ 132 +
+
+ +
+
+
            .field(
+
+
+
+ 133 +
+
+ +
+
+
                "progression",
+
+
+
+ 134 +
+
+ +
+
+
                &format!("{:?}/{:?}", &self.progression, &self.recipe.progress),
+
+
+
+ 135 +
+
+ +
+
+
            )
+
+
+
+ 136 +
+
+ +
+
+
            .field(
+
+
+
+ 137 +
+
+ +
+
+
                "quality",
+
+
+
+ 138 +
+
+ +
+
+
                &format!("{:?}/{:?}", &self.quality, &self.recipe.quality),
+
+
+
+ 139 +
+
+ +
+
+
            )
+
+
+
+ 140 +
+
+ +
+
+
            .field(
+
+
+
+ 141 +
+
+ +
+
+
                "durability",
+
+
+
+ 142 +
+
+ +
+
+
                &format!("{:?}/{:?}", &self.durability, &self.recipe.durability),
+
+
+
+ 143 +
+
+ +
+
+
            )
+
+
+
+ 144 +
+
+ +
+
+
            .field("cp", &format!("{:?}/{:?}", &self.cp, &self.stats.max_cp))
+
+
+
+ 145 +
+
+ +
+
+
            .finish()
+
+
+
+ 146 +
+
+ +
+
+
    }
+
+
+
+ 147 +
+
+ +
+
+
}
+
+
+
+ + + diff --git a/coverage/html/src/index.html b/coverage/html/src/index.html new file mode 100644 index 0000000..e016d84 --- /dev/null +++ b/coverage/html/src/index.html @@ -0,0 +1,201 @@ + + + + + Grcov report - src + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FileLine CoverageFunctionsBranches
action.rs + + 0% + + + 0% + + 0 / 239 + 0%0 / 36 100%0 / 0
craft.rs + + 0% + + + 0% + + 0 / 102 + 0%0 / 14 100%0 / 0
io.rs + + 53.77% + + + 53.77% + + 114 / 212 + 13.4%28 / 209 100%0 / 0
lib.rs + + 0.43% + + + 0.43% + + 1 / 230 + 4.76%1 / 21 100%0 / 0
solver.rs + + 0% + + + 0% + + 0 / 203 + 0%0 / 12 100%0 / 0
specs.rs + + 0% + + + 0% + + 0 / 75 + 0%0 / 48 100%0 / 0
+ + + diff --git a/coverage/html/src/io.rs.html b/coverage/html/src/io.rs.html new file mode 100644 index 0000000..efb11ac --- /dev/null +++ b/coverage/html/src/io.rs.html @@ -0,0 +1,5328 @@ + + + + + Grcov report - io.rs + + +
+ + + +
+
+ 1 +
+
+ +
+
+
#[warn(missing_docs)]
+
+
+
+ 2 +
+
+ +
+
+

+            
+
+
+ 3 +
+
+ +
+
+
use crate::Craft;
+
+
+
+ 4 +
+
+ +
+
+
use clap::Parser;
+
+
+
+ 5 +
+
+ +
+
+
use core::fmt::Display;
+
+
+
+ 6 +
+
+ +
+
+

+            
+
+
+ 7 +
+
+ +
+
+
// #[cfg(not(feature = "no_python"))]
+
+
+
+ 8 +
+
+ +
+
+
use pyo3::prelude::*;
+
+
+
+ 9 +
+
+ +
+
+

+            
+
+
+ 10 +
+
+ 1 +
+
+
#[derive(Debug, Clone, Copy)]
+
+
+
+ 11 +
+
+ +
+
+
pub struct Parameters {
+
+
+
+ 12 +
+
+ +
+
+
    pub threads: usize,
+
+
+
+ 13 +
+
+ +
+
+
    pub verbose: u8,
+
+
+
+ 14 +
+
+ +
+
+
    pub depth: u32,
+
+
+
+ 15 +
+
+ +
+
+
    pub desperate: bool,
+
+
+
+ 16 +
+
+ +
+
+
    pub byregot_step: u8,
+
+
+
+ 17 +
+
+ +
+
+
}
+
+
+
+ 18 +
+
+ +
+
+

+            
+
+
+ 19 +
+
+ 8 +
+
+
#[derive(Parser, Debug, Clone)]
+
+
+
+ 20 +
+
+ +
+
+
#[command(author, version, about, long_about = None)]
+
+
+
+ 21 +
+
+ +
+
+
pub struct Args {
+
+
+
+ 22 +
+
+ +
+
+
    /// Name of the receipe
+
+
+
+ 23 +
+
+ 1 +
+
+
    #[arg(short, long, default_value_t = String::from("default_recipe"))]
+
+
+
+ 24 +
+
+ +
+
+
    pub recipe_name: String,
+
+
+
+ 25 +
+
+ +
+
+

+            
+
+
+ 26 +
+
+ +
+
+
    /// Name of the character
+
+
+
+ 27 +
+
+ 1 +
+
+
    #[arg(short, long, default_value_t = String::from("default_character"))]
+
+
+
+ 28 +
+
+ +
+
+
    pub character_name: String,
+
+
+
+ 29 +
+
+ +
+
+

+            
+
+
+ 30 +
+
+ +
+
+
    /// The ml file name
+
+
+
+ 31 +
+
+ 1 +
+
+
    #[arg(short, long, default_value_t = String::from("craft.toml"))]
+
+
+
+ 32 +
+
+ +
+
+
    pub file_name: String,
+
+
+
+ 33 +
+
+ +
+
+

+            
+
+
+ 34 +
+
+ +
+
+
    /// The verbose flag
+
+
+
+ 35 +
+
+ +
+
+
    #[arg(short, long, action = clap::ArgAction::Count)]
+
+
+
+ 36 +
+
+ +
+
+
    pub verbose: u8,
+
+
+
+ 37 +
+
+ +
+
+

+            
+
+
+ 38 +
+
+ +
+
+
    /// The depth of the first pass
+
+
+
+ 39 +
+
+ 1 +
+
+
    #[arg(short, long, default_value_t = 8)]
+
+
+
+ 40 +
+
+ +
+
+
    pub depth: u32,
+
+
+
+ 41 +
+
+ +
+
+

+            
+
+
+ 42 +
+
+ +
+
+
    /// Thread counts, default is 4
+
+
+
+ 43 +
+
+ 1 +
+
+
    #[arg(short, long, default_value_t = 4)]
+
+
+
+ 44 +
+
+ +
+
+
    pub threads: usize,
+
+
+
+ 45 +
+
+ +
+
+

+            
+
+
+ 46 +
+
+ +
+
+
    /// Desperate mode, will try to finish the craft above all
+
+
+
+ 47 +
+
+ 1 +
+
+
    #[arg(short = 'D', long, default_value_t = false)]
+
+
+
+ 48 +
+
+ +
+
+
    pub desperate: bool,
+
+
+
+ 49 +
+
+ +
+
+

+            
+
+
+ 50 +
+
+ +
+
+
    /// Long mode, will try to find more solutions, at the expense of time
+
+
+
+ 51 +
+
+ 1 +
+
+
    #[arg(short = 'l', long, default_value_t = false)]
+
+
+
+ 52 +
+
+ +
+
+
    pub long: bool,
+
+
+
+ 53 +
+
+ +
+
+
}
+
+
+
+ 54 +
+
+ +
+
+

+            
+
+
+ 55 +
+
+ +
+
+
/// A final stripped down version of a craft
+
+
+
+ 56 +
+
+ +
+
+
/// used for final print and talking with python
+
+
+
+ 57 +
+
+ 1 +
+
+
#[derive(Debug)]
+
+
+
+ 58 +
+
+ +
+
+
#[pyclass]
+
+
+
+ 59 +
+
+ +
+
+
pub struct SolverResult {
+
+
+
+ 60 +
+
+ +
+
+
    #[pyo3(get)]
+
+
+
+ 61 +
+
+ +
+
+
    pub steps: u32,
+
+
+
+ 62 +
+
+ +
+
+
    #[pyo3(get)]
+
+
+
+ 63 +
+
+ +
+
+
    pub quality: u32,
+
+
+
+ 64 +
+
+ +
+
+
    #[pyo3(get)]
+
+
+
+ 65 +
+
+ +
+
+
    pub progression: u32,
+
+
+
+ 66 +
+
+ +
+
+
    #[pyo3(get)]
+
+
+
+ 67 +
+
+ +
+
+
    pub durability: i32,
+
+
+
+ 68 +
+
+ +
+
+
    #[pyo3(get)]
+
+
+
+ 69 +
+
+ +
+
+
    pub cp: i32,
+
+
+
+ 70 +
+
+ +
+
+
    #[pyo3(get)]
+
+
+
+ 71 +
+
+ +
+
+
    pub total_cp: u32,
+
+
+
+ 72 +
+
+ +
+
+
    #[pyo3(get)]
+
+
+
+ 73 +
+
+ +
+
+
    pub total_progression: u32,
+
+
+
+ 74 +
+
+ +
+
+
    #[pyo3(get)]
+
+
+
+ 75 +
+
+ +
+
+
    pub total_quality: u32,
+
+
+
+ 76 +
+
+ +
+
+
    #[pyo3(get)]
+
+
+
+ 77 +
+
+ +
+
+
    pub total_durability: u32,
+
+
+
+ 78 +
+
+ +
+
+
    #[pyo3(get)]
+
+
+
+ 79 +
+
+ +
+
+
    pub actions: Vec<String>,
+
+
+
+ 80 +
+
+ +
+
+
    #[pyo3(get)]
+
+
+
+ 81 +
+
+ +
+
+
    pub step1_solutions: usize,
+
+
+
+ 82 +
+
+ +
+
+
    #[pyo3(get)]
+
+
+
+ 83 +
+
+ +
+
+
    pub step2_solutions: usize,
+
+
+
+ 84 +
+
+ +
+
+
    #[pyo3(get)]
+
+
+
+ 85 +
+
+ +
+
+
    pub found_100_percent: bool,
+
+
+
+ 86 +
+
+ +
+
+
}
+
+
+
+ 87 +
+
+ +
+
+

+            
+
+
+ 88 +
+
+ +
+
+
/// Pretty display for SolverResult
+
+
+
+ 89 +
+
+ +
+
+
impl Display for SolverResult {
+
+
+
+ 90 +
+
+ 2 +
+
+
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
+
+
+
+ 91 +
+
+ 2 +
+
+
        write!(f, "{:?}", self.actions)
+
+
+
+ 92 +
+
+ 2 +
+
+
    }
+
+
+
+ 93 +
+
+ +
+
+
}
+
+
+
+ 94 +
+
+ +
+
+

+            
+
+
+ 95 +
+
+ +
+
+
//#[pymethods]
+
+
+
+ 96 +
+
+ +
+
+
impl SolverResult {
+
+
+
+ 97 +
+
+ +
+
+
    pub fn from_craft(
+
+
+
+ 98 +
+
+ +
+
+
        craft: &Craft,
+
+
+
+ 99 +
+
+ +
+
+
        step1_solutions: usize,
+
+
+
+ 100 +
+
+ +
+
+
        step2_solutions: usize,
+
+
+
+ 101 +
+
+ +
+
+
        found_100_percent: bool,
+
+
+
+ 102 +
+
+ +
+
+
    ) -> SolverResult {
+
+
+
+ 103 +
+
+ +
+
+
        let mut actions = craft
+
+
+
+ 104 +
+
+ +
+
+
            .actions
+
+
+
+ 105 +
+
+ +
+
+
            .iter()
+
+
+
+ 106 +
+
+ +
+
+
            .map(|action| format!("{}", action.short_name))
+
+
+
+ 107 +
+
+ +
+
+
            .collect::<Vec<String>>();
+
+
+
+ 108 +
+
+ +
+
+
        let arg = (craft.recipe.progress as f32 - craft.progression as f32)
+
+
+
+ 109 +
+
+ +
+
+
            / craft.get_base_progression() as f32;
+
+
+
+ 110 +
+
+ +
+
+
        if 0.0 < arg && arg < 1.2 {
+
+
+
+ 111 +
+
+ +
+
+
            actions.push("basicSynth2".to_string());
+
+
+
+ 112 +
+
+ +
+
+
        }
+
+
+
+ 113 +
+
+ +
+
+
        if 1.2 <= arg && arg < 1.8 {
+
+
+
+ 114 +
+
+ +
+
+
            actions.push("carefulSynthesis".to_string());
+
+
+
+ 115 +
+
+ +
+
+
        }
+
+
+
+ 116 +
+
+ +
+
+
        if 1.8 <= arg && arg < 2.0 {
+
+
+
+ 117 +
+
+ +
+
+
            actions.push("observe".to_string());
+
+
+
+ 118 +
+
+ +
+
+
            actions.push("focusedSynthesis".to_string());
+
+
+
+ 119 +
+
+ +
+
+
        }
+
+
+
+ 120 +
+
+ +
+
+
        SolverResult {
+
+
+
+ 121 +
+
+ +
+
+
            steps: craft.step_count,
+
+
+
+ 122 +
+
+ +
+
+
            progression: craft.progression,
+
+
+
+ 123 +
+
+ +
+
+
            quality: craft.quality,
+
+
+
+ 124 +
+
+ +
+
+
            durability: craft.durability,
+
+
+
+ 125 +
+
+ +
+
+
            actions: actions,
+
+
+
+ 126 +
+
+ +
+
+
            step1_solutions,
+
+
+
+ 127 +
+
+ +
+
+
            step2_solutions,
+
+
+
+ 128 +
+
+ +
+
+
            found_100_percent,
+
+
+
+ 129 +
+
+ +
+
+
            total_progression: craft.recipe.progress,
+
+
+
+ 130 +
+
+ +
+
+
            total_quality: craft.recipe.quality,
+
+
+
+ 131 +
+
+ +
+
+
            total_durability: craft.recipe.durability,
+
+
+
+ 132 +
+
+ +
+
+
            cp: craft.cp,
+
+
+
+ 133 +
+
+ +
+
+
            total_cp: craft.stats.max_cp,
+
+
+
+ 134 +
+
+ +
+
+
        }
+
+
+
+ 135 +
+
+ +
+
+
    }
+
+
+
+ 136 +
+
+ +
+
+
}
+
+
+
+ 137 +
+
+ +
+
+

+            
+
+
+ 138 +
+
+ +
+
+
#[pymethods]
+
+
+
+ 139 +
+
+ +
+
+
impl SolverResult {
+
+
+
+ 140 +
+
+ +
+
+
    #[staticmethod]
+
+
+
+ 141 +
+
+ 2 +
+
+
    pub fn default() -> Self {
+
+
+
+ 142 +
+
+ 2 +
+
+
        Self {
+
+
+
+ 143 +
+
+ 2 +
+
+
            steps: 0,
+
+
+
+ 144 +
+
+ 2 +
+
+
            progression: 0,
+
+
+
+ 145 +
+
+ 2 +
+
+
            quality: 0,
+
+
+
+ 146 +
+
+ 2 +
+
+
            durability: 0,
+
+
+
+ 147 +
+
+ 2 +
+
+
            total_progression: 0,
+
+
+
+ 148 +
+
+ 2 +
+
+
            total_quality: 0,
+
+
+
+ 149 +
+
+ 2 +
+
+
            total_durability: 0,
+
+
+
+ 150 +
+
+ 2 +
+
+
            actions: vec!["Act1".to_string(), "Act2".to_string()],
+
+
+
+ 151 +
+
+ 2 +
+
+
            step1_solutions: 0,
+
+
+
+ 152 +
+
+ 2 +
+
+
            step2_solutions: 0,
+
+
+
+ 153 +
+
+ 2 +
+
+
            found_100_percent: false,
+
+
+
+ 154 +
+
+ 2 +
+
+
            cp: 0,
+
+
+
+ 155 +
+
+ 2 +
+
+
            total_cp: 0,
+
+
+
+ 156 +
+
+ 2 +
+
+
        }
+
+
+
+ 157 +
+
+ 2 +
+
+
    }
+
+
+
+ 158 +
+
+ +
+
+

+            
+
+
+ 159 +
+
+ 1 +
+
+
    pub fn pretty_print(&self) {
+
+
+
+ 160 +
+
+ 1 +
+
+
        println!(
+
+
+
+ 161 +
+
+ 1 +
+
+
            "Quality: [{}/{}] | Durability: [{}/{}] | Cp : [{}/{}] | Steps : {}",
+
+
+
+ 162 +
+
+ 1 +
+
+
            self.quality,
+
+
+
+ 163 +
+
+ 1 +
+
+
            self.total_quality,
+
+
+
+ 164 +
+
+ 1 +
+
+
            self.durability,
+
+
+
+ 165 +
+
+ 1 +
+
+
            self.total_durability,
+
+
+
+ 166 +
+
+ 1 +
+
+
            self.cp,
+
+
+
+ 167 +
+
+ 1 +
+
+
            self.total_cp,
+
+
+
+ 168 +
+
+ 1 +
+
+
            self.steps
+
+
+
+ 169 +
+
+ 1 +
+
+
        );
+
+
+
+ 170 +
+
+ 1 +
+
+
        println!("{:?}", self.actions);
+
+
+
+ 171 +
+
+ 1 +
+
+
    }
+
+
+
+ 172 +
+
+ +
+
+
}
+
+
+
+ 173 +
+
+ +
+
+

+            
+
+
+ 174 +
+
+ +
+
+
impl Parameters {
+
+
+
+ 175 +
+
+ +
+
+
    pub fn from_args(args: &Args) -> Self {
+
+
+
+ 176 +
+
+ +
+
+
        Self {
+
+
+
+ 177 +
+
+ +
+
+
            depth: if args.desperate { 11 } else { 8 },
+
+
+
+ 178 +
+
+ +
+
+
            threads: args.threads,
+
+
+
+ 179 +
+
+ +
+
+
            verbose: args.verbose,
+
+
+
+ 180 +
+
+ +
+
+
            desperate: args.desperate,
+
+
+
+ 181 +
+
+ +
+
+
            byregot_step: if args.long { 6 } else { 8 },
+
+
+
+ 182 +
+
+ +
+
+
        }
+
+
+
+ 183 +
+
+ +
+
+
    }
+
+
+
+ 184 +
+
+ +
+
+
}
+
+
+
+ 185 +
+
+ +
+
+

+            
+
+
+ 186 +
+
+ +
+
+
////// Python Bindings //////
+
+
+
+ 187 +
+
+ +
+
+

+            
+
+
+ 188 +
+
+ +
+
+
/// A Python module implemented in Rust.
+
+
+
+ 189 +
+
+ +
+
+
#[cfg(not(feature = "no_python"))]
+
+
+
+ 190 +
+
+ +
+
+
#[pymodule]
+
+
+
+ 191 +
+
+ +
+
+
fn xiv_csolver_lib(_py: Python, m: &PyModule) -> PyResult<()> {
+
+
+
+ 192 +
+
+ +
+
+
    m.add_function(wrap_pyfunction!(test_result, m)?)?;
+
+
+
+ 193 +
+
+ +
+
+
    m.add_function(wrap_pyfunction!(solve_from_python, m)?)?;
+
+
+
+ 194 +
+
+ +
+
+
    Ok(())
+
+
+
+ 195 +
+
+ +
+
+
}
+
+
+
+ 196 +
+
+ +
+
+

+            
+
+
+ 197 +
+
+ +
+
+
///
+
+
+
+ 198 +
+
+ +
+
+
#[cfg(not(feature = "no_python"))]
+
+
+
+ 199 +
+
+ +
+
+
#[pyfunction]
+
+
+
+ 200 +
+
+ +
+
+
pub fn test_result() -> SolverResult {
+
+
+
+ 201 +
+
+ +
+
+
    SolverResult::default()
+
+
+
+ 202 +
+
+ +
+
+
}
+
+
+
+ 203 +
+
+ +
+
+

+            
+
+
+ 204 +
+
+ +
+
+
/// Create a stat struct stats with the base values
+
+
+
+ 205 +
+
+ +
+
+
#[cfg(not(feature = "no_python"))]
+
+
+
+ 206 +
+
+ +
+
+
use crate::{solve_craft, Recipe, Stats};
+
+
+
+ 207 +
+
+ +
+
+

+            
+
+
+ 208 +
+
+ +
+
+
#[cfg(not(feature = "no_python"))]
+
+
+
+ 209 +
+
+ +
+
+
#[pyfunction]
+
+
+
+ 210 +
+
+ +
+
+
pub fn solve_from_python(values: &PyAny) -> PyResult<Option<Vec<SolverResult>>> {
+
+
+
+ 211 +
+
+ +
+
+
    // // Create Recipe
+
+
+
+ 212 +
+
+ +
+
+
    let recipe = Recipe {
+
+
+
+ 213 +
+
+ +
+
+
        durability: values.getattr("durability")?.extract()?,
+
+
+
+ 214 +
+
+ +
+
+
        progress: values.getattr("progress")?.extract()?,
+
+
+
+ 215 +
+
+ +
+
+
        progress_divider: values.getattr("progress_divider")?.extract()?,
+
+
+
+ 216 +
+
+ +
+
+
        progress_modifier: values.getattr("progress_modifier")?.extract()?,
+
+
+
+ 217 +
+
+ +
+
+
        quality: values.getattr("quality")?.extract()?,
+
+
+
+ 218 +
+
+ +
+
+
        quality_divider: values.getattr("quality_divider")?.extract()?,
+
+
+
+ 219 +
+
+ +
+
+
        quality_modifier: values.getattr("quality_modifier")?.extract()?,
+
+
+
+ 220 +
+
+ +
+
+
    };
+
+
+
+ 221 +
+
+ +
+
+

+            
+
+
+ 222 +
+
+ +
+
+
    // Create Stats
+
+
+
+ 223 +
+
+ +
+
+
    let stats = Stats {
+
+
+
+ 224 +
+
+ +
+
+
        craftsmanship: values.getattr("craftsmanship")?.extract()?,
+
+
+
+ 225 +
+
+ +
+
+
        control: values.getattr("control")?.extract()?,
+
+
+
+ 226 +
+
+ +
+
+
        max_cp: values.getattr("max_cp")?.extract()?,
+
+
+
+ 227 +
+
+ +
+
+
    };
+
+
+
+ 228 +
+
+ +
+
+

+            
+
+
+ 229 +
+
+ +
+
+
    // Create parameters
+
+
+
+ 230 +
+
+ +
+
+
    let param = Parameters {
+
+
+
+ 231 +
+
+ +
+
+
        depth: values.getattr("depth")?.extract()?,
+
+
+
+ 232 +
+
+ +
+
+
        byregot_step: values.getattr("byregot_step")?.extract()?,
+
+
+
+ 233 +
+
+ +
+
+
        desperate: values.getattr("desperate")?.extract()?,
+
+
+
+ 234 +
+
+ +
+
+
        threads: values.getattr("threads")?.extract()?,
+
+
+
+ 235 +
+
+ +
+
+
        verbose: values.getattr("verbose")?.extract()?,
+
+
+
+ 236 +
+
+ +
+
+
    };
+
+
+
+ 237 +
+
+ +
+
+

+            
+
+
+ 238 +
+
+ +
+
+
    // println!("{:?} len: {:?} ",values,values.getattr("len()"));
+
+
+
+ 239 +
+
+ +
+
+
    let res = solve_craft(recipe, stats, param);
+
+
+
+ 240 +
+
+ +
+
+
    Ok(res)
+
+
+
+ 241 +
+
+ +
+
+
}
+
+
+
+ 242 +
+
+ +
+
+

+            
+
+
+ 243 +
+
+ +
+
+
#[cfg(test)]
+
+
+
+ 244 +
+
+ +
+
+
mod tests {
+
+
+
+ 245 +
+
+ +
+
+
    use crate::io::Args;
+
+
+
+ 246 +
+
+ +
+
+
    use crate::{Parameters, SolverResult};
+
+
+
+ 247 +
+
+ +
+
+
    use pretty_assertions::{assert_eq, assert_ne};
+
+
+
+ 248 +
+
+ +
+
+
    use clap::Parser;
+
+
+
+ 249 +
+
+ +
+
+

+            
+
+
+ 250 +
+
+ +
+
+
    impl PartialEq for Parameters {
+
+
+
+ 251 +
+
+ 1 +
+
+
        fn eq(&self, rhs: &Parameters) -> bool {
+
+
+
+ 252 +
+
+ 1 +
+
+
            (self.byregot_step == rhs.byregot_step)
+
+
+
+ 253 +
+
+ 1 +
+
+
                & (self.depth == rhs.depth)
+
+
+
+ 254 +
+
+ 1 +
+
+
                & (self.desperate == rhs.desperate)
+
+
+
+ 255 +
+
+ 1 +
+
+
                & (self.threads == rhs.threads)
+
+
+
+ 256 +
+
+ 1 +
+
+
        }
+
+
+
+ 257 +
+
+ +
+
+
    }
+
+
+
+ 258 +
+
+ +
+
+

+            
+
+
+ 259 +
+
+ 1 +
+
+
    #[test]
+
+
+
+ 260 +
+
+ 1 +
+
+
    pub fn test_parameters_derived_attributes() {
+
+
+
+ 261 +
+
+ 1 +
+
+
        let def = Parameters {
+
+
+
+ 262 +
+
+ 1 +
+
+
            byregot_step: 0,
+
+
+
+ 263 +
+
+ 1 +
+
+
            depth: 0,
+
+
+
+ 264 +
+
+ 1 +
+
+
            desperate: false,
+
+
+
+ 265 +
+
+ 1 +
+
+
            threads: 42,
+
+
+
+ 266 +
+
+ 1 +
+
+
            verbose: 1,
+
+
+
+ 267 +
+
+ 1 +
+
+
        };
+
+
+
+ 268 +
+
+ 1 +
+
+
        let def2 = def;
+
+
+
+ 269 +
+
+ 1 +
+
+
        let def3 = def2.clone();
+
+
+
+ 270 +
+
+ 1 +
+
+

+            
+
+
+ 271 +
+
+ 1 +
+
+
        assert_eq!(def2, def3);
+
+
+
+ 272 +
+
+ 1 +
+
+
    }
+
+
+
+ 273 +
+
+ +
+
+

+            
+
+
+ 274 +
+
+ 1 +
+
+
    #[test]
+
+
+
+ 275 +
+
+ 1 +
+
+
    pub fn test_display() {
+
+
+
+ 276 +
+
+ 1 +
+
+
        let def = SolverResult::default();
+
+
+
+ 277 +
+
+ 1 +
+
+
        assert_ne!(def.to_string(), "");
+
+
+
+ 278 +
+
+ 1 +
+
+
        assert_eq!(def.to_string(), "[\"Act1\", \"Act2\"]");
+
+
+
+ 279 +
+
+ 1 +
+
+
        def.pretty_print();
+
+
+
+ 280 +
+
+ 1 +
+
+
    }
+
+
+
+ 281 +
+
+ +
+
+

+            
+
+
+ 282 +
+
+ 1 +
+
+
    #[test]
+
+
+
+ 283 +
+
+ 1 +
+
+
    pub fn test_debug() {
+
+
+
+ 284 +
+
+ 1 +
+
+
        let def = SolverResult::default();
+
+
+
+ 285 +
+
+ 1 +
+
+
        assert_eq!(format!("{:?}", def),"SolverResult { steps: 0, quality: 0, progression: 0, durability: 0, cp: 0, total_cp: 0, total_progression: 0, total_quality: 0, total_durability: 0, actions: [\"Act1\", \"Act2\"], step1_solutions: 0, step2_solutions: 0, found_100_percent: false }");
+
+
+
+ 286 +
+
+ 1 +
+
+
    }
+
+
+
+ 287 +
+
+ +
+
+

+            
+
+
+ 288 +
+
+ 1 +
+
+
    #[test]
+
+
+
+ 289 +
+
+ 1 +
+
+
    pub fn test_arguments() {
+
+
+
+ 290 +
+
+ 1 +
+
+
        // Create false argument parameter
+
+
+
+ 291 +
+
+ 1 +
+
+
        let a = Args {
+
+
+
+ 292 +
+
+ 1 +
+
+
            character_name: "Bob GZ".to_string(),
+
+
+
+ 293 +
+
+ 1 +
+
+
            depth: 77,
+
+
+
+ 294 +
+
+ 1 +
+
+
            desperate: false,
+
+
+
+ 295 +
+
+ 1 +
+
+
            file_name: "test.toml".to_string(),
+
+
+
+ 296 +
+
+ 1 +
+
+
            long: false,
+
+
+
+ 297 +
+
+ 1 +
+
+
            recipe_name: "Belladone".to_string(),
+
+
+
+ 298 +
+
+ 1 +
+
+
            threads: 11,
+
+
+
+ 299 +
+
+ 1 +
+
+
            verbose: 1,
+
+
+
+ 300 +
+
+ 1 +
+
+
        };
+
+
+
+ 301 +
+
+ 1 +
+
+
        let a2 = a.clone();
+
+
+
+ 302 +
+
+ 1 +
+
+
        println!("{:?}",a2);
+
+
+
+ 303 +
+
+ 1 +
+
+
        // Test Custom recipe
+
+
+
+ 304 +
+
+ 1 +
+
+
        let a3 = Args::parse_from(["ultraman","-r", "recipe","-c","dan","-f","bigfile.toml","-d","45","-t","4","-D","-l","-vvv"]);
+
+
+
+ 305 +
+
+ 1 +
+
+
        let _ = Args::parse_from(["-V"]);
+
+
+
+ 306 +
+
+ 1 +
+
+
        let _ = Args::parse_from(["-H"]);
+
+
+
+ 307 +
+
+ 1 +
+
+
        assert_eq!(a3.recipe_name,"recipe");
+
+
+
+ 308 +
+
+ 1 +
+
+
        assert_eq!(a3.character_name,"dan");
+
+
+
+ 309 +
+
+ 1 +
+
+
        assert_eq!(a3.file_name,"bigfile.toml");
+
+
+
+ 310 +
+
+ 1 +
+
+
        assert_eq!(a3.verbose,3);
+
+
+
+ 311 +
+
+ 1 +
+
+
        assert_eq!(a3.depth,45);
+
+
+
+ 312 +
+
+ 1 +
+
+
        assert_eq!(a3.threads,4);
+
+
+
+ 313 +
+
+ 1 +
+
+
        assert_eq!(a3.desperate,true);
+
+
+
+ 314 +
+
+ 1 +
+
+
        assert_eq!(a3.long,true);
+
+
+
+ 315 +
+
+ +
+
+

+            
+
+
+ 316 +
+
+ +
+
+
        // Test default parameters
+
+
+
+ 317 +
+
+ 1 +
+
+
        let a4 = Args::parse_from(["bobGZ"]); 
+
+
+
+ 318 +
+
+ 1 +
+
+
        assert_eq!(a4.recipe_name,"default_recipe");
+
+
+
+ 319 +
+
+ 1 +
+
+
        assert_eq!(a4.character_name,"default_character");
+
+
+
+ 320 +
+
+ 1 +
+
+
        assert_eq!(a4.file_name,"craft.toml");
+
+
+
+ 321 +
+
+ 1 +
+
+
        assert_eq!(a4.verbose,0);
+
+
+
+ 322 +
+
+ 1 +
+
+
        assert_eq!(a4.depth,8);
+
+
+
+ 323 +
+
+ 1 +
+
+
        assert_eq!(a4.threads,4);
+
+
+
+ 324 +
+
+ 1 +
+
+
        assert_eq!(a4.desperate,false);
+
+
+
+ 325 +
+
+ 1 +
+
+
        assert_eq!(a4.long,false);
+
+
+
+ 326 +
+
+ 1 +
+
+
    }
+
+
+
+ 327 +
+
+ +
+
+

+            
+
+
+ 328 +
+
+ 1 +
+
+
    #[test]
+
+
+
+ 329 +
+
+ 1 +
+
+
    pub fn test_parameters() {}
+
+
+
+ 330 +
+
+ +
+
+
}
+
+
+
+ + + diff --git a/coverage/html/src/lib.rs.html b/coverage/html/src/lib.rs.html new file mode 100644 index 0000000..7d6d9fb --- /dev/null +++ b/coverage/html/src/lib.rs.html @@ -0,0 +1,4496 @@ + + + + + Grcov report - lib.rs + + +
+ + + +
+
+ 1 +
+
+ 1 +
+
+
use crate::io::SolverResult;
+
+
+
+ 2 +
+
+ +
+
+
use crate::{
+
+
+
+ 3 +
+
+ +
+
+
    craft::Craft,
+
+
+
+ 4 +
+
+ +
+
+
    io::Parameters,
+
+
+
+ 5 +
+
+ +
+
+
    specs::{Recipe, Stats},
+
+
+
+ 6 +
+
+ +
+
+
};
+
+
+
+ 7 +
+
+ +
+
+
use std::sync::{Arc, Mutex};
+
+
+
+ 8 +
+
+ +
+
+
use threadpool::ThreadPool;
+
+
+
+ 9 +
+
+ +
+
+

+            
+
+
+ 10 +
+
+ +
+
+
pub mod action;
+
+
+
+ 11 +
+
+ +
+
+
pub mod craft;
+
+
+
+ 12 +
+
+ +
+
+
pub mod io;
+
+
+
+ 13 +
+
+ +
+
+
mod solver;
+
+
+
+ 14 +
+
+ +
+
+
mod specs;
+
+
+
+ 15 +
+
+ +
+
+

+            
+
+
+ 16 +
+
+ +
+
+
/// Solve the craft with given arguments, this functions calls threads and must own it's values
+
+
+
+ 17 +
+
+ +
+
+
pub fn solve_craft<'a>(
+
+
+
+ 18 +
+
+ +
+
+
    recipe: Recipe,
+
+
+
+ 19 +
+
+ +
+
+
    stats: Stats,
+
+
+
+ 20 +
+
+ +
+
+
    params: Parameters,
+
+
+
+ 21 +
+
+ +
+
+
) -> Option<Vec<SolverResult>> {
+
+
+
+ 22 +
+
+ +
+
+
    // Load the craft with given arguments
+
+
+
+ 23 +
+
+ +
+
+
    let craft = Craft::new(recipe, stats, params);
+
+
+
+ 24 +
+
+ +
+
+

+            
+
+
+ 25 +
+
+ +
+
+
    // Start a threadpool
+
+
+
+ 26 +
+
+ +
+
+
    let pool = ThreadPool::new(params.threads);
+
+
+
+ 27 +
+
+ +
+
+

+            
+
+
+ 28 +
+
+ +
+
+
    #[cfg(feature = "verbose")]
+
+
+
+ 29 +
+
+ +
+
+
    if params.verbose > 0 {
+
+
+
+ 30 +
+
+ +
+
+
        println!("[P1] Starting phase 1...");
+
+
+
+ 31 +
+
+ +
+
+
    }
+
+
+
+ 32 +
+
+ +
+
+

+            
+
+
+ 33 +
+
+ +
+
+
    let phase1_routes = solver::generate_routes_phase1(craft);
+
+
+
+ 34 +
+
+ +
+
+
    let nb_p1 = phase1_routes.len();
+
+
+
+ 35 +
+
+ +
+
+

+            
+
+
+ 36 +
+
+ +
+
+
    #[cfg(feature = "verbose")]
+
+
+
+ 37 +
+
+ +
+
+
    if params.verbose > 0 {
+
+
+
+ 38 +
+
+ +
+
+
        println!(
+
+
+
+ 39 +
+
+ +
+
+
            "[P1] Found {} routes, testing them all...",
+
+
+
+ 40 +
+
+ +
+
+
            phase1_routes.len()
+
+
+
+ 41 +
+
+ +
+
+
        );
+
+
+
+ 42 +
+
+ +
+
+
        if params.verbose > 1 {
+
+
+
+ 43 +
+
+ +
+
+
            for r in &phase1_routes {
+
+
+
+ 44 +
+
+ +
+
+
                println!(
+
+
+
+ 45 +
+
+ +
+
+
                    "[P1] {:?} p:{}% q:{}% c:{} d:{}",
+
+
+
+ 46 +
+
+ +
+
+
                    r.actions,
+
+
+
+ 47 +
+
+ +
+
+
                    r.progression,
+
+
+
+ 48 +
+
+ +
+
+
                    r.quality * 100 / r.recipe.quality,
+
+
+
+ 49 +
+
+ +
+
+
                    r.cp,
+
+
+
+ 50 +
+
+ +
+
+
                    r.durability
+
+
+
+ 51 +
+
+ +
+
+
                );
+
+
+
+ 52 +
+
+ +
+
+
            }
+
+
+
+ 53 +
+
+ +
+
+
        }
+
+
+
+ 54 +
+
+ +
+
+
    }
+
+
+
+ 55 +
+
+ +
+
+

+            
+
+
+ 56 +
+
+ +
+
+
    // Core algorithm, fill all found routes with the best route (doesn't branch, just replace)
+
+
+
+ 57 +
+
+ +
+
+
    let arc_phase2_routes = Arc::new(Mutex::new(Vec::<Craft>::new()));
+
+
+
+ 58 +
+
+ +
+
+

+            
+
+
+ 59 +
+
+ +
+
+
    for route in phase1_routes {
+
+
+
+ 60 +
+
+ +
+
+
        let _phase2_routes = Arc::clone(&arc_phase2_routes);
+
+
+
+ 61 +
+
+ +
+
+

+            
+
+
+ 62 +
+
+ +
+
+
        pool.execute(move || {
+
+
+
+ 63 +
+
+ +
+
+
            if let Some(mut _route) = solver::generate_routes_phase2(route) {
+
+
+
+ 64 +
+
+ +
+
+
                let mut shared = _phase2_routes.lock().unwrap();
+
+
+
+ 65 +
+
+ +
+
+
                shared.append(&mut _route);
+
+
+
+ 66 +
+
+ +
+
+
            };
+
+
+
+ 67 +
+
+ +
+
+
        });
+
+
+
+ 68 +
+
+ +
+
+
    }
+
+
+
+ 69 +
+
+ +
+
+

+            
+
+
+ 70 +
+
+ +
+
+
    pool.join();
+
+
+
+ 71 +
+
+ +
+
+
    let phase2_routes = arc_phase2_routes.lock().unwrap();
+
+
+
+ 72 +
+
+ +
+
+
    let nb_p2 = phase2_routes.len();
+
+
+
+ 73 +
+
+ +
+
+

+            
+
+
+ 74 +
+
+ +
+
+
    // Drop on empty results
+
+
+
+ 75 +
+
+ +
+
+
    if phase2_routes.len() == 0 {
+
+
+
+ 76 +
+
+ +
+
+
        return None;
+
+
+
+ 77 +
+
+ +
+
+
    }
+
+
+
+ 78 +
+
+ +
+
+

+            
+
+
+ 79 +
+
+ +
+
+
    // Print the results if verbose
+
+
+
+ 80 +
+
+ +
+
+
    #[cfg(feature = "verbose")]
+
+
+
+ 81 +
+
+ +
+
+
    if params.verbose > 0 {
+
+
+
+ 82 +
+
+ +
+
+
        println!("[P2] Found {} solutions, sorting", phase2_routes.len());
+
+
+
+ 83 +
+
+ +
+
+
        if params.verbose > 1 {
+
+
+
+ 84 +
+
+ +
+
+
            for r in phase2_routes.iter() {
+
+
+
+ 85 +
+
+ +
+
+
                println!(
+
+
+
+ 86 +
+
+ +
+
+
                    "[P2] {:?} p:{}% q:{}% d:{}",
+
+
+
+ 87 +
+
+ +
+
+
                    r.actions,
+
+
+
+ 88 +
+
+ +
+
+
                    r.progression * 100 / r.recipe.progress,
+
+
+
+ 89 +
+
+ +
+
+
                    r.quality * 100 / r.recipe.quality,
+
+
+
+ 90 +
+
+ +
+
+
                    r.durability
+
+
+
+ 91 +
+
+ +
+
+
                );
+
+
+
+ 92 +
+
+ +
+
+
            }
+
+
+
+ 93 +
+
+ +
+
+
        }
+
+
+
+ 94 +
+
+ +
+
+
    }
+
+
+
+ 95 +
+
+ +
+
+

+            
+
+
+ 96 +
+
+ +
+
+
    // Prune the results for analysis
+
+
+
+ 97 +
+
+ +
+
+
    // let mut valid_routes : Vec<Craft> = vec![];
+
+
+
+ 98 +
+
+ +
+
+
    let mut valid_solutions: Vec<SolverResult> = vec![];
+
+
+
+ 99 +
+
+ +
+
+
    for route in phase2_routes.iter() {
+
+
+
+ 100 +
+
+ +
+
+
        if route.quality >= route.recipe.quality {
+
+
+
+ 101 +
+
+ +
+
+
            // valid_routes.push(route.clone());
+
+
+
+ 102 +
+
+ +
+
+
            valid_solutions.push(SolverResult::from_craft(route, nb_p1, nb_p2, true));
+
+
+
+ 103 +
+
+ +
+
+
        }
+
+
+
+ 104 +
+
+ +
+
+
    }
+
+
+
+ 105 +
+
+ +
+
+
    // If no craft can make it to 100% HQ, fallback to base results
+
+
+
+ 106 +
+
+ +
+
+
    if valid_solutions.len() == 0 {
+
+
+
+ 107 +
+
+ +
+
+
        for route in phase2_routes.iter() {
+
+
+
+ 108 +
+
+ +
+
+
            valid_solutions.push(SolverResult::from_craft(route, nb_p1, nb_p2, false));
+
+
+
+ 109 +
+
+ +
+
+
        }
+
+
+
+ 110 +
+
+ +
+
+
    }
+
+
+
+ 111 +
+
+ +
+
+

+            
+
+
+ 112 +
+
+ +
+
+
    Some(valid_solutions)
+
+
+
+ 113 +
+
+ +
+
+
}
+
+
+
+ 114 +
+
+ +
+
+

+            
+
+
+ 115 +
+
+ +
+
+
/// Load the config from args and make a craft from it
+
+
+
+ 116 +
+
+ +
+
+
pub fn load_from_config<'a>(
+
+
+
+ 117 +
+
+ +
+
+
    recipe_name: &str,
+
+
+
+ 118 +
+
+ +
+
+
    file_name: &str,
+
+
+
+ 119 +
+
+ +
+
+
    character_name: &str,
+
+
+
+ 120 +
+
+ +
+
+
) -> (Recipe, Stats) {
+
+
+
+ 121 +
+
+ +
+
+
    //read craft.toml
+
+
+
+ 122 +
+
+ +
+
+
    let config: toml::Value = toml::from_str(
+
+
+
+ 123 +
+
+ +
+
+
        &std::fs::read_to_string(file_name).expect(&format!("Can't open {}", file_name)),
+
+
+
+ 124 +
+
+ +
+
+
    )
+
+
+
+ 125 +
+
+ +
+
+
    .unwrap();
+
+
+
+ 126 +
+
+ +
+
+

+            
+
+
+ 127 +
+
+ +
+
+
    let recp = match config.get(recipe_name) {
+
+
+
+ 128 +
+
+ +
+
+
        Some(r) => r,
+
+
+
+ 129 +
+
+ +
+
+
        None => panic!("Can't find value '{}' in '{}'", recipe_name, file_name),
+
+
+
+ 130 +
+
+ +
+
+
    };
+
+
+
+ 131 +
+
+ +
+
+

+            
+
+
+ 132 +
+
+ +
+
+
    // Load receipe values
+
+
+
+ 133 +
+
+ +
+
+
    let recipe = Recipe {
+
+
+
+ 134 +
+
+ +
+
+
        durability: recp
+
+
+
+ 135 +
+
+ +
+
+
            .get("durability")
+
+
+
+ 136 +
+
+ +
+
+
            .expect(&format!(
+
+
+
+ 137 +
+
+ +
+
+
                "Can't find 'durability' in recipe '{}' on file '{}'",
+
+
+
+ 138 +
+
+ +
+
+
                recipe_name, file_name
+
+
+
+ 139 +
+
+ +
+
+
            ))
+
+
+
+ 140 +
+
+ +
+
+
            .as_integer()
+
+
+
+ 141 +
+
+ +
+
+
            .expect("Can't convert durability as an integer") as u32,
+
+
+
+ 142 +
+
+ +
+
+
        progress: recp
+
+
+
+ 143 +
+
+ +
+
+
            .get("progress")
+
+
+
+ 144 +
+
+ +
+
+
            .expect(&format!(
+
+
+
+ 145 +
+
+ +
+
+
                "Can't find 'progress' in recipe '{}' on '{}'",
+
+
+
+ 146 +
+
+ +
+
+
                recipe_name, file_name
+
+
+
+ 147 +
+
+ +
+
+
            ))
+
+
+
+ 148 +
+
+ +
+
+
            .as_integer()
+
+
+
+ 149 +
+
+ +
+
+
            .expect("Can't convert progress as an integer") as u32,
+
+
+
+ 150 +
+
+ +
+
+
        quality: recp
+
+
+
+ 151 +
+
+ +
+
+
            .get("quality")
+
+
+
+ 152 +
+
+ +
+
+
            .expect(&format!(
+
+
+
+ 153 +
+
+ +
+
+
                "Can't find 'quality' in recipe '{}' on '{}'",
+
+
+
+ 154 +
+
+ +
+
+
                recipe_name, file_name
+
+
+
+ 155 +
+
+ +
+
+
            ))
+
+
+
+ 156 +
+
+ +
+
+
            .as_integer()
+
+
+
+ 157 +
+
+ +
+
+
            .expect("Can't convert quality as an integer") as u32,
+
+
+
+ 158 +
+
+ +
+
+
        progress_divider: recp
+
+
+
+ 159 +
+
+ +
+
+
            .get("progress_divider")
+
+
+
+ 160 +
+
+ +
+
+
            .expect(&format!(
+
+
+
+ 161 +
+
+ +
+
+
                "Can't find 'progress_divider' in recipe '{}' on '{}'",
+
+
+
+ 162 +
+
+ +
+
+
                recipe_name, file_name
+
+
+
+ 163 +
+
+ +
+
+
            ))
+
+
+
+ 164 +
+
+ +
+
+
            .as_integer()
+
+
+
+ 165 +
+
+ +
+
+
            .expect("Can't convert progress_divider as an integer")
+
+
+
+ 166 +
+
+ +
+
+
            as u32,
+
+
+
+ 167 +
+
+ +
+
+
        quality_divider: recp
+
+
+
+ 168 +
+
+ +
+
+
            .get("quality_divider")
+
+
+
+ 169 +
+
+ +
+
+
            .expect(&format!(
+
+
+
+ 170 +
+
+ +
+
+
                "Can't find 'quality_divider' in recipe '{}' on '{}'",
+
+
+
+ 171 +
+
+ +
+
+
                recipe_name, file_name
+
+
+
+ 172 +
+
+ +
+
+
            ))
+
+
+
+ 173 +
+
+ +
+
+
            .as_integer()
+
+
+
+ 174 +
+
+ +
+
+
            .expect("Can't convert quality_divider as an integer") as u32,
+
+
+
+ 175 +
+
+ +
+
+
        progress_modifier: recp
+
+
+
+ 176 +
+
+ +
+
+
            .get("progress_modifier")
+
+
+
+ 177 +
+
+ +
+
+
            .expect(&format!(
+
+
+
+ 178 +
+
+ +
+
+
                "Can't find 'progress_modifier' in recipe '{}' on '{}'",
+
+
+
+ 179 +
+
+ +
+
+
                recipe_name, file_name
+
+
+
+ 180 +
+
+ +
+
+
            ))
+
+
+
+ 181 +
+
+ +
+
+
            .as_integer()
+
+
+
+ 182 +
+
+ +
+
+
            .expect("Can't convert progress_modifier as an integer")
+
+
+
+ 183 +
+
+ +
+
+
            as u32,
+
+
+
+ 184 +
+
+ +
+
+
        quality_modifier: recp
+
+
+
+ 185 +
+
+ +
+
+
            .get("quality_modifier")
+
+
+
+ 186 +
+
+ +
+
+
            .expect(&format!(
+
+
+
+ 187 +
+
+ +
+
+
                "Can't find 'quality_modifier' in recipe '{}' on '{}'",
+
+
+
+ 188 +
+
+ +
+
+
                recipe_name, file_name
+
+
+
+ 189 +
+
+ +
+
+
            ))
+
+
+
+ 190 +
+
+ +
+
+
            .as_integer()
+
+
+
+ 191 +
+
+ +
+
+
            .expect("Can't convert quality_modifier as an integer")
+
+
+
+ 192 +
+
+ +
+
+
            as u32,
+
+
+
+ 193 +
+
+ +
+
+
    };
+
+
+
+ 194 +
+
+ +
+
+

+            
+
+
+ 195 +
+
+ +
+
+
    let cfg = match config.get(character_name) {
+
+
+
+ 196 +
+
+ +
+
+
        Some(c) => c,
+
+
+
+ 197 +
+
+ +
+
+
        None => panic!("Can't find '{}' in file '{}'", character_name, file_name),
+
+
+
+ 198 +
+
+ +
+
+
    };
+
+
+
+ 199 +
+
+ +
+
+
    let stats = Stats {
+
+
+
+ 200 +
+
+ +
+
+
        craftsmanship: cfg
+
+
+
+ 201 +
+
+ +
+
+
            .get("craftsmanship")
+
+
+
+ 202 +
+
+ +
+
+
            .expect(&format!(
+
+
+
+ 203 +
+
+ +
+
+
                "Can't find 'craftsmanship' in character '{}' on file '{}'",
+
+
+
+ 204 +
+
+ +
+
+
                character_name, file_name
+
+
+
+ 205 +
+
+ +
+
+
            ))
+
+
+
+ 206 +
+
+ +
+
+
            .as_integer()
+
+
+
+ 207 +
+
+ +
+
+
            .expect("Can't convert craftsmanship as an integer") as u32,
+
+
+
+ 208 +
+
+ +
+
+
        control: cfg
+
+
+
+ 209 +
+
+ +
+
+
            .get("control")
+
+
+
+ 210 +
+
+ +
+
+
            .expect(&format!(
+
+
+
+ 211 +
+
+ +
+
+
                "Can't find 'control' in character '{}' on file '{}'",
+
+
+
+ 212 +
+
+ +
+
+
                character_name, file_name
+
+
+
+ 213 +
+
+ +
+
+
            ))
+
+
+
+ 214 +
+
+ +
+
+
            .as_integer()
+
+
+
+ 215 +
+
+ +
+
+
            .expect("Can't convert control as an integer") as u32,
+
+
+
+ 216 +
+
+ +
+
+
        max_cp: cfg
+
+
+
+ 217 +
+
+ +
+
+
            .get("max_cp")
+
+
+
+ 218 +
+
+ +
+
+
            .expect(&format!(
+
+
+
+ 219 +
+
+ +
+
+
                "Can't find 'max_cp' in character '{}' on file '{}'",
+
+
+
+ 220 +
+
+ +
+
+
                character_name, file_name
+
+
+
+ 221 +
+
+ +
+
+
            ))
+
+
+
+ 222 +
+
+ +
+
+
            .as_integer()
+
+
+
+ 223 +
+
+ +
+
+
            .expect("Can't convert max_cp as an integer") as u32,
+
+
+
+ 224 +
+
+ +
+
+
    };
+
+
+
+ 225 +
+
+ +
+
+
    (recipe, stats)
+
+
+
+ 226 +
+
+ +
+
+
}
+
+
+
+ 227 +
+
+ +
+
+

+            
+
+
+ 228 +
+
+ +
+
+
/// Print all routes in the vect, verbose
+
+
+
+ 229 +
+
+ +
+
+
pub fn print_routes<'a>(routes: &Option<Vec<SolverResult>>) {
+
+
+
+ 230 +
+
+ +
+
+
    match routes {
+
+
+
+ 231 +
+
+ +
+
+
        Some(r) => {
+
+
+
+ 232 +
+
+ +
+
+
            println!("Showing {} routes", r.len());
+
+
+
+ 233 +
+
+ +
+
+
            for c in r.iter() {
+
+
+
+ 234 +
+
+ +
+
+
                println!(
+
+
+
+ 235 +
+
+ +
+
+
                    "\n[{}¤][{}@][{}#] {:?} ",
+
+
+
+ 236 +
+
+ +
+
+
                    c.quality, c.durability, c.steps, c.actions
+
+
+
+ 237 +
+
+ +
+
+
                )
+
+
+
+ 238 +
+
+ +
+
+
            }
+
+
+
+ 239 +
+
+ +
+
+
        }
+
+
+
+ 240 +
+
+ +
+
+
        None => println!("No routes to print"),
+
+
+
+ 241 +
+
+ +
+
+
    }
+
+
+
+ 242 +
+
+ +
+
+
}
+
+
+
+ 243 +
+
+ +
+
+

+            
+
+
+ 244 +
+
+ +
+
+
/// Find the route with the least amount of steps
+
+
+
+ 245 +
+
+ +
+
+
pub fn find_fast_route(routes: &Option<Vec<SolverResult>>) -> Option<&SolverResult> {
+
+
+
+ 246 +
+
+ +
+
+
    match routes {
+
+
+
+ 247 +
+
+ +
+
+
        Some(_routes) => {
+
+
+
+ 248 +
+
+ +
+
+
            if _routes.len() > 0 {
+
+
+
+ 249 +
+
+ +
+
+
                _routes.iter().min_by_key(|key| key.steps)
+
+
+
+ 250 +
+
+ +
+
+
            } else {
+
+
+
+ 251 +
+
+ +
+
+
                None
+
+
+
+ 252 +
+
+ +
+
+
            }
+
+
+
+ 253 +
+
+ +
+
+
        }
+
+
+
+ 254 +
+
+ +
+
+
        None => None,
+
+
+
+ 255 +
+
+ +
+
+
    }
+
+
+
+ 256 +
+
+ +
+
+
}
+
+
+
+ 257 +
+
+ +
+
+

+            
+
+
+ 258 +
+
+ +
+
+
/// Find the route with the maximum amount of quality
+
+
+
+ 259 +
+
+ +
+
+
pub fn find_quality_route(routes: &Option<Vec<SolverResult>>) -> Option<&SolverResult> {
+
+
+
+ 260 +
+
+ +
+
+
    match routes {
+
+
+
+ 261 +
+
+ +
+
+
        Some(_routes) => _routes.iter().max_by_key(|key| key.quality),
+
+
+
+ 262 +
+
+ +
+
+
        None => None,
+
+
+
+ 263 +
+
+ +
+
+
    }
+
+
+
+ 264 +
+
+ +
+
+
}
+
+
+
+ 265 +
+
+ +
+
+

+            
+
+
+ 266 +
+
+ +
+
+
/// Find the route with the maximum of durability left
+
+
+
+ 267 +
+
+ +
+
+
pub fn find_safe_route(routes: &Option<Vec<SolverResult>>) -> Option<&SolverResult> {
+
+
+
+ 268 +
+
+ +
+
+
    match routes {
+
+
+
+ 269 +
+
+ +
+
+
        Some(_routes) => {
+
+
+
+ 270 +
+
+ +
+
+
            if _routes.len() > 0 {
+
+
+
+ 271 +
+
+ +
+
+
                _routes.iter().max_by_key(|key| key.durability)
+
+
+
+ 272 +
+
+ +
+
+
            } else {
+
+
+
+ 273 +
+
+ +
+
+
                None
+
+
+
+ 274 +
+
+ +
+
+
            }
+
+
+
+ 275 +
+
+ +
+
+
        }
+
+
+
+ 276 +
+
+ +
+
+
        None => None,
+
+
+
+ 277 +
+
+ +
+
+
    }
+
+
+
+ 278 +
+
+ +
+
+
}
+
+
+
+ + + diff --git a/coverage/html/src/solver.rs.html b/coverage/html/src/solver.rs.html new file mode 100644 index 0000000..8acb7c9 --- /dev/null +++ b/coverage/html/src/solver.rs.html @@ -0,0 +1,3952 @@ + + + + + Grcov report - solver.rs + + +
+ + + +
+
+ 1 +
+
+ +
+
+
use crate::action::{Action, ACTIONS};
+
+
+
+ 2 +
+
+ +
+
+
use crate::craft::Craft;
+
+
+
+ 3 +
+
+ +
+
+
use crate::specs::Success;
+
+
+
+ 4 +
+
+ +
+
+
use std::collections::VecDeque;
+
+
+
+ 5 +
+
+ +
+
+
use std::ops::Not;
+
+
+
+ 6 +
+
+ +
+
+

+            
+
+
+ 7 +
+
+ +
+
+
macro_rules! action_vec {
+
+
+
+ 8 +
+
+ +
+
+
    ($($tt:expr),*) => { vec![ $(Some(&$tt),)*]};
+
+
+
+ 9 +
+
+ +
+
+
}
+
+
+
+ 10 +
+
+ +
+
+

+            
+
+
+ 11 +
+
+ +
+
+
/// Find the next authorised action for this step of the craft
+
+
+
+ 12 +
+
+ +
+
+
pub fn next_action_picker_1<'a>(craft: &Craft<'a>) -> Vec<Option<&'a Action>> {
+
+
+
+ 13 +
+
+ +
+
+
    if craft.success != Success::Pending {
+
+
+
+ 14 +
+
+ +
+
+
        return vec![None];
+
+
+
+ 15 +
+
+ +
+
+
    }
+
+
+
+ 16 +
+
+ +
+
+
    let mut available_actions = Vec::<Option<&'a Action>>::new();
+
+
+
+ 17 +
+
+ +
+
+
    let mut forbidden_actions = Vec::<Option<&'a Action>>::new();
+
+
+
+ 18 +
+
+ +
+
+

+            
+
+
+ 19 +
+
+ +
+
+
    // Optimize the first three steps for massive time save
+
+
+
+ 20 +
+
+ +
+
+
    if craft.step_count == 0 {
+
+
+
+ 21 +
+
+ +
+
+
        return action_vec![ACTIONS.muscle_memory];
+
+
+
+ 22 +
+
+ +
+
+
    }
+
+
+
+ 23 +
+
+ +
+
+
    if craft.step_count == 1 {
+
+
+
+ 24 +
+
+ +
+
+
        return action_vec![ACTIONS.manipulation];
+
+
+
+ 25 +
+
+ +
+
+
    }
+
+
+
+ 26 +
+
+ +
+
+

+            
+
+
+ 27 +
+
+ +
+
+
    // Prune some actions if not requested by --long
+
+
+
+ 28 +
+
+ +
+
+
    if craft.step_count == 2 {
+
+
+
+ 29 +
+
+ +
+
+
        return action_vec![/*ACTIONS.waste_not, ACTIONS.waste_not_ii, */ ACTIONS.veneration];
+
+
+
+ 30 +
+
+ +
+
+
    }
+
+
+
+ 31 +
+
+ +
+
+
    if craft.step_count == 3 {
+
+
+
+ 32 +
+
+ +
+
+
        available_actions.append(&mut action_vec![
+
+
+
+ 33 +
+
+ +
+
+
            ACTIONS.waste_not_ii /*,ACTIONS.waste_not*/
+
+
+
+ 34 +
+
+ +
+
+
        ])
+
+
+
+ 35 +
+
+ +
+
+
    }
+
+
+
+ 36 +
+
+ +
+
+

+            
+
+
+ 37 +
+
+ +
+
+
    // Groundwork mostly for wn / mm
+
+
+
+ 38 +
+
+ +
+
+
    if craft.buffs.waste_not > 0 || craft.buffs.muscle_memory > 0 {
+
+
+
+ 39 +
+
+ +
+
+
        available_actions.append(&mut action_vec![ACTIONS.groundwork])
+
+
+
+ 40 +
+
+ +
+
+
    }
+
+
+
+ 41 +
+
+ +
+
+

+            
+
+
+ 42 +
+
+ +
+
+
    // Forbidding actions depending on buffs
+
+
+
+ 43 +
+
+ +
+
+
    if craft.buffs.muscle_memory > 0 {
+
+
+
+ 44 +
+
+ +
+
+
        forbidden_actions.append(&mut action_vec![
+
+
+
+ 45 +
+
+ +
+
+
            ACTIONS.basic_synthesis,
+
+
+
+ 46 +
+
+ +
+
+
            ACTIONS.careful_synthesis,
+
+
+
+ 47 +
+
+ +
+
+
            ACTIONS.prudent_synthesis,
+
+
+
+ 48 +
+
+ +
+
+
            ACTIONS.delicate_synthesis
+
+
+
+ 49 +
+
+ +
+
+
        ])
+
+
+
+ 50 +
+
+ +
+
+
    }
+
+
+
+ 51 +
+
+ +
+
+
    if craft.buffs.waste_not > 0 {
+
+
+
+ 52 +
+
+ +
+
+
        forbidden_actions.append(&mut action_vec![ACTIONS.prudent_synthesis])
+
+
+
+ 53 +
+
+ +
+
+
    }
+
+
+
+ 54 +
+
+ +
+
+
    available_actions.append(&mut action_vec![
+
+
+
+ 55 +
+
+ +
+
+
        ACTIONS.basic_synthesis,
+
+
+
+ 56 +
+
+ +
+
+
        ACTIONS.careful_synthesis,
+
+
+
+ 57 +
+
+ +
+
+
        ACTIONS.prudent_synthesis,
+
+
+
+ 58 +
+
+ +
+
+
        ACTIONS.delicate_synthesis
+
+
+
+ 59 +
+
+ +
+
+
    ]);
+
+
+
+ 60 +
+
+ +
+
+

+            
+
+
+ 61 +
+
+ +
+
+
    // ACTIONS.groundwork for the --pls
+
+
+
+ 62 +
+
+ +
+
+
    if craft.args.desperate {
+
+
+
+ 63 +
+
+ +
+
+
        available_actions.append(&mut action_vec![ACTIONS.groundwork]);
+
+
+
+ 64 +
+
+ +
+
+
    }
+
+
+
+ 65 +
+
+ +
+
+

+            
+
+
+ 66 +
+
+ +
+
+
    // For long first run
+
+
+
+ 67 +
+
+ +
+
+
    if craft.step_count > 8 {
+
+
+
+ 68 +
+
+ +
+
+
        available_actions.append(&mut action_vec![ACTIONS.waste_not_ii, ACTIONS.waste_not])
+
+
+
+ 69 +
+
+ +
+
+
    };
+
+
+
+ 70 +
+
+ +
+
+

+            
+
+
+ 71 +
+
+ +
+
+
    // Pruning the actions with the forbidden ones
+
+
+
+ 72 +
+
+ +
+
+
    let mut result_actions = Vec::<Option<&'a Action>>::new();
+
+
+
+ 73 +
+
+ +
+
+
    for action in available_actions {
+
+
+
+ 74 +
+
+ +
+
+
        if !forbidden_actions.contains(&action)
+
+
+
+ 75 +
+
+ +
+
+
            && action.unwrap().can_use(&craft)
+
+
+
+ 76 +
+
+ +
+
+
            && result_actions
+
+
+
+ 77 +
+
+ +
+
+
                .iter()
+
+
+
+ 78 +
+
+ +
+
+
                .any(|x| x.unwrap() == action.unwrap())
+
+
+
+ 79 +
+
+ +
+
+
                .not()
+
+
+
+ 80 +
+
+ +
+
+
        {
+
+
+
+ 81 +
+
+ +
+
+
            result_actions.push(action);
+
+
+
+ 82 +
+
+ +
+
+
        }
+
+
+
+ 83 +
+
+ +
+
+
    }
+
+
+
+ 84 +
+
+ +
+
+

+            
+
+
+ 85 +
+
+ +
+
+
    result_actions
+
+
+
+ 86 +
+
+ +
+
+
}
+
+
+
+ 87 +
+
+ +
+
+

+            
+
+
+ 88 +
+
+ +
+
+
/// Find all routes that can finish in one more action
+
+
+
+ 89 +
+
+ +
+
+
pub fn generate_routes_phase1<'a>(craft: Craft<'a>) -> Vec<Craft<'a>> {
+
+
+
+ 90 +
+
+ +
+
+
    let mut queue = Vec::new();
+
+
+
+ 91 +
+
+ +
+
+
    queue.push(craft);
+
+
+
+ 92 +
+
+ +
+
+
    let mut routes = Vec::new();
+
+
+
+ 93 +
+
+ +
+
+
    while !queue.is_empty() {
+
+
+
+ 94 +
+
+ +
+
+
        let craft = queue.pop().unwrap();
+
+
+
+ 95 +
+
+ +
+
+
        for action in next_action_picker_1(&craft) {
+
+
+
+ 96 +
+
+ +
+
+
            let mut craft = craft.clone();
+
+
+
+ 97 +
+
+ +
+
+

+            
+
+
+ 98 +
+
+ +
+
+
            match action {
+
+
+
+ 99 +
+
+ +
+
+
                Some(a) => craft.run_action(a),
+
+
+
+ 100 +
+
+ +
+
+
                None => break,
+
+
+
+ 101 +
+
+ +
+
+
            };
+
+
+
+ 102 +
+
+ +
+
+

+            
+
+
+ 103 +
+
+ +
+
+
            let remaining_prog = (craft.recipe.progress as f32 - craft.progression as f32)
+
+
+
+ 104 +
+
+ +
+
+
                / craft.get_base_progression() as f32;
+
+
+
+ 105 +
+
+ +
+
+
            if remaining_prog <= 2.0 {
+
+
+
+ 106 +
+
+ +
+
+
                if remaining_prog <= 0.0 {
+
+
+
+ 107 +
+
+ +
+
+
                    continue;
+
+
+
+ 108 +
+
+ +
+
+
                } else if 0.0 < remaining_prog && remaining_prog <= 1.2 {
+
+
+
+ 109 +
+
+ +
+
+
                    // pass         // Will finish with basicSynth2 (free)
+
+
+
+ 110 +
+
+ +
+
+
                } else if 1.2 < remaining_prog && remaining_prog <= 1.2 {
+
+
+
+ 111 +
+
+ +
+
+
                    craft.cp -= 7; // Will finish with carefulSynthesis (7cp)
+
+
+
+ 112 +
+
+ +
+
+
                } else if 1.2 < remaining_prog && remaining_prog <= 2.0 {
+
+
+
+ 113 +
+
+ +
+
+
                    craft.cp -= 12; // Will finish with observe+focusedSynthesis (12cp)
+
+
+
+ 114 +
+
+ +
+
+
                }
+
+
+
+ 115 +
+
+ +
+
+
                craft.durability -= 10; // Save the final step, since we always aim to end with -5dur, it doesn't matter
+
+
+
+ 116 +
+
+ +
+
+
                routes.push(craft);
+
+
+
+ 117 +
+
+ +
+
+
                continue;
+
+
+
+ 118 +
+
+ +
+
+
            }
+
+
+
+ 119 +
+
+ +
+
+

+            
+
+
+ 120 +
+
+ +
+
+
            // Keep adding initial routes with several pass, we must be able to finish in one step
+
+
+
+ 121 +
+
+ +
+
+
            // 8 Seemed to be a good initial guess with enouth to use a good amount of WN / WNII to get close
+
+
+
+ 122 +
+
+ +
+
+
            // A higher value will yield more initial guesses with minimal benefits
+
+
+
+ 123 +
+
+ +
+
+
            // A lover value will yield less initial guesses and might spent too much CP to get to the required progression
+
+
+
+ 124 +
+
+ +
+
+
            if craft.step_count < craft.args.depth {
+
+
+
+ 125 +
+
+ +
+
+
                queue.push(craft);
+
+
+
+ 126 +
+
+ +
+
+
            }
+
+
+
+ 127 +
+
+ +
+
+
        }
+
+
+
+ 128 +
+
+ +
+
+
    }
+
+
+
+ 129 +
+
+ +
+
+
    routes
+
+
+
+ 130 +
+
+ +
+
+
}
+
+
+
+ 131 +
+
+ +
+
+

+            
+
+
+ 132 +
+
+ +
+
+
/// Find the list of authorised actions for this step
+
+
+
+ 133 +
+
+ +
+
+
pub fn next_action_phase_2<'a>(craft: &Craft<'a>) -> Vec<Option<&'a Action>> {
+
+
+
+ 134 +
+
+ +
+
+
    let mut available_actions = vec![
+
+
+
+ 135 +
+
+ +
+
+
        &ACTIONS.basic_touch,
+
+
+
+ 136 +
+
+ +
+
+
        &ACTIONS.prudent_touch,
+
+
+
+ 137 +
+
+ +
+
+
        &ACTIONS.preparatory_touch,
+
+
+
+ 138 +
+
+ +
+
+
    ];
+
+
+
+ 139 +
+
+ +
+
+
    let mut forbidden_actions = Vec::new();
+
+
+
+ 140 +
+
+ +
+
+
    if craft.success != Success::Pending {
+
+
+
+ 141 +
+
+ +
+
+
        return vec![None];
+
+
+
+ 142 +
+
+ +
+
+
    }
+
+
+
+ 143 +
+
+ +
+
+
    if craft.buffs.innovation > 0 {
+
+
+
+ 144 +
+
+ +
+
+
        forbidden_actions.push(&ACTIONS.innovation);
+
+
+
+ 145 +
+
+ +
+
+
    } else {
+
+
+
+ 146 +
+
+ +
+
+
        if craft.buffs.inner_quiet >= 2 {
+
+
+
+ 147 +
+
+ +
+
+
            forbidden_actions.append(&mut vec![
+
+
+
+ 148 +
+
+ +
+
+
                &ACTIONS.basic_touch,
+
+
+
+ 149 +
+
+ +
+
+
                &ACTIONS.standard_touch,
+
+
+
+ 150 +
+
+ +
+
+
                &ACTIONS.advanced_touch,
+
+
+
+ 151 +
+
+ +
+
+
                &ACTIONS.trained_finesse,
+
+
+
+ 152 +
+
+ +
+
+
                &ACTIONS.prudent_touch,
+
+
+
+ 153 +
+
+ +
+
+
                &ACTIONS.preparatory_touch,
+
+
+
+ 154 +
+
+ +
+
+
                &ACTIONS.byregot_blessing,
+
+
+
+ 155 +
+
+ +
+
+
            ]);
+
+
+
+ 156 +
+
+ +
+
+
        }
+
+
+
+ 157 +
+
+ +
+
+
        available_actions.push(&ACTIONS.innovation);
+
+
+
+ 158 +
+
+ +
+
+
    }
+
+
+
+ 159 +
+
+ +
+
+
    if craft.buffs.manipulation == 0
+
+
+
+ 160 +
+
+ +
+
+
        && craft.buffs.basic_touch == 0
+
+
+
+ 161 +
+
+ +
+
+
        && craft.buffs.standard_touch == 0
+
+
+
+ 162 +
+
+ +
+
+
        && craft.buffs.inner_quiet < 8
+
+
+
+ 163 +
+
+ +
+
+
    {
+
+
+
+ 164 +
+
+ +
+
+
        available_actions.push(&ACTIONS.manipulation);
+
+
+
+ 165 +
+
+ +
+
+
    }
+
+
+
+ 166 +
+
+ +
+
+
    if craft.buffs.waste_not > 0 {
+
+
+
+ 167 +
+
+ +
+
+
        available_actions.push(&ACTIONS.preparatory_touch);
+
+
+
+ 168 +
+
+ +
+
+
        forbidden_actions.push(&ACTIONS.prudent_touch);
+
+
+
+ 169 +
+
+ +
+
+
    } else {
+
+
+
+ 170 +
+
+ +
+
+
        available_actions.push(&ACTIONS.prudent_touch);
+
+
+
+ 171 +
+
+ +
+
+
        forbidden_actions.push(&ACTIONS.preparatory_touch);
+
+
+
+ 172 +
+
+ +
+
+
    }
+
+
+
+ 173 +
+
+ +
+
+
    if craft.buffs.basic_touch > 0 {
+
+
+
+ 174 +
+
+ +
+
+
        available_actions.push(&ACTIONS.standard_touch);
+
+
+
+ 175 +
+
+ +
+
+
        forbidden_actions.push(&ACTIONS.basic_touch);
+
+
+
+ 176 +
+
+ +
+
+
    }
+
+
+
+ 177 +
+
+ +
+
+
    if craft.buffs.standard_touch > 0 {
+
+
+
+ 178 +
+
+ +
+
+
        available_actions.push(&ACTIONS.advanced_touch);
+
+
+
+ 179 +
+
+ +
+
+
        forbidden_actions.push(&ACTIONS.basic_touch);
+
+
+
+ 180 +
+
+ +
+
+
    }
+
+
+
+ 181 +
+
+ +
+
+

+            
+
+
+ 182 +
+
+ +
+
+
    if craft.buffs.inner_quiet >= craft.args.byregot_step {
+
+
+
+ 183 +
+
+ +
+
+
        // 10
+
+
+
+ 184 +
+
+ +
+
+
        available_actions.push(&ACTIONS.trained_finesse);
+
+
+
+ 185 +
+
+ +
+
+
        available_actions.push(&ACTIONS.great_strides);
+
+
+
+ 186 +
+
+ +
+
+
    }
+
+
+
+ 187 +
+
+ +
+
+
    if craft.buffs.great_strides > 0 {
+
+
+
+ 188 +
+
+ +
+
+
        forbidden_actions.push(&ACTIONS.trained_finesse);
+
+
+
+ 189 +
+
+ +
+
+
        forbidden_actions.push(&ACTIONS.great_strides);
+
+
+
+ 190 +
+
+ +
+
+
        if craft.buffs.innovation > 0 {
+
+
+
+ 191 +
+
+ +
+
+
            available_actions.push(&ACTIONS.byregot_blessing);
+
+
+
+ 192 +
+
+ +
+
+
        }
+
+
+
+ 193 +
+
+ +
+
+
    }
+
+
+
+ 194 +
+
+ +
+
+
    let mut final_actions: Vec<Option<&Action>> = Vec::new();
+
+
+
+ 195 +
+
+ +
+
+

+            
+
+
+ 196 +
+
+ +
+
+
    for action in available_actions {
+
+
+
+ 197 +
+
+ +
+
+
        if !forbidden_actions.contains(&action)
+
+
+
+ 198 +
+
+ +
+
+
            && !final_actions.iter().any(|a| a.unwrap() == action)
+
+
+
+ 199 +
+
+ +
+
+
        {
+
+
+
+ 200 +
+
+ +
+
+
            final_actions.push(Some(action));
+
+
+
+ 201 +
+
+ +
+
+
        }
+
+
+
+ 202 +
+
+ +
+
+
    }
+
+
+
+ 203 +
+
+ +
+
+
    final_actions
+
+
+
+ 204 +
+
+ +
+
+
}
+
+
+
+ 205 +
+
+ +
+
+

+            
+
+
+ 206 +
+
+ +
+
+
/// Apply all actions to the current route
+
+
+
+ 207 +
+
+ +
+
+
pub fn generate_routes_phase2<'a>(craft: Craft<'a>) -> Option<Vec<Craft<'a>>> {
+
+
+
+ 208 +
+
+ +
+
+
    let mut queue = VecDeque::new();
+
+
+
+ 209 +
+
+ +
+
+

+            
+
+
+ 210 +
+
+ +
+
+
    let mut top_route: Craft<'a> = craft.clone(); // Default route, no hq on that one
+
+
+
+ 211 +
+
+ +
+
+
    let mut top_routes: Vec<Craft<'a>> = vec![];
+
+
+
+ 212 +
+
+ +
+
+

+            
+
+
+ 213 +
+
+ +
+
+
    queue.push_back(craft);
+
+
+
+ 214 +
+
+ +
+
+

+            
+
+
+ 215 +
+
+ +
+
+
    while !queue.is_empty() {
+
+
+
+ 216 +
+
+ +
+
+
        let _craft = queue.pop_front().unwrap();
+
+
+
+ 217 +
+
+ +
+
+
        for action in next_action_phase_2(&_craft) {
+
+
+
+ 218 +
+
+ +
+
+
            if _craft.success != Success::Pending
+
+
+
+ 219 +
+
+ +
+
+
                || action.is_none()
+
+
+
+ 220 +
+
+ +
+
+
                || !action.unwrap().can_use(&_craft)
+
+
+
+ 221 +
+
+ +
+
+
            {
+
+
+
+ 222 +
+
+ +
+
+
                continue;
+
+
+
+ 223 +
+
+ +
+
+
            }
+
+
+
+ 224 +
+
+ +
+
+
            let mut craft = _craft.clone();
+
+
+
+ 225 +
+
+ +
+
+
            craft.run_action(action.unwrap());
+
+
+
+ 226 +
+
+ +
+
+
            if action.unwrap() == &ACTIONS.byregot_blessing {
+
+
+
+ 227 +
+
+ +
+
+
                #[cfg(not(feature = "fast"))]
+
+
+
+ 228 +
+
+ +
+
+
                if top_route.quality >= craft.recipe.quality {
+
+
+
+ 229 +
+
+ +
+
+
                    top_routes.push(craft.clone()); // Me memory
+
+
+
+ 230 +
+
+ +
+
+
                }
+
+
+
+ 231 +
+
+ +
+
+
                if top_route.quality < craft.quality {
+
+
+
+ 232 +
+
+ +
+
+
                    #[cfg(feature = "fast")]
+
+
+
+ 233 +
+
+ +
+
+
                    top_routes.push(craft.clone());
+
+
+
+ 234 +
+
+ +
+
+
                    top_route = craft;
+
+
+
+ 235 +
+
+ +
+
+
                }
+
+
+
+ 236 +
+
+ +
+
+
            } else {
+
+
+
+ 237 +
+
+ +
+
+
                queue.push_back(craft);
+
+
+
+ 238 +
+
+ +
+
+
            }
+
+
+
+ 239 +
+
+ +
+
+
        }
+
+
+
+ 240 +
+
+ +
+
+
    }
+
+
+
+ 241 +
+
+ +
+
+
    // Let's not forget the best result
+
+
+
+ 242 +
+
+ +
+
+
    top_routes.push(top_route);
+
+
+
+ 243 +
+
+ +
+
+
    Some(top_routes)
+
+
+
+ 244 +
+
+ +
+
+
}
+
+
+
+ + + diff --git a/coverage/html/src/specs.rs.html b/coverage/html/src/specs.rs.html new file mode 100644 index 0000000..d2ea3c1 --- /dev/null +++ b/coverage/html/src/specs.rs.html @@ -0,0 +1,2224 @@ + + + + + Grcov report - specs.rs + + +
+ + + +
+
+ 1 +
+
+ +
+
+
use std::fmt::Debug;
+
+
+
+ 2 +
+
+ +
+
+
use strum_macros::EnumIter;
+
+
+
+ 3 +
+
+ +
+
+

+            
+
+
+ 4 +
+
+ +
+
+
#[derive(Debug, Clone, Copy)]
+
+
+
+ 5 +
+
+ +
+
+
pub struct Recipe {
+
+
+
+ 6 +
+
+ +
+
+
    pub durability: u32,
+
+
+
+ 7 +
+
+ +
+
+
    pub progress: u32,
+
+
+
+ 8 +
+
+ +
+
+
    pub quality: u32,
+
+
+
+ 9 +
+
+ +
+
+
    pub progress_divider: u32,
+
+
+
+ 10 +
+
+ +
+
+
    pub quality_divider: u32,
+
+
+
+ 11 +
+
+ +
+
+
    pub progress_modifier: u32,
+
+
+
+ 12 +
+
+ +
+
+
    pub quality_modifier: u32,
+
+
+
+ 13 +
+
+ +
+
+
}
+
+
+
+ 14 +
+
+ +
+
+

+            
+
+
+ 15 +
+
+ +
+
+
#[derive(Debug, Clone, Copy)]
+
+
+
+ 16 +
+
+ +
+
+
pub struct Stats {
+
+
+
+ 17 +
+
+ +
+
+
    pub craftsmanship: u32,
+
+
+
+ 18 +
+
+ +
+
+
    pub control: u32,
+
+
+
+ 19 +
+
+ +
+
+
    pub max_cp: u32,
+
+
+
+ 20 +
+
+ +
+
+
}
+
+
+
+ 21 +
+
+ +
+
+

+            
+
+
+ 22 +
+
+ +
+
+
#[derive(Debug, Clone, Copy, PartialEq, EnumIter)]
+
+
+
+ 23 +
+
+ +
+
+
pub enum Buff {
+
+
+
+ 24 +
+
+ +
+
+
    InnerQuiet,
+
+
+
+ 25 +
+
+ +
+
+
    WasteNot,
+
+
+
+ 26 +
+
+ +
+
+
    GreatStrides,
+
+
+
+ 27 +
+
+ +
+
+
    Innovation,
+
+
+
+ 28 +
+
+ +
+
+
    Veneration,
+
+
+
+ 29 +
+
+ +
+
+
    Manipulation,
+
+
+
+ 30 +
+
+ +
+
+
    MuscleMemory,
+
+
+
+ 31 +
+
+ +
+
+
    // v Hidden v
+
+
+
+ 32 +
+
+ +
+
+
    BasicTouch,
+
+
+
+ 33 +
+
+ +
+
+
    StandardTouch,
+
+
+
+ 34 +
+
+ +
+
+
    Observe,
+
+
+
+ 35 +
+
+ +
+
+
}
+
+
+
+ 36 +
+
+ +
+
+

+            
+
+
+ 37 +
+
+ +
+
+
#[derive(Debug, Clone, Copy)]
+
+
+
+ 38 +
+
+ +
+
+
pub struct BuffState {
+
+
+
+ 39 +
+
+ +
+
+
    pub inner_quiet: u8,
+
+
+
+ 40 +
+
+ +
+
+
    pub waste_not: u8,
+
+
+
+ 41 +
+
+ +
+
+
    pub great_strides: u8,
+
+
+
+ 42 +
+
+ +
+
+
    pub innovation: u8,
+
+
+
+ 43 +
+
+ +
+
+
    pub veneration: u8,
+
+
+
+ 44 +
+
+ +
+
+
    pub manipulation: u8,
+
+
+
+ 45 +
+
+ +
+
+
    pub muscle_memory: u8,
+
+
+
+ 46 +
+
+ +
+
+
    pub basic_touch: u8,
+
+
+
+ 47 +
+
+ +
+
+
    pub standard_touch: u8,
+
+
+
+ 48 +
+
+ +
+
+
    pub observe: u8,
+
+
+
+ 49 +
+
+ +
+
+
}
+
+
+
+ 50 +
+
+ +
+
+

+            
+
+
+ 51 +
+
+ +
+
+
impl BuffState {
+
+
+
+ 52 +
+
+ +
+
+
    pub fn default() -> Self {
+
+
+
+ 53 +
+
+ +
+
+
        Self {
+
+
+
+ 54 +
+
+ +
+
+
            inner_quiet: 0,
+
+
+
+ 55 +
+
+ +
+
+
            waste_not: 0,
+
+
+
+ 56 +
+
+ +
+
+
            great_strides: 0,
+
+
+
+ 57 +
+
+ +
+
+
            innovation: 0,
+
+
+
+ 58 +
+
+ +
+
+
            veneration: 0,
+
+
+
+ 59 +
+
+ +
+
+
            manipulation: 0,
+
+
+
+ 60 +
+
+ +
+
+
            muscle_memory: 0,
+
+
+
+ 61 +
+
+ +
+
+
            basic_touch: 0,
+
+
+
+ 62 +
+
+ +
+
+
            standard_touch: 0,
+
+
+
+ 63 +
+
+ +
+
+
            observe: 0,
+
+
+
+ 64 +
+
+ +
+
+
        }
+
+
+
+ 65 +
+
+ +
+
+
    }
+
+
+
+ 66 +
+
+ +
+
+

+            
+
+
+ 67 +
+
+ +
+
+
    pub fn remove(&mut self, buff: Buff) {
+
+
+
+ 68 +
+
+ +
+
+
        match buff {
+
+
+
+ 69 +
+
+ +
+
+
            Buff::InnerQuiet => self.inner_quiet = 0,
+
+
+
+ 70 +
+
+ +
+
+
            Buff::WasteNot => self.waste_not = 0,
+
+
+
+ 71 +
+
+ +
+
+
            Buff::GreatStrides => self.great_strides = 0,
+
+
+
+ 72 +
+
+ +
+
+
            Buff::Innovation => self.innovation = 0,
+
+
+
+ 73 +
+
+ +
+
+
            Buff::Veneration => self.veneration = 0,
+
+
+
+ 74 +
+
+ +
+
+
            Buff::Manipulation => self.manipulation = 0,
+
+
+
+ 75 +
+
+ +
+
+
            Buff::MuscleMemory => self.muscle_memory = 0,
+
+
+
+ 76 +
+
+ +
+
+
            Buff::BasicTouch => self.basic_touch = 0,
+
+
+
+ 77 +
+
+ +
+
+
            Buff::StandardTouch => self.standard_touch = 0,
+
+
+
+ 78 +
+
+ +
+
+
            Buff::Observe => self.observe = 0,
+
+
+
+ 79 +
+
+ +
+
+
        }
+
+
+
+ 80 +
+
+ +
+
+
    }
+
+
+
+ 81 +
+
+ +
+
+

+            
+
+
+ 82 +
+
+ +
+
+
    pub fn apply(&mut self, buff: Buff, value: u8) {
+
+
+
+ 83 +
+
+ +
+
+
        match buff {
+
+
+
+ 84 +
+
+ +
+
+
            Buff::InnerQuiet => {
+
+
+
+ 85 +
+
+ +
+
+
                if value == 0 {
+
+
+
+ 86 +
+
+ +
+
+
                    self.inner_quiet = 0;
+
+
+
+ 87 +
+
+ +
+
+
                } else {
+
+
+
+ 88 +
+
+ +
+
+
                    self.inner_quiet += value;
+
+
+
+ 89 +
+
+ +
+
+
                }
+
+
+
+ 90 +
+
+ +
+
+
            }
+
+
+
+ 91 +
+
+ +
+
+
            Buff::WasteNot => self.waste_not = value,
+
+
+
+ 92 +
+
+ +
+
+
            Buff::GreatStrides => self.great_strides = value,
+
+
+
+ 93 +
+
+ +
+
+
            Buff::Innovation => self.innovation = value,
+
+
+
+ 94 +
+
+ +
+
+
            Buff::Veneration => self.veneration = value,
+
+
+
+ 95 +
+
+ +
+
+
            Buff::Manipulation => self.manipulation = value,
+
+
+
+ 96 +
+
+ +
+
+
            Buff::MuscleMemory => self.muscle_memory = value,
+
+
+
+ 97 +
+
+ +
+
+
            Buff::BasicTouch => self.basic_touch = value,
+
+
+
+ 98 +
+
+ +
+
+
            Buff::StandardTouch => self.standard_touch = value,
+
+
+
+ 99 +
+
+ +
+
+
            Buff::Observe => self.standard_touch = value,
+
+
+
+ 100 +
+
+ +
+
+
        }
+
+
+
+ 101 +
+
+ +
+
+
    }
+
+
+
+ 102 +
+
+ +
+
+

+            
+
+
+ 103 +
+
+ +
+
+
    pub fn tick(&mut self) {
+
+
+
+ 104 +
+
+ +
+
+
        if self.waste_not > 0 {
+
+
+
+ 105 +
+
+ +
+
+
            self.waste_not -= 1;
+
+
+
+ 106 +
+
+ +
+
+
        }
+
+
+
+ 107 +
+
+ +
+
+
        if self.great_strides > 0 {
+
+
+
+ 108 +
+
+ +
+
+
            self.great_strides -= 1;
+
+
+
+ 109 +
+
+ +
+
+
        }
+
+
+
+ 110 +
+
+ +
+
+
        if self.innovation > 0 {
+
+
+
+ 111 +
+
+ +
+
+
            self.innovation -= 1;
+
+
+
+ 112 +
+
+ +
+
+
        }
+
+
+
+ 113 +
+
+ +
+
+
        if self.veneration > 0 {
+
+
+
+ 114 +
+
+ +
+
+
            self.veneration -= 1;
+
+
+
+ 115 +
+
+ +
+
+
        }
+
+
+
+ 116 +
+
+ +
+
+
        if self.manipulation > 0 {
+
+
+
+ 117 +
+
+ +
+
+
            self.manipulation -= 1;
+
+
+
+ 118 +
+
+ +
+
+
        }
+
+
+
+ 119 +
+
+ +
+
+
        if self.muscle_memory > 0 {
+
+
+
+ 120 +
+
+ +
+
+
            self.muscle_memory -= 1;
+
+
+
+ 121 +
+
+ +
+
+
        }
+
+
+
+ 122 +
+
+ +
+
+
        if self.basic_touch > 0 {
+
+
+
+ 123 +
+
+ +
+
+
            self.basic_touch -= 1;
+
+
+
+ 124 +
+
+ +
+
+
        }
+
+
+
+ 125 +
+
+ +
+
+
        if self.standard_touch > 0 {
+
+
+
+ 126 +
+
+ +
+
+
            self.standard_touch -= 1;
+
+
+
+ 127 +
+
+ +
+
+
        }
+
+
+
+ 128 +
+
+ +
+
+
    }
+
+
+
+ 129 +
+
+ +
+
+
}
+
+
+
+ 130 +
+
+ +
+
+

+            
+
+
+ 131 +
+
+ +
+
+
#[derive(Debug, Clone, Copy, PartialEq)]
+
+
+
+ 132 +
+
+ +
+
+
pub enum Success {
+
+
+
+ 133 +
+
+ +
+
+
    Pending,
+
+
+
+ 134 +
+
+ +
+
+
    Success,
+
+
+
+ 135 +
+
+ +
+
+
    Failure,
+
+
+
+ 136 +
+
+ +
+
+
}
+
+
+
+ + + diff --git a/coverage/html/tests/index.html b/coverage/html/tests/index.html new file mode 100644 index 0000000..74338e6 --- /dev/null +++ b/coverage/html/tests/index.html @@ -0,0 +1,105 @@ + + + + + Grcov report - tests + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FileLine CoverageFunctionsBranches
io.rs + + 100% + + + 100% + + 1 / 1 + 100%1 / 1 100%0 / 0
lib.rs + + 100% + + + 100% + + 1 / 1 + 100%1 / 1 100%0 / 0
+ + + diff --git a/coverage/html/tests/io.rs.html b/coverage/html/tests/io.rs.html new file mode 100644 index 0000000..c7289fb --- /dev/null +++ b/coverage/html/tests/io.rs.html @@ -0,0 +1,64 @@ + + + + + Grcov report - io.rs + + +
+ + + +
+
+ 1 +
+
+ 11 +
+
+

+            
+
+
+ + + diff --git a/coverage/html/tests/lib.rs.html b/coverage/html/tests/lib.rs.html new file mode 100644 index 0000000..cf779cc --- /dev/null +++ b/coverage/html/tests/lib.rs.html @@ -0,0 +1,64 @@ + + + + + Grcov report - lib.rs + + +
+ + + +
+
+ 1 +
+
+ 11 +
+
+

+            
+
+
+ + + diff --git a/pyproject.toml b/pyproject.toml index b998759..7e21dc0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "maturin" [project] # The rust bindings name = "xiv_csolver_lib" requires-python = ">=3.7" -version = "0.1.5" +version = "0.1.6" classifiers = [ "Programming Language :: Rust", "Programming Language :: Python :: Implementation :: CPython", diff --git a/python/pyproject.toml b/python/pyproject.toml index 7f9030e..f2d2440 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -9,7 +9,7 @@ authors = [ {name="Dandaedre"}, ] requires-python = ">=3.7" -version = "0.1.5" +version = "0.1.6" license = {text="Mozilla Public License Version 2.0"} classifiers = [ "Programming Language :: Rust", diff --git a/python/src/xiv_csolver/resources/ffcraft_solver.ico b/python/src/xiv_csolver/resources/ffcraft_solver.ico deleted file mode 100644 index 3b9f0cf..0000000 Binary files a/python/src/xiv_csolver/resources/ffcraft_solver.ico and /dev/null differ diff --git a/python/src/xiv_csolver/resources/ffcraft_solver.png b/python/src/xiv_csolver/resources/ffcraft_solver.png deleted file mode 100644 index 60a51ef..0000000 Binary files a/python/src/xiv_csolver/resources/ffcraft_solver.png and /dev/null differ diff --git a/src/action.rs b/src/action.rs index cf9d44e..89f16bb 100644 --- a/src/action.rs +++ b/src/action.rs @@ -1,24 +1,55 @@ +//! Module containing all actions that a crafter can execute +//! +//! All actions are defined as Action, containing all methods to actively use it in a craft +//! while ActionBuilder is used only initally as a lazy_static setup +//! + use crate::craft::Craft; use crate::specs::{Buff, Success}; use lazy_static::lazy_static; -#[allow(dead_code)] use std::fmt::Debug; +/// Hold an action for the solver to try using +/// +/// It will be used heavily to try/discard actions durin craft pub struct Action { + /// The action name, in a human readable format, it will be used to generate a short_name pub name: String, + /// The natural durability cost, without buff or reductions pub dur: u32, + /// The cost in cp pub cp: u32, + /// The amount of progression provided in percent (not the actual value added to the craft) pub progress: u32, + /// The amount of quality provided in percent (not the acual value added to the craft) pub quality: u32, + /// The name of the buff given, if any pub buff: Option<(Buff, u8)>, + /// The short name of the action, as used by most crafting simulator (aka: stripped of whitespace) pub short_name: String, } +/// Builds an action based on an action +/// +/// Made to initialize lazy_static and nothing more pub struct ActionBuilder { action: Action, } impl ActionBuilder { + /// Base creator, takes a name and initialize an empty action with the short_name + /// and name setup and default values for all other fields + /// + /// # Examples + /// ``` + /// use xiv_csolver_lib::action::ActionBuilder; + /// use xiv_csolver_lib::specs::Buff; + /// ActionBuilder::new("Muscle Memory") + /// .cp(6) + /// .progress(300) + /// .buff(Some((Buff::MuscleMemory, 5))) + /// .build(); + /// ``` pub fn new(name: &str) -> Self { let mut short_name = name.to_string(); short_name = short_name.replace("II", "2"); @@ -46,31 +77,46 @@ impl ActionBuilder { }, } } + /// Changes the durability consumption of an action pub fn dur(mut self, dur: u32) -> Self { self.action.dur = dur; self } + + /// Changes the crafting points (cp) consumption of an action pub fn cp(mut self, cp: u32) -> Self { self.action.cp = cp; self } + /// Changes the amount of progress of an action pub fn progress(mut self, progress: u32) -> Self { self.action.progress = progress; self } + /// Changes the amount of quality of an action pub fn quality(mut self, quality: u32) -> Self { self.action.quality = quality; self } + /// Makes an action add a buff for certain number of actions + /// The buffs available are defined in [specs.rs](crate::specs::Buff) + /// + /// `` + /// (self.recipe.progress as f32 - self.progression as f32) / self.get_base_progression() as f32; + /// `` pub fn buff(mut self, buff: Option<(Buff, u8)>) -> Self { self.action.buff = buff; self } + /// Finalize the usage of the ActionBuilder and return the action + /// Once again, all this is for the usage of lazy_static pub fn build(self) -> Action { self.action } } +/// Custom implementation of the equality operator, it is used to compare actions during the +/// the crafting process impl PartialEq for Action { fn eq(&self, other: &Self) -> bool { self.cp == other.cp @@ -80,10 +126,14 @@ impl PartialEq for Action { } } +/// A craft action, after compilation (with lazy_static) +// no other actions should be created impl Action { + /// Get the printable name of the action pub fn get_name(&self) -> String { self.name.clone() } + /// Get the CP cost, reduced by the eventual chain buffs currently active in the craft pub fn get_cp_cost(&self, _craft: &Craft) -> u32 { if self == &ACTIONS.standard_touch && _craft.buffs.basic_touch > 0 { return 18; @@ -93,6 +143,8 @@ impl Action { }; self.cp } + /// Get the durability cost this action would have if used at this stage of the craft + /// This method accounts for the effects of **master mend** and **waste not**. pub fn get_durability_cost(&self, _craft: &Craft) -> u32 { if self == &ACTIONS.masters_mend { return 30; @@ -109,6 +161,14 @@ impl Action { } dur } + /// Get the progress effect this action would have if used at this stage of the craft + /// This method accounts for the effects of **groundwork** under 20 durability, + /// and the effects of **veneration** and **muscle memory** + /// # Exemple + /// ```md + /// - Groundwork will return 200 if the durability remaining is above 20 + /// - Basic Synthesis will return 100 if no buffs are up and 150 with veneration + /// ``` pub fn get_progress(&self, _craft: &Craft) -> u32 { let mut prog = self.progress as f64; if self.dur == 20 && _craft.durability < self.get_durability_cost(_craft) as i32 { @@ -123,6 +183,9 @@ impl Action { } (prog * mult).floor() as u32 } + + /// Get the quality effect this action would have if used at this stage of the craft. + /// This method account for the **inner quiet** stacking effect, **innovation** and **great strides** pub fn get_quality(&self, _craft: &Craft) -> u32 { let mut qual = self.quality as f64; if self == &ACTIONS.byregot_blessing { @@ -141,9 +204,19 @@ impl Action { let iq_mult = (_craft.buffs.inner_quiet as f64 * 0.1) + 1.0; (qual * mult * iq_mult).floor() as u32 } + /// Returns the Buff (if any) up at this time of the craft pub fn get_buff(&self) -> Option<(Buff, u8)> { self.buff } + /// Returns a bool representing if this action **can** be used, note that this does only account + /// for the game limitations and not viability limitation + /// + /// # Improvements + /// This function could easily prune useless actions by considering them not available. + /// Doing so could stop early refresh of buffs and spam of observe and such. + /// However some of such "optimisations" could just plain hurt the craft by forbidding a *seemingly* + /// useless action. The "bruteforce" method being easily computatble on a modern computer, such + /// optimisations arent warrented and left to aother time. pub fn can_use(&self, _craft: &Craft) -> bool { if self.get_cp_cost(_craft) > _craft.cp as u32 { return false; @@ -170,32 +243,110 @@ impl Debug for Action { } } +/// The callable actionlist, to be used in conjunction with lazy_static pub struct ActionList { + /// Increases progress. + /// Efficiency: 300% + /// Success Rate: 100% + /// Additional Effect: Efficiency of your next Synthesis action is increased by 100% + /// Available only on the first step. + /// Additional effect is active for five steps. pub muscle_memory: Action, + /// Increases quality. + /// Efficiency: 100% + /// Success Rate: 100% + /// Additional Effect: Increases Inner Quiet stack by one (up to 10) + /// Availabe only on the first step. pub reflect: Action, + /// Increases progress. + /// Efficiency: 120% + /// Success Rate: 100% pub basic_synthesis: Action, + /// Increases progress. + /// Efficiency: 120% + /// Success Rate: 100% pub careful_synthesis: Action, + /// Increases progress at greater cost to durability. + /// Efficiency decreases by half when durability is below durability cost. + /// Efficiency: 300% + /// Success Rate: 100% + /// Durability Cost: 20 pub groundwork: Action, + /// Increases progress at half the durability cost. + /// Efficiency: 180% + /// Success Rate: 100% + /// Unavailable when Waste Not or Waste Not II is active. pub prudent_synthesis: Action, + /// Increases both progress and quality. + /// Efficiency: 100% + /// Success Rate: 100% pub delicate_synthesis: Action, + /// Increases quality. + /// Efficiency: 100% + /// Success Rate: 100% pub basic_touch: Action, + /// Increases quality. + /// Efficiency: 125% + /// Success Rate: 100% + /// Combo action: Basic Touch + /// Combo bonus: CP cost reduced to 18 pub standard_touch: Action, + /// Increases quality. Inner Quiet effect ends upon use. + /// Efficiency: 100% plus 20% for each count of your Inner Quiet stack, up to a maximum of 300% + /// Success Rate: 100% + /// Requires at least one stack of Inner Quiet. pub byregot_blessing: Action, + /// Increases quality at half the durability cost. + /// Efficiency: 100% + /// Success Rate: 100% + /// Unavailable when Waste Not or Waste Not II are active. pub prudent_touch: Action, + /// Increases quality at a greater cost to durability. + /// Additional Effect: Increases Inner Quiet stack by one (up to 11) + /// Efficiency: 200% + /// Success Rate: 100% + /// Durability Cost: 20 pub preparatory_touch: Action, + /// Increases quality. + /// Efficiency: 150% + /// Success Rate: 100% + /// Combo action: Standard Touch + /// Combo bonus: CP cost reduced to 18 pub advanced_touch: Action, + /// Increases quality at no cost to durability. + /// Efficiency: 100% + /// Success Rate: 100% + /// Available only when Inner Quiet stack size is 10. pub trained_finesse: Action, + /// Restores item durability by 30. pub masters_mend: Action, + + // Restores item durability by 60. + // pub masters_mend_2: Action, + /// Reduces loss of durability by 50% for the next four steps. pub waste_not: Action, + /// Reduces loss of durability by 50% for the next eight steps. pub waste_not_ii: Action, + /// Restores 5 points of durability after each step for the next eight steps. pub manipulation: Action, + /// Increases efficiency of Synthesis actions by 50% for the next four steps. pub veneration: Action, + /// Increases the efficiency of next Touch action by 100%. + /// Effect active for three steps. pub great_strides: Action, + /// Increases efficiency of Touch actions by 50% for the next four steps. pub innovation: Action, + // Do nothing for one step. //pub observe: Action, + // Increases progress. + // Efficiency: 200% + // Success Rate: 50% + // Combo Action: Observe + // Combo Bonus: Increases success rate to 100% //pub focused_synthesis: Action, } +/// Create all base actions as a default (for lazy_static) impl Default for ActionList { fn default() -> Self { Self { @@ -300,5 +451,6 @@ impl Default for ActionList { } lazy_static! { + /// Initialize a static pseudo &Craft: ACTIONS pub static ref ACTIONS: ActionList = ActionList::default(); } diff --git a/src/bin/xiv_csolver.rs b/src/bin/xiv_csolver.rs index de9c789..c94c690 100644 --- a/src/bin/xiv_csolver.rs +++ b/src/bin/xiv_csolver.rs @@ -1,4 +1,100 @@ -// #![warn(missing_docs,unsafe_code,unstable_features,)] +//! # Solver bin for FFXIV Crafting in Rust +//! +//! This project strives to provide a fast, accurate and reliable way to craft +//! in FFXIV and obtain HQ results +//! +//! This project also provides bindings for python to allow hooking it to any form of better GUI/CLI +//! +//! The project is (for now) self-hosted and hosted on [Github](https://github.com/Dandaedre/xiv_csolver) +//! +//! ## Getting started +//! +//! ### Development +//! +//! #### Rust +//! To set up the whole development environment, it is recommended to use cargo-make +//! +//! Doing so will allow you custom commands to +//! +//! ```sh +//! cargo make rebuild +//! ``` +//! To rebuild the whole project +//! +//! ```sh +//! cargo make release +//! ``` +//! To generate the release files, bins and libs, package them and make them ready to release +//! +//! #### Python +//! +//! It is really recommended to set up a venv to handle the python development +//! +//! All bindings and the explanation of how to use them can be found in the [`io`](crate::io) module. +//! +//! ### Features +//! +//! Use these by running `cargo run/build --features ` +//! +//! - ``no_python`` : Don't build the lib & python bindings (WIP, not fully implemented) +//! - ``fast`` : Don't allow some under-optimisation to run (saving global run-time) +//! - ``verbose`` : Allow for more debug messages (note that -v(vv) must still be passed to activate them) +//! +//! ## Regenerating the API Bindings +//! +//! The python bindings are generated using maturin +//! +//! ```sh +//! cargo install maturin +//! maturin develop +//! ``` +//! ## Solving and bias +//! +//! The solving algorithm used has a very strong bias toward a particular method: +//! +//! - **Step 1** : Try to push the progression of the craft one step before being finishable +//! - **Step 2** : Try to increase the quality as much as possible. +//! - **Step 3** : Finish the craft +//! +//! To account for a lot of possibilities, step one generates all methods to try and finish the craft +//! and step two tests all methods to up the quality until all crafting points are depleted +//! Doing so ensures by brute force that all permutations are thoroughly tested. +//! +//! While this method works and is very likely the best method for the current patch, +//! a rework of the crafting actions could very well make this method subpar or at least +//! on par with another method. +//! +//! In layman's term, only the groundwork opening is tested and no delicate synthesis spam is tested. +//! However, for now, these two crafting techniques remain subpar and discarding them comes at no +//! loss for the crafter. +//! +//! Others algorithm exists and could very well cover all other basis at the expense of runtime. +//! We have chosen not to implement them as they (for now) would be very unlikely to uncover anything +//! meaningful. +//! +//! ### Leveling +//! +//! We have (for now at least) no intention to release a leveling feature to the crafting solver +//! However, selecting some spells and buffs and have them disabled could be added as a feature +//! hence making a "leveling" option +//! +//! If it is ever released, this feature is likely to be heavily reliant on the python GUI. +//! +//! +//! ## Contributing +//! +//! All form of contributions are welcome ! +//! +//! While this project was originally a collab and didn't strive to encompass every need +//! of a modern FFXIV crafter, more polish and finish is always welcome. +//! +//! ## License +//! +//! The original code was released without a license by [RikaKagurasaka](https://github.com/RikaKagurasaka/xiv_craft_solver) +//! +//! All this fork's code is released under [Apache-2.0](http://www.apache.org/licenses/LICENSE-2.0) + +#![warn(missing_docs)] use clap::Parser; use std::time::Instant; diff --git a/src/craft.rs b/src/craft.rs index 9a04e5a..b60e49f 100644 --- a/src/craft.rs +++ b/src/craft.rs @@ -1,24 +1,48 @@ +//! Module containing everything to create a craft and all methods to get the current state of the craft +//! +//! A craft represent the state of the recipe with a vector of actions applied to it. +//! Applying actions to it will make the craft progress, while branching and trying other actions +//! will be done by cloning +//! + use crate::action::Action; use crate::specs::{Buff, BuffState, Recipe, Stats, Success}; use crate::Parameters; use std::fmt::{Debug, Display, Formatter}; +/// The craft structure, note that there is no standard way of backtracking +/// and a traditional branching method is applied when solving. #[derive(Clone)] pub struct Craft<'a> { + /// The recipe used, contains all needed information on the difficulty and target pub recipe: Recipe, + /// The stats of the crafter pub stats: Stats, + /// The buffs currently running pub buffs: BuffState, + /// The step count, aka number of steps done from the beggining of the craft pub step_count: u32, + /// The remaining durability pub durability: i32, + /// The current progression pub progression: u32, + /// The current quality pub quality: u32, + /// The cp currently remaining pub cp: i32, + /// Wether the craft has succeded, is pending sucess, or failed pub success: Success, + /// The vector of action already applied, structs are used for the vector since + /// static references are used and therefore take no additional memory at runtime pub actions: Vec<&'a Action>, + /// The parameters used for the craft + /// TODO: The usage of a non reference is quite an oversight and should be changed ASAP pub args: Parameters, } impl<'a> Craft<'a> { + /// Create a new craft with a recipe, stats and parameters + /// pub fn new(recipe: Recipe, stats: Stats, params: Parameters) -> Craft<'a> { Self { recipe, @@ -35,13 +59,18 @@ impl<'a> Craft<'a> { } } + /// How much progression will be done by an action with 100 efficiency and no buffs + /// This function is mainly used to know wether or not the craft will finish in + /// 1, 1.2 or 2.0 actions. 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; (base_value * (self.recipe.progress_modifier as f64 / 100.0) as f64).floor() as u32 } - + /// How much quality will the crafter generate with one action with 100 efficiency and no buffs + /// This function is usually called by [`run_action`](crate::craft::Craft::run_action) + /// wich will then apply all needed buff and progress the craft 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) @@ -49,6 +78,15 @@ impl<'a> Craft<'a> { (base_value * (self.recipe.quality_modifier as f64 / 100.0) as f64).floor() as u32 } + /// Add an action to the current craft + /// This method will: + /// - Check wether the action can be used + /// - Increment the step count + /// - Decrease cp + /// - Decrease or increase durability + /// - Increase progression + /// - "Tick" buffs (substract 1 from their remaining time) and remove them if consumed + /// - Add the used action to the vec of actions used pub fn run_action(&mut self, action: &'a Action) -> &mut Craft<'a> { if !action.can_use(self) { self.success = Success::Failure; diff --git a/src/io.rs b/src/io.rs index 83457d4..6c06e85 100644 --- a/src/io.rs +++ b/src/io.rs @@ -1,3 +1,9 @@ +//! The main IO module +//! For now it contains the python bindings, the Args bindings (for clap) and the struct +//! needed to hold all parameters needed at runtime +//! +//! Moving the bindings and making them non mandatory is a WIP + use crate::Craft; use clap::Parser; use core::fmt::Display; @@ -5,15 +11,27 @@ use core::fmt::Display; // #[cfg(not(feature = "no_python"))] use pyo3::prelude::*; +/// The parameters needed at runtime, used since Args cannot easily be passed to python #[derive(Debug, Clone, Copy)] pub struct Parameters { + /// The number of threads to use + /// TODO: Add an auto feature to guess threads depending on architecture and action pool pub threads: usize, + /// The level of verbosity from 0 to 3 pub verbose: u8, + /// How many steps are allowed for finishing the craft + /// TODO: Be a little smarted about this approach and stop guessing if enough starters are found + /// and continue guessing if more are needed pub depth: u32, + /// Wether to try every mesure to finish the craft or not pub desperate: bool, + /// How early byregot will be used, setting it too low high miss easy solutions (for small crafts) + /// but setting it too low will have the solver try byregot way too often adding many useless crafts + /// in the pool of solutions pub byregot_step: u8, } +/// The args passed to the CLI, used by clap to generate a nice argument parser #[derive(Parser, Debug, Clone)] #[command(author, version, about, long_about = None)] pub struct Args { @@ -52,47 +70,61 @@ pub struct Args { /// A final stripped down version of a craft /// used for final print and talking with python +/// TODO: Half of these parameter are unique and SHOULD NOT be replicated on every solution #[derive(Debug)] #[pyclass] pub struct SolverResult { + /// The number of steps this particular craft takes #[pyo3(get)] pub steps: u32, + /// The quality obtained at the end of the craft (absolute value) #[pyo3(get)] pub quality: u32, + /// The amount of progression obtained at the end of the craft (absolute value) #[pyo3(get)] pub progression: u32, + /// The remaining durability at the end of this craft #[pyo3(get)] pub durability: i32, + /// The remaining crafting points at the end of this craft #[pyo3(get)] pub cp: i32, + /// The total amount of crafting points the crafter had available (Deprecated) #[pyo3(get)] pub total_cp: u32, + /// The total amount of progression needed to finish the craft (Deprecated) #[pyo3(get)] pub total_progression: u32, + /// The total quality needed to make this craft 100% HQ (Deprecated) #[pyo3(get)] pub total_quality: u32, + /// The total durability for this craft (Deprecated) #[pyo3(get)] pub total_durability: u32, + /// The list of actions, as a string #[pyo3(get)] pub actions: Vec, + /// The amount of solutions found during the first step of the solving (Used for debug) (Deprecated) #[pyo3(get)] pub step1_solutions: usize, + /// The amount of solutions found at the end of the second step of solving (Used for debug) (Deprecated) #[pyo3(get)] pub step2_solutions: usize, #[pyo3(get)] + /// Wether a 100% HQ solution was found (Deprecated) 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(()) + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { + write!(f, "{:?}", self.actions) } } -//#[pymethods] impl SolverResult { + /// Create a SolverResult from a solution + /// Using this returns a solution, usable by Python pub fn from_craft( craft: &Craft, step1_solutions: usize, @@ -104,6 +136,7 @@ impl SolverResult { .iter() .map(|action| format!("{}", action.short_name)) .collect::>(); + // Todo: Stop adding these by hand let arg = (craft.recipe.progress as f32 - craft.progression as f32) / craft.get_base_progression() as f32; if 0.0 < arg && arg < 1.2 { @@ -136,6 +169,12 @@ impl SolverResult { #[pymethods] impl SolverResult { + /// Default method to create an empty solution, only used for debug purposes + /// to test wether the import worked + /// ```py + /// import xiv_csolver_lib + /// print(xiv_csolver_lib.default()) + /// ``` #[staticmethod] pub fn default() -> Self { Self { @@ -155,6 +194,8 @@ impl SolverResult { } } + /// Implement a pretty_print method + /// Mainly used for debug purposes pub fn pretty_print(&self) { println!( "Quality: [{}/{}] | Durability: [{}/{}] | Cp : [{}/{}] | Steps : {}", @@ -171,6 +212,7 @@ impl SolverResult { } impl Parameters { + /// Create parameters from the arguments parsed by clap pub fn from_args(args: &Args) -> Self { Self { depth: if args.desperate { 11 } else { 8 }, @@ -204,10 +246,37 @@ pub fn test_result() -> SolverResult { #[cfg(not(feature = "no_python"))] use crate::{solve_craft, Recipe, Stats}; +/// Solve a craft from parameters given by python +/// The values are all obtained by a `&PyAny`, wich must guaranty that several attributes are +/// accesible by `__getattr__` +/// +/// ```python +/// import xiv_craft_solver, rich +/// +/// class FeedingClass: +/// 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 +/// crafting_feeder = FeedingClass() +/// rich.inspect(xiv_csolver_lib.solve_from_python(crafting_feeder)) +/// ``` #[cfg(not(feature = "no_python"))] #[pyfunction] pub fn solve_from_python(values: &PyAny) -> PyResult>> { - // // Create Recipe + // Create Recipe let recipe = Recipe { durability: values.getattr("durability")?.extract()?, progress: values.getattr("progress")?.extract()?, @@ -238,3 +307,107 @@ pub fn solve_from_python(values: &PyAny) -> PyResult>> let res = solve_craft(recipe, stats, param); Ok(res) } + +#[cfg(test)] +mod tests { + use crate::io::Args; + use crate::{Parameters, SolverResult}; + use clap::Parser; + use pretty_assertions::{assert_eq, assert_ne}; + + impl PartialEq for Parameters { + fn eq(&self, rhs: &Parameters) -> bool { + (self.byregot_step == rhs.byregot_step) + & (self.depth == rhs.depth) + & (self.desperate == rhs.desperate) + & (self.threads == rhs.threads) + } + } + + #[test] + pub fn test_parameters_derived_attributes() { + let def = Parameters { + byregot_step: 0, + depth: 0, + desperate: false, + threads: 42, + verbose: 1, + }; + let def2 = def; + let def3 = def2.clone(); + + assert_eq!(def2, def3); + } + + #[test] + pub fn test_display() { + let def = SolverResult::default(); + assert_ne!(def.to_string(), ""); + assert_eq!(def.to_string(), "[\"Act1\", \"Act2\"]"); + def.pretty_print(); + } + + #[test] + pub fn test_debug() { + let def = SolverResult::default(); + assert_eq!(format!("{:?}", def),"SolverResult { steps: 0, quality: 0, progression: 0, durability: 0, cp: 0, total_cp: 0, total_progression: 0, total_quality: 0, total_durability: 0, actions: [\"Act1\", \"Act2\"], step1_solutions: 0, step2_solutions: 0, found_100_percent: false }"); + } + + #[test] + pub fn test_arguments() { + // Create false argument parameter + let a = Args { + character_name: "Bob GZ".to_string(), + depth: 77, + desperate: false, + file_name: "test.toml".to_string(), + long: false, + recipe_name: "Belladone".to_string(), + threads: 11, + verbose: 1, + }; + let a2 = a.clone(); + println!("{:?}", a2); + // Test Custom recipe + let a3 = Args::parse_from([ + "ultraman", + "-r", + "recipe", + "-c", + "dan", + "-f", + "bigfile.toml", + "-d", + "45", + "-t", + "4", + "-D", + "-l", + "-vvv", + ]); + let _ = Args::parse_from(["-V"]); + let _ = Args::parse_from(["-H"]); + assert_eq!(a3.recipe_name, "recipe"); + assert_eq!(a3.character_name, "dan"); + assert_eq!(a3.file_name, "bigfile.toml"); + assert_eq!(a3.verbose, 3); + assert_eq!(a3.depth, 45); + assert_eq!(a3.threads, 4); + assert_eq!(a3.desperate, true); + assert_eq!(a3.long, true); + + // Test default parameters + let a4 = Args::parse_from(["bobGZ"]); + assert_eq!(a4.recipe_name, "default_recipe"); + assert_eq!(a4.character_name, "default_character"); + assert_eq!(a4.file_name, "craft.toml"); + assert_eq!(a4.verbose, 0); + assert_eq!(a4.depth, 8); + assert_eq!(a4.threads, 4); + assert_eq!(a4.desperate, false); + assert_eq!(a4.long, false); + } + + #[test] + pub fn test_parameters() {} +} diff --git a/src/lib.rs b/src/lib.rs index afbaa6d..96c4de4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,101 @@ +//! # Solver bin for FFXIV Crafting in Rust +//! +//! This project strives to provide a fast, accurate and reliable way to craft +//! in FFXIV and obtain HQ results +//! +//! This project also provides bindings for python to allow hooking it to any form of better GUI/CLI +//! +//! The project is (for now) self-hosted and hosted on [Github](https://github.com/Dandaedre/xiv_csolver) +//! +//! ## Getting started +//! +//! ### Development +//! +//! #### Rust +//! To set up the whole development environment, it is recommended to use cargo-make +//! +//! Doing so will allow you custom commands to +//! +//! ```sh +//! cargo make rebuild +//! ``` +//! To rebuild the whole project +//! +//! ```sh +//! cargo make release +//! ``` +//! To generate the release files, bins and libs, package them and make them ready to release +//! +//! #### Python +//! +//! It is really recommended to set up a venv to handle the python development +//! +//! All bindings and the explanation of how to use them can be found in the [`io`](crate::io) module. +//! +//! ### Features +//! +//! Use these by running `cargo run/build --features ` +//! +//! - ``no_python`` : Don't build the lib & python bindings (WIP, not fully implemented) +//! - ``fast`` : Don't allow some under-optimisation to run (saving global run-time) +//! - ``verbose`` : Allow for more debug messages (note that -v(vv) must still be passed to activate them) +//! +//! ## Regenerating the API Bindings +//! +//! The python bindings are generated using maturin +//! +//! ```sh +//! cargo install maturin +//! maturin develop +//! ``` +//! ## Solving and bias +//! +//! The solving algorithm used has a very strong bias toward a particular method: +//! +//! - **Step 1** : Try to push the progression of the craft one step before being finishable +//! - **Step 2** : Try to increase the quality as much as possible. +//! - **Step 3** : Finish the craft +//! +//! To account for a lot of possibilities, step one generates all methods to try and finish the craft +//! and step two tests all methods to up the quality until all crafting points are depleted +//! Doing so ensures by brute force that all permutations are thoroughly tested. +//! +//! While this method works and is very likely the best method for the current patch, +//! a rework of the crafting actions could very well make this method subpar or at least +//! on par with another method. +//! +//! In layman's term, only the groundwork opening is tested and no delicate synthesis spam is tested. +//! However, for now, these two crafting techniques remain subpar and discarding them comes at no +//! loss for the crafter. +//! +//! Others algorithm exists and could very well cover all other basis at the expense of runtime. +//! We have chosen not to implement them as they (for now) would be very unlikely to uncover anything +//! meaningful. +//! +//! ### Leveling +//! +//! We have (for now at least) no intention to release a leveling feature to the crafting solver +//! However, selecting some spells and buffs and have them disabled could be added as a feature +//! hence making a "leveling" option +//! +//! If it is ever released, this feature is likely to be heavily reliant on the python GUI. +//! +//! +//! ## Contributing +//! +//! All form of contributions are welcome ! +//! +//! While this project was originally a collab and didn't strive to encompass every need +//! of a modern FFXIV crafter, more polish and finish is always welcome. +//! +//! ## License +//! +//! The original code was released without a license by [RikaKagurasaka](https://github.com/RikaKagurasaka/xiv_craft_solver) +//! +//! All this fork's code is released under [Apache-2.0](http://www.apache.org/licenses/LICENSE-2.0) + +#![warn(missing_docs)] + use crate::io::SolverResult; use crate::{ craft::Craft, @@ -11,7 +109,7 @@ pub mod action; pub mod craft; pub mod io; mod solver; -mod specs; +pub mod specs; /// Solve the craft with given arguments, this functions calls threads and must own it's values pub fn solve_craft<'a>( diff --git a/src/specs.rs b/src/specs.rs index 28bf66c..04a50e6 100644 --- a/src/specs.rs +++ b/src/specs.rs @@ -1,54 +1,106 @@ +//! This modules instanciate all the tools needed to load and use the solver + use std::fmt::Debug; use strum_macros::EnumIter; +/// The recipe to craft +/// On some websites the fields are instead called +/// [Progress, quality, durability, progress difficulty, quality difficulty, extra progress difficulty, extra quality difficulty] #[derive(Debug, Clone, Copy)] pub struct Recipe { + /// The recipe durability (also called solidity) (35, 40, 70 or 80 usually) pub durability: u32, + /// The total recipe progress needed pub progress: u32, + /// The total recipe quality pub quality: u32, + /// How much the progress is hard to set, + /// it's an (hidden) extra progress multiplier, + /// inflicting a -10% to -30% to starred recipes + /// Also called `progress_difficulty` pub progress_divider: u32, + /// The same (hidden) difficulty multiplier, for quality + /// Also called `progress_difficulty` pub quality_divider: u32, + /// Modifies how much the base stats are affecting the craft progress + /// Also called `progress_extra_difficulty` pub progress_modifier: u32, + /// Modifies how much the base stats are affectif the craft quality + /// Also called `quality_extra_difficulty` pub quality_modifier: u32, } +/// The craftsman stats #[derive(Debug, Clone, Copy)] pub struct Stats { + /// The craftsmanship, influences the progress pub craftsmanship: u32, + /// The control, inluences the quality pub control: u32, + /// The amount of cp, ressource used for actions pub max_cp: u32, } +/// The buffs available for the crafter #[derive(Debug, Clone, Copy, PartialEq, EnumIter)] pub enum Buff { + /// Gain a stack of Inner Quiet with every increase in quality, up to a maximum of 10. + /// Grants a 10% bonus to the efficiency of Touch actions for each stack. InnerQuiet, + /// Reduces loss of durability by 50%. WasteNot, + /// Increases the efficiency of next Touch action by 100%. GreatStrides, + /// Increases efficiency of Touch actions by 50%. Innovation, + /// Increases efficiency of Synthesis actions by 50%. Veneration, + /// Restores 5 points of durability after each step. Manipulation, + /// Increases progress. + /// Efficiency: 300% + /// Success Rate: 100% + /// Additional Effect: Efficiency of your next Synthesis action is increased by 100% + /// Available only on the first step. + /// Additional effect is active for five steps. MuscleMemory, // v Hidden v + /// (Hidden) Combo with Standart touch costs 18 cp. BasicTouch, + /// (Hidden) Combo with Advanced touch costs 18 cp. StandardTouch, + /// (Hidden) Do nothing for one step. Observe, } +/// Keeps track of all the durations remaining on all buffs +/// Also called buff tracker in the docs #[derive(Debug, Clone, Copy)] pub struct BuffState { + /// Caps at 10 for a 100% extra efficiency in quality increase pub inner_quiet: u8, + /// Lasts for four steps if Waste not was used, height if Waste Not II was. pub waste_not: u8, + /// Effect active for three steps, dissipates after a quality action is used. pub great_strides: u8, + /// Lasts four steps pub innovation: u8, + /// Lasts four steps. pub veneration: u8, + /// Lasts height steps pub manipulation: u8, + /// Lasts five steps, dissipate after a progression action is used. pub muscle_memory: u8, + /// Lasts one step pub basic_touch: u8, + /// Lasts one step pub standard_touch: u8, + /// Lasts one step pub observe: u8, } impl BuffState { + /// Default state of buffs (all at zero) as per the beggining of craft pub fn default() -> Self { Self { inner_quiet: 0, @@ -64,6 +116,7 @@ impl BuffState { } } + /// Remove the given buff from the buff tracker pub fn remove(&mut self, buff: Buff) { match buff { Buff::InnerQuiet => self.inner_quiet = 0, @@ -79,6 +132,8 @@ impl BuffState { } } + /// Apply the given buff to the buff tracker for `value` steps + /// In the case of Inner Quiet, it inseads adds one to the stack counter pub fn apply(&mut self, buff: Buff, value: u8) { match buff { Buff::InnerQuiet => { @@ -100,6 +155,7 @@ impl BuffState { } } + /// Tick downs the remaining duration of all buffs, if up pub fn tick(&mut self) { if self.waste_not > 0 { self.waste_not -= 1; @@ -128,9 +184,14 @@ impl BuffState { } } +/// State the craft is in, used to keep track of wether the craft +/// is to be worked on, added to the success vector or discarded #[derive(Debug, Clone, Copy, PartialEq)] pub enum Success { + /// Pending success and therefor still ongoing Pending, + /// Finised, not ongoing and finished without breaking (Doens't take quality into account) Success, + /// Finised because of lack of remaining durability Failure, } diff --git a/tests/io.rs b/tests/io.rs new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/io.rs @@ -0,0 +1 @@ + diff --git a/tests/lib.rs b/tests/lib.rs new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/lib.rs @@ -0,0 +1 @@ +