From cce631261b4fe7b457972456dccdb4d88fc7d0b6 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Mon, 6 Mar 2023 15:34:11 +0100 Subject: [PATCH 01/14] Coverage(actions) - Adds coverage of actions.rs --- coverage/html/badges/flat.svg | 8 +-- coverage/html/badges/flat_square.svg | 6 +- coverage/html/badges/for_the_badge.svg | 6 +- coverage/html/badges/plastic.svg | 8 +-- coverage/html/badges/social.svg | 8 +-- src/action.rs | 93 ++++++++++++++++++++++++++ src/craft.rs | 36 +++++++++- 7 files changed, 145 insertions(+), 20 deletions(-) diff --git a/coverage/html/badges/flat.svg b/coverage/html/badges/flat.svg index d9147e7..6febf64 100644 --- a/coverage/html/badges/flat.svg +++ b/coverage/html/badges/flat.svg @@ -1,6 +1,6 @@ - coverage: 22% + xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="20" role="img" aria-label="coverage: 48%"> + coverage: 48% @@ -16,8 +16,8 @@ coverage - - 22% + + 48% \ No newline at end of file diff --git a/coverage/html/badges/flat_square.svg b/coverage/html/badges/flat_square.svg index 76037e6..9907885 100644 --- a/coverage/html/badges/flat_square.svg +++ b/coverage/html/badges/flat_square.svg @@ -1,13 +1,13 @@ - coverage: 22% + xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="20" role="img" aria-label="coverage: 48%"> + coverage: 48% coverage - 22% + 48% \ No newline at end of file diff --git a/coverage/html/badges/for_the_badge.svg b/coverage/html/badges/for_the_badge.svg index 53a73bc..7d6b58d 100644 --- a/coverage/html/badges/for_the_badge.svg +++ b/coverage/html/badges/for_the_badge.svg @@ -1,13 +1,13 @@ - COVERAGE: 22% + xmlns:xlink="http://www.w3.org/1999/xlink" width="142.5" height="28" role="img" aria-label="COVERAGE: 48%"> + COVERAGE: 48% COVERAGE - 22% + 48% \ No newline at end of file diff --git a/coverage/html/badges/plastic.svg b/coverage/html/badges/plastic.svg index 1296731..209f476 100644 --- a/coverage/html/badges/plastic.svg +++ b/coverage/html/badges/plastic.svg @@ -1,6 +1,6 @@ - coverage: 22% + xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="18" role="img" aria-label="coverage: 48%"> + coverage: 48% @@ -18,8 +18,8 @@ coverage - - 22% + + 48% \ No newline at end of file diff --git a/coverage/html/badges/social.svg b/coverage/html/badges/social.svg index 5dc8ab7..ccb1035 100644 --- a/coverage/html/badges/social.svg +++ b/coverage/html/badges/social.svg @@ -1,6 +1,6 @@ - Coverage: 22% + xmlns:xlink="http://www.w3.org/1999/xlink" width="99" height="20" role="img" aria-label="Coverage: 48%"> + Coverage: 48% @@ -20,8 +20,8 @@ Coverage - - 22% + + 48% \ No newline at end of file diff --git a/src/action.rs b/src/action.rs index 89f16bb..9ff889f 100644 --- a/src/action.rs +++ b/src/action.rs @@ -454,3 +454,96 @@ lazy_static! { /// Initialize a static pseudo &Craft: ACTIONS pub static ref ACTIONS: ActionList = ActionList::default(); } + +#[cfg(test)] +mod test { + use crate::action::ACTIONS; + use pretty_assertions::assert_eq; + use strum::IntoEnumIterator; + #[test] + pub fn test_structs() { + let ac = crate::action::Action { + name: "Michel".to_string(), + dur: 0, + cp: 0, + progress: 0, + quality: 0, + buff: None, + short_name: "miguel".to_string(), + }; + let ab = crate::action::ActionBuilder { action: ac }; + let ba = crate::action::ActionBuilder::new(&"Basic Synthesis"); + let _ = crate::action::ActionBuilder::new(&"Groundwork"); + let cs = crate::action::ActionBuilder::new(&"Careful Synthesis"); + ab.dur(10) + .cp(10) + .progress(10) + .quality(10) + .buff(None) + .build(); + let act1 = ba.cp(10).dur(22).progress(33).quality(44).build(); + let act2 = cs.cp(10).dur(22).progress(33).quality(44).build(); + assert_eq!(act1, act2); + format!("{:?}", act1); + let _ = crate::action::ActionList::default(); + } + + #[test] + pub fn test_with_craft() { + let mut bbs = crate::specs::BuffState::default(); + for buff in crate::specs::Buff::iter() { + bbs.apply(buff, 2); + } + let mut act1 = crate::action::ActionBuilder::new(&"Basic Synthesis") + .dur(22) + .cp(10) + .progress(100) + .quality(100) + .build(); + let mut craft = crate::craft::Craft::default(); + craft.buffs = bbs; + + assert_eq!(act1.get_name(), "Basic Synthesis"); + assert_eq!(act1.get_cp_cost(&craft), 10); + assert_eq!(act1.get_durability_cost(&craft), 11); + assert_eq!(act1.get_progress(&craft), 250); + assert_eq!(act1.get_quality(&craft), 300); + assert_eq!(act1.get_buff(), None); + + assert!(act1.can_use(&craft)); + + assert_eq!(&ACTIONS.standard_touch.get_cp_cost(&craft), &18); + assert_eq!(&ACTIONS.advanced_touch.get_cp_cost(&craft), &18); + assert_eq!(&ACTIONS.masters_mend.get_durability_cost(&craft), &30); + + assert_eq!(&ACTIONS.byregot_blessing.get_quality(&craft), &420); + assert_eq!(&ACTIONS.byregot_blessing.can_use(&craft), &true); + assert_eq!(&ACTIONS.muscle_memory.can_use(&craft), &true); + assert_eq!(&ACTIONS.trained_finesse.can_use(&craft), &false); + assert_eq!(&ACTIONS.reflect.can_use(&craft), &true); + + act1.progress = 0; + act1.quality = 0; + assert_eq!(act1.get_durability_cost(&craft), 0); + act1.dur = 0; + act1.progress = 100; + act1.quality = 100; + assert_eq!(act1.get_durability_cost(&craft), 0); + + act1.dur = 20; + craft.durability = 10; + craft.buffs = crate::specs::BuffState::default(); + assert_eq!(act1.get_progress(&craft), 50); + assert_eq!(act1.get_quality(&craft), 50); + + act1.dur = 2; + assert_eq!(act1.get_durability_cost(&craft), 5); + + craft.cp = 0; + assert_eq!(&ACTIONS.reflect.can_use(&craft), &false); + + craft.cp = 100; + craft.success = crate::specs::Success::Failure; + assert_eq!(&ACTIONS.reflect.can_use(&craft), &false); + } +} diff --git a/src/craft.rs b/src/craft.rs index 863fa66..2a43a4d 100644 --- a/src/craft.rs +++ b/src/craft.rs @@ -42,7 +42,6 @@ pub struct Craft<'a> { 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, @@ -184,9 +183,42 @@ impl<'a> Display for Craft<'a> { } } +#[cfg(test)] +impl<'a> Craft<'a> { + /// Create a "Default" craft, testing only + pub fn default() -> Craft<'a> { + Self::new( + crate::specs::Recipe { + durability: 200, + progress: 200, + progress_divider: 100, + progress_modifier: 100, + quality: 100, + quality_divider: 100, + quality_modifier: 100, + }, + crate::specs::Stats { + craftsmanship: 200, + control: 200, + max_cp: 200, + }, + crate::io::Parameters { + threads: 10, + verbose: 2, + depth: 10, + desperate: false, + byregot_step: 10, + }, + ) + } +} + #[cfg(test)] mod test { + // use pretty_assertions::assert_eq; // Struct Test #[test] - pub fn struct_tests() {} + pub fn struct_tests() { + let _craft = crate::craft::Craft::default(); + } } -- 2.45.1 From d5ff22d026aa00171322dc5ed0abbc05bed3d8a1 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Tue, 7 Mar 2023 06:23:33 +0100 Subject: [PATCH 02/14] Build(Tests) - Cleanup of the test harness --- Cargo.toml | 8 +++++--- Makefile.toml | 2 +- coverage/html/badges/flat.svg | 8 ++++---- coverage/html/badges/flat_square.svg | 6 +++--- coverage/html/badges/for_the_badge.svg | 6 +++--- coverage/html/badges/plastic.svg | 8 ++++---- coverage/html/badges/social.svg | 8 ++++---- pyproject.toml | 5 ++++- 8 files changed, 28 insertions(+), 23 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e3e6c0e..f0d1f67 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ toml = "0.5.9" clap = {version = "4.1.6", features = ["derive"]} threadpool = "1.8.1" # For python bindings TODO: make it optionnal -pyo3 = { version = "0.18.0", features = ["extension-module"] } +pyo3 = { version = "0.18.1", features= ["extension-module"]} # [target.'cfg(not(no_python))'.dependencies] # pyo3 = { version = "0.18.0", features = ["extension-module"] } @@ -36,7 +36,8 @@ opt-level = 3 lto = true [features] -default = [] +extension-module = ["pyo3/extension-module"] +default = ["extension-module"] verbose = [] no_python = [] # Removes the python bindings fast = [] # Remove some under optimisations that try to find other routes @@ -48,4 +49,5 @@ crate-type = ["cdylib","rlib"] [[bin]] name = "xiv_csolver_cli" -path = "src/bin/xiv_csolver.rs" \ No newline at end of file +path = "src/bin/xiv_csolver.rs" + diff --git a/Makefile.toml b/Makefile.toml index cf4c53b..b9d99a1 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -29,7 +29,7 @@ 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", +"CARGO_INCREMENTAL=0 RUSTFLAGS='-Cinstrument-coverage -Ccodegen-units=1 -Copt-level=0 -Coverflow-checks=off' 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/" ] diff --git a/coverage/html/badges/flat.svg b/coverage/html/badges/flat.svg index 6febf64..4c9dba0 100644 --- a/coverage/html/badges/flat.svg +++ b/coverage/html/badges/flat.svg @@ -1,6 +1,6 @@ - coverage: 48% + xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="20" role="img" aria-label="coverage: 56%"> + coverage: 56% @@ -16,8 +16,8 @@ coverage - - 48% + + 56% \ No newline at end of file diff --git a/coverage/html/badges/flat_square.svg b/coverage/html/badges/flat_square.svg index 9907885..efc26f9 100644 --- a/coverage/html/badges/flat_square.svg +++ b/coverage/html/badges/flat_square.svg @@ -1,13 +1,13 @@ - coverage: 48% + xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="20" role="img" aria-label="coverage: 56%"> + coverage: 56% coverage - 48% + 56% \ No newline at end of file diff --git a/coverage/html/badges/for_the_badge.svg b/coverage/html/badges/for_the_badge.svg index 7d6b58d..0956090 100644 --- a/coverage/html/badges/for_the_badge.svg +++ b/coverage/html/badges/for_the_badge.svg @@ -1,13 +1,13 @@ - COVERAGE: 48% + xmlns:xlink="http://www.w3.org/1999/xlink" width="142.5" height="28" role="img" aria-label="COVERAGE: 56%"> + COVERAGE: 56% COVERAGE - 48% + 56% \ No newline at end of file diff --git a/coverage/html/badges/plastic.svg b/coverage/html/badges/plastic.svg index 209f476..16fde0e 100644 --- a/coverage/html/badges/plastic.svg +++ b/coverage/html/badges/plastic.svg @@ -1,6 +1,6 @@ - coverage: 48% + xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="18" role="img" aria-label="coverage: 56%"> + coverage: 56% @@ -18,8 +18,8 @@ coverage - - 48% + + 56% \ No newline at end of file diff --git a/coverage/html/badges/social.svg b/coverage/html/badges/social.svg index ccb1035..f5e0951 100644 --- a/coverage/html/badges/social.svg +++ b/coverage/html/badges/social.svg @@ -1,6 +1,6 @@ - Coverage: 48% + xmlns:xlink="http://www.w3.org/1999/xlink" width="99" height="20" role="img" aria-label="Coverage: 56%"> + Coverage: 56% @@ -20,8 +20,8 @@ Coverage - - 48% + + 56% \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 5c2868e..19a619f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,4 +10,7 @@ classifiers = [ "Programming Language :: Rust", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", -] \ No newline at end of file +] + +[tool.maturin] +features = ["pyo3/extension-module"] \ No newline at end of file -- 2.45.1 From ee24bdd0af3f4f149223345504bb4cf25214e562 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Tue, 7 Mar 2023 06:24:22 +0100 Subject: [PATCH 03/14] Tests(Multiple) - Updates multiple test units --- README.md | 2 +- rustfmt.toml | 1 + src/action.rs | 10 ++++++---- src/bin/xiv_csolver.rs | 2 +- src/craft.rs | 42 ++++++++++++++++++++++++++++++++++++++++-- src/io.rs | 22 +++++++++++++++++++++- src/solver.rs | 4 ++++ 7 files changed, 74 insertions(+), 9 deletions(-) create mode 100644 rustfmt.toml diff --git a/README.md b/README.md index fb2e1c4..0a64ce8 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Originaly written by [RikaKagurasaka](https://github.com/RikaKagurasaka/xiv_craf 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) +![coverage/html/badges/plastic.svg](coverage/html/badges/flat.svg) ### Basic RUST CLI Usage Everything is done through the regular cargo interface diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..4e727a0 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1 @@ +reorder_imports = true \ No newline at end of file diff --git a/src/action.rs b/src/action.rs index 9ff889f..fe4d716 100644 --- a/src/action.rs +++ b/src/action.rs @@ -145,9 +145,10 @@ impl Action { } /// 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 { + /// Note that not using i32 for durability from scratch is a desing choice + pub fn get_durability_cost(&self, _craft: &Craft) -> i32 { if self == &ACTIONS.masters_mend { - return 30; + return -30; } if self.dur == 0 || self.progress == 0 && self.quality == 0 { return 0; @@ -159,7 +160,7 @@ impl Action { if dur < 5 { dur = 5; } - dur + dur as i32 } /// 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, @@ -419,6 +420,7 @@ impl Default for ActionList { .build(), masters_mend: ActionBuilder::new("Master's Mend").cp(88).build(), + //masters_mend: ActionBuilder::new("Master's Mend").dur(-30).cp(88).build(), waste_not: ActionBuilder::new("Waste Not") .cp(56) .buff(Some((Buff::WasteNot, 4))) @@ -514,7 +516,7 @@ mod test { assert_eq!(&ACTIONS.standard_touch.get_cp_cost(&craft), &18); assert_eq!(&ACTIONS.advanced_touch.get_cp_cost(&craft), &18); - assert_eq!(&ACTIONS.masters_mend.get_durability_cost(&craft), &30); + assert_eq!(&ACTIONS.masters_mend.get_durability_cost(&craft), &-30); assert_eq!(&ACTIONS.byregot_blessing.get_quality(&craft), &420); assert_eq!(&ACTIONS.byregot_blessing.can_use(&craft), &true); diff --git a/src/bin/xiv_csolver.rs b/src/bin/xiv_csolver.rs index c94c690..9549faf 100644 --- a/src/bin/xiv_csolver.rs +++ b/src/bin/xiv_csolver.rs @@ -30,7 +30,7 @@ //! //! 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. +//! All bindings and the explanation of how to use them can be found in the [`io`](xiv_csolver_lib::io) module. //! //! ### Features //! diff --git a/src/craft.rs b/src/craft.rs index 2a43a4d..777e696 100644 --- a/src/craft.rs +++ b/src/craft.rs @@ -215,10 +215,48 @@ impl<'a> Craft<'a> { #[cfg(test)] mod test { - // use pretty_assertions::assert_eq; + use pretty_assertions::assert_eq; // Struct Test #[test] pub fn struct_tests() { - let _craft = crate::craft::Craft::default(); + let craft = crate::craft::Craft::default().clone(); + assert_eq!(craft.get_base_progression(), 22); + assert_eq!(craft.get_base_quality(), 55); + + format!("{}", craft); + format!("{:?}", craft); + } + + #[test] + pub fn test_craft() { + let mut craft = crate::craft::Craft::default(); + craft.cp = 1000; + format!("{:?}", craft); + let mut craft2 = craft.run_action(&crate::action::ACTIONS.veneration).clone(); + + craft.run_action(&crate::action::ACTIONS.masters_mend); + craft.run_action(&crate::action::ACTIONS.masters_mend); + craft.run_action(&crate::action::ACTIONS.manipulation); + craft.run_action(&crate::action::ACTIONS.basic_touch); + craft.run_action(&crate::action::ACTIONS.basic_synthesis); + assert_eq!(craft.durability, 190); + craft.run_action(&crate::action::ACTIONS.masters_mend); + assert_eq!(craft.durability, 200); + craft.run_action(&crate::action::ACTIONS.masters_mend); + for _ in 0..10 { + craft.run_action(&crate::action::ACTIONS.basic_touch); + } + + for _ in 0..3 { + craft.run_action(&crate::action::ACTIONS.masters_mend); + craft.run_action(&crate::action::ACTIONS.groundwork); + } + assert_eq!(craft.success, crate::craft::Success::Success); + + for _ in 0..20 { + craft2.run_action(&crate::action::ACTIONS.preparatory_touch); + } + assert_eq!(craft2.durability, 0); + assert_eq!(craft2.success, crate::craft::Success::Failure); } } diff --git a/src/io.rs b/src/io.rs index 4c6e038..c9bd331 100644 --- a/src/io.rs +++ b/src/io.rs @@ -235,7 +235,26 @@ fn xiv_csolver_lib(_py: Python, m: &PyModule) -> PyResult<()> { Ok(()) } -/// +/// A test result, useful for debugging, all values are set to zero as per the +/// [`default`](crate::io::SolverResult::default) +/// ``` +/// # use xiv_csolver_lib::io::SolverResult; +/// SolverResult{ +/// steps: 0, +/// progression: 0, +/// quality: 0, +/// durability: 0, +/// total_progression: 0, +/// total_quality: 0, +/// total_durability: 0, +/// actions: vec!["Act1".to_string(), "Act2".to_string()], +/// step1_solutions: 0, +/// step2_solutions: 0, +/// found_100_percent: false, +/// cp: 0, +/// total_cp: 0, +/// }; +/// ``` #[cfg(not(feature = "no_python"))] #[pyfunction] pub fn test_result() -> SolverResult { @@ -273,6 +292,7 @@ use crate::{solve_craft, Recipe, Stats}; /// crafting_feeder = FeedingClass() /// rich.inspect(xiv_csolver_lib.solve_from_python(crafting_feeder)) /// ``` + #[cfg(not(feature = "no_python"))] #[pyfunction] pub fn solve_from_python(py: Python<'_>, values: &PyAny) -> PyResult>> { diff --git a/src/solver.rs b/src/solver.rs index 6a2e35f..d16af34 100644 --- a/src/solver.rs +++ b/src/solver.rs @@ -61,6 +61,7 @@ pub fn next_action_picker_1<'a>(craft: &Craft<'a>) -> Vec> { // ACTIONS.groundwork for the --pls if craft.args.desperate { available_actions.append(&mut action_vec![ACTIONS.groundwork]); + available_actions.append(&mut action_vec![ACTIONS.masters_mend]); } // For long first run @@ -191,6 +192,9 @@ pub fn next_action_phase_2<'a>(craft: &Craft<'a>) -> Vec> { available_actions.push(&ACTIONS.byregot_blessing); } } + // if craft.durability + 30 < craft.recipe.durability as i32{ + // available_actions.push(&ACTIONS.masters_mend); + // } let mut final_actions: Vec> = Vec::new(); for action in available_actions { -- 2.45.1 From fc5cce934acd196267de3cc16285c34799a79cc6 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Tue, 7 Mar 2023 06:48:35 +0100 Subject: [PATCH 04/14] Reformat(All) - Reformats the code --- Makefile.toml | 9 +++++---- rustfmt.toml | 2 +- src/action.rs | 9 ++++----- src/craft.rs | 1 - src/io.rs | 22 +++++++++++----------- src/solver.rs | 4 ++-- 6 files changed, 23 insertions(+), 24 deletions(-) diff --git a/Makefile.toml b/Makefile.toml index b9d99a1..92956fa 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -18,10 +18,11 @@ script = [ "twine upload releases/xiv_csolver_lib*.whl --repository gitea", ] -[tasks.format] -install_crate = "rustfmt" -command = "cargo" -args = ["fmt", "--", "--emit=files"] +[tasks.fmt] +script_runner = "@shell" +script = [ +"cargo +nightly fmt -- --config format_code_in_doc_comments=true" +] [tasks.testcov] script_runner = "@shell" diff --git a/rustfmt.toml b/rustfmt.toml index 4e727a0..44148a2 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1 +1 @@ -reorder_imports = true \ No newline at end of file +reorder_imports = true diff --git a/src/action.rs b/src/action.rs index fe4d716..0ae718d 100644 --- a/src/action.rs +++ b/src/action.rs @@ -2,7 +2,6 @@ //! //! 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}; @@ -45,10 +44,10 @@ impl ActionBuilder { /// 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(); + /// .cp(6) + /// .progress(300) + /// .buff(Some((Buff::MuscleMemory, 5))) + /// .build(); /// ``` pub fn new(name: &str) -> Self { let mut short_name = name.to_string(); diff --git a/src/craft.rs b/src/craft.rs index 777e696..cbffb01 100644 --- a/src/craft.rs +++ b/src/craft.rs @@ -3,7 +3,6 @@ //! 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}; diff --git a/src/io.rs b/src/io.rs index c9bd331..e4214b7 100644 --- a/src/io.rs +++ b/src/io.rs @@ -239,21 +239,21 @@ fn xiv_csolver_lib(_py: Python, m: &PyModule) -> PyResult<()> { /// [`default`](crate::io::SolverResult::default) /// ``` /// # use xiv_csolver_lib::io::SolverResult; -/// SolverResult{ +/// SolverResult { /// steps: 0, /// progression: 0, /// quality: 0, /// durability: 0, -/// total_progression: 0, -/// total_quality: 0, -/// total_durability: 0, -/// actions: vec!["Act1".to_string(), "Act2".to_string()], -/// step1_solutions: 0, -/// step2_solutions: 0, -/// found_100_percent: false, -/// cp: 0, -/// total_cp: 0, -/// }; +/// total_progression: 0, +/// total_quality: 0, +/// total_durability: 0, +/// actions: vec!["Act1".to_string(), "Act2".to_string()], +/// step1_solutions: 0, +/// step2_solutions: 0, +/// found_100_percent: false, +/// cp: 0, +/// total_cp: 0, +/// }; /// ``` #[cfg(not(feature = "no_python"))] #[pyfunction] diff --git a/src/solver.rs b/src/solver.rs index d16af34..3ed2fe6 100644 --- a/src/solver.rs +++ b/src/solver.rs @@ -26,11 +26,11 @@ pub fn next_action_picker_1<'a>(craft: &Craft<'a>) -> Vec> { // Prune some actions if not requested by --long if craft.step_count == 2 { - return action_vec![/*ACTIONS.waste_not, ACTIONS.waste_not_ii, */ ACTIONS.veneration]; + return action_vec![/* ACTIONS.waste_not, ACTIONS.waste_not_ii, */ ACTIONS.veneration]; } if craft.step_count == 3 { available_actions.append(&mut action_vec![ - ACTIONS.waste_not_ii /*,ACTIONS.waste_not*/ + ACTIONS.waste_not_ii /* ,ACTIONS.waste_not */ ]) } -- 2.45.1 From 539a14a4fc795f90e3f7e93217b86872d4bf238c Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Tue, 7 Mar 2023 07:58:12 +0100 Subject: [PATCH 05/14] Coverage(Solver) - Puts solver at 76% coverage --- Makefile.toml | 2 +- coverage/html/badges/flat.svg | 8 +- coverage/html/badges/flat_square.svg | 6 +- coverage/html/badges/for_the_badge.svg | 6 +- coverage/html/badges/plastic.svg | 8 +- coverage/html/badges/social.svg | 8 +- src/craft.rs | 27 +++ src/lib.rs | 9 +- src/solver.rs | 255 ++++++++++++++++++++++++- 9 files changed, 302 insertions(+), 27 deletions(-) diff --git a/Makefile.toml b/Makefile.toml index 92956fa..72dcc22 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -21,7 +21,7 @@ script = [ [tasks.fmt] script_runner = "@shell" script = [ -"cargo +nightly fmt -- --config format_code_in_doc_comments=true" +"cargo +nightly fmt -- --config format_code_in_doc_comments=true --config imports_granularity=Module" ] [tasks.testcov] diff --git a/coverage/html/badges/flat.svg b/coverage/html/badges/flat.svg index 4c9dba0..cbcfb5c 100644 --- a/coverage/html/badges/flat.svg +++ b/coverage/html/badges/flat.svg @@ -1,6 +1,6 @@ - coverage: 56% + xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="20" role="img" aria-label="coverage: 69%"> + coverage: 69% @@ -16,8 +16,8 @@ coverage - - 56% + + 69% \ No newline at end of file diff --git a/coverage/html/badges/flat_square.svg b/coverage/html/badges/flat_square.svg index efc26f9..36d4829 100644 --- a/coverage/html/badges/flat_square.svg +++ b/coverage/html/badges/flat_square.svg @@ -1,13 +1,13 @@ - coverage: 56% + xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="20" role="img" aria-label="coverage: 69%"> + coverage: 69% coverage - 56% + 69% \ No newline at end of file diff --git a/coverage/html/badges/for_the_badge.svg b/coverage/html/badges/for_the_badge.svg index 0956090..0cfc978 100644 --- a/coverage/html/badges/for_the_badge.svg +++ b/coverage/html/badges/for_the_badge.svg @@ -1,13 +1,13 @@ - COVERAGE: 56% + xmlns:xlink="http://www.w3.org/1999/xlink" width="142.5" height="28" role="img" aria-label="COVERAGE: 69%"> + COVERAGE: 69% COVERAGE - 56% + 69% \ No newline at end of file diff --git a/coverage/html/badges/plastic.svg b/coverage/html/badges/plastic.svg index 16fde0e..68d3549 100644 --- a/coverage/html/badges/plastic.svg +++ b/coverage/html/badges/plastic.svg @@ -1,6 +1,6 @@ - coverage: 56% + xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="18" role="img" aria-label="coverage: 69%"> + coverage: 69% @@ -18,8 +18,8 @@ coverage - - 56% + + 69% \ No newline at end of file diff --git a/coverage/html/badges/social.svg b/coverage/html/badges/social.svg index f5e0951..45c8c46 100644 --- a/coverage/html/badges/social.svg +++ b/coverage/html/badges/social.svg @@ -1,6 +1,6 @@ - Coverage: 56% + xmlns:xlink="http://www.w3.org/1999/xlink" width="99" height="20" role="img" aria-label="Coverage: 69%"> + Coverage: 69% @@ -20,8 +20,8 @@ Coverage - - 56% + + 69% \ No newline at end of file diff --git a/src/craft.rs b/src/craft.rs index cbffb01..9f4cd95 100644 --- a/src/craft.rs +++ b/src/craft.rs @@ -210,6 +210,33 @@ impl<'a> Craft<'a> { }, ) } + + /// Create a "Three start" craft, testing only + pub fn three_star() -> Craft<'a> { + Self::new( + crate::specs::Recipe { + durability: 70, + progress: 3900, + quality: 10920, + progress_divider: 130, + quality_divider: 115, + progress_modifier: 80, + quality_modifier: 70, + }, + crate::specs::Stats { + craftsmanship: 4041, + control: 3971, + max_cp: 595, + }, + crate::io::Parameters { + threads: 8, + verbose: 2, + depth: 8, + desperate: false, + byregot_step: 10, + }, + ) + } } #[cfg(test)] diff --git a/src/lib.rs b/src/lib.rs index 96c4de4..b83a71f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -96,12 +96,9 @@ #![warn(missing_docs)] -use crate::io::SolverResult; -use crate::{ - craft::Craft, - io::Parameters, - specs::{Recipe, Stats}, -}; +use crate::craft::Craft; +use crate::io::{Parameters, SolverResult}; +use crate::specs::{Recipe, Stats}; use std::sync::{Arc, Mutex}; use threadpool::ThreadPool; diff --git a/src/solver.rs b/src/solver.rs index 3ed2fe6..bbce062 100644 --- a/src/solver.rs +++ b/src/solver.rs @@ -16,7 +16,7 @@ pub fn next_action_picker_1<'a>(craft: &Craft<'a>) -> Vec> { let mut available_actions = Vec::>::new(); let mut forbidden_actions = Vec::>::new(); - // Optimize the first three steps for massive time save + // Optimize the first four steps for massive time save if craft.step_count == 0 { return action_vec![ACTIONS.muscle_memory]; } @@ -65,7 +65,7 @@ pub fn next_action_picker_1<'a>(craft: &Craft<'a>) -> Vec> { } // For long first run - if craft.step_count > 8 { + if craft.step_count > 8 && craft.buffs.waste_not == 0 { available_actions.append(&mut action_vec![ACTIONS.waste_not_ii, ACTIONS.waste_not]) }; @@ -246,3 +246,254 @@ pub fn generate_routes_phase2<'a>(craft: Craft<'a>) -> Option>> { top_routes.push(top_route); Some(top_routes) } + +#[cfg(test)] +mod test { + use crate::solver::{generate_routes_phase1, next_action_picker_1, ACTIONS}; + + #[test] + pub fn test_first_step() { + let mut craft = crate::craft::Craft::three_star(); + // Try a failed craft + craft.success = crate::specs::Success::Failure; + let vact = next_action_picker_1(&craft); + assert_eq!(vact, vec![None]); + craft.success = crate::specs::Success::Pending; + + // Try the first 4 steps + let vact = next_action_picker_1(&craft); + assert_eq!(vact, action_vec![ACTIONS.muscle_memory]); + craft.run_action(&ACTIONS.muscle_memory); + + let vact = next_action_picker_1(&craft); + assert_eq!(vact, action_vec![ACTIONS.manipulation]); + craft.run_action(&ACTIONS.manipulation); + + let vact = next_action_picker_1(&craft); + assert_eq!(vact, action_vec![ACTIONS.veneration]); + craft.run_action(&ACTIONS.veneration); + + let vact = next_action_picker_1(&craft); + assert_eq!(vact, action_vec![ACTIONS.waste_not_ii, ACTIONS.groundwork]); + craft.run_action(&ACTIONS.waste_not_ii); + + // Try the steps 5-8, deterministically + let vact = next_action_picker_1(&craft); + assert_eq!(vact, action_vec![ACTIONS.groundwork]); + craft.run_action(&ACTIONS.careful_synthesis); + + let vact = next_action_picker_1(&craft); + assert_eq!( + vact, + action_vec![ + ACTIONS.groundwork, + ACTIONS.basic_synthesis, + ACTIONS.careful_synthesis, + ACTIONS.delicate_synthesis + ] + ); + craft.run_action(&ACTIONS.careful_synthesis); + + let vact = next_action_picker_1(&craft); + assert_eq!( + vact, + action_vec![ + ACTIONS.groundwork, + ACTIONS.basic_synthesis, + ACTIONS.careful_synthesis, + ACTIONS.delicate_synthesis + ] + ); + craft.run_action(&ACTIONS.careful_synthesis); + + let vact = next_action_picker_1(&craft); + assert_eq!( + vact, + action_vec![ + ACTIONS.groundwork, + ACTIONS.basic_synthesis, + ACTIONS.careful_synthesis, + ACTIONS.delicate_synthesis + ] + ); + craft.run_action(&ACTIONS.careful_synthesis); + + // Check odd parameters + craft.buffs.waste_not = 0; + craft.progression = 0; + let vact = next_action_picker_1(&craft); + assert_eq!( + vact, + action_vec![ + ACTIONS.basic_synthesis, + ACTIONS.careful_synthesis, + ACTIONS.prudent_synthesis, + ACTIONS.delicate_synthesis + ] + ); + craft.run_action(&ACTIONS.delicate_synthesis); + + let vact = next_action_picker_1(&craft); + assert_eq!( + vact, + action_vec![ + ACTIONS.basic_synthesis, + ACTIONS.careful_synthesis, + ACTIONS.prudent_synthesis, + ACTIONS.delicate_synthesis, + ACTIONS.waste_not_ii, + ACTIONS.waste_not + ] + ); + + craft.args.desperate = true; + let vact = next_action_picker_1(&craft); + assert_eq!( + vact, + action_vec![ + ACTIONS.basic_synthesis, + ACTIONS.careful_synthesis, + ACTIONS.prudent_synthesis, + ACTIONS.delicate_synthesis, + ACTIONS.groundwork, + ACTIONS.masters_mend, + ACTIONS.waste_not_ii, + ACTIONS.waste_not + ] + ); + } + + #[test] + pub fn test_routes_p1() { + let craft = crate::craft::Craft::three_star(); + let mut routes1 = generate_routes_phase1(craft); + + for route in routes1.iter() { + println!("{:?}", route.actions); + } + // Literrally any change will break it + // An eq should be implmented to just check a vector of vector versus a route + assert_eq!(routes1.len(), 9); + let route = routes1.pop().unwrap(); + assert_eq!( + route.actions, + vec![ + &ACTIONS.muscle_memory, + &ACTIONS.manipulation, + &ACTIONS.veneration, + &ACTIONS.waste_not_ii, + &ACTIONS.groundwork, + &ACTIONS.delicate_synthesis, + &ACTIONS.delicate_synthesis + ] + ); + + let route = routes1.pop().unwrap(); + assert_eq!( + route.actions, + vec![ + &ACTIONS.muscle_memory, + &ACTIONS.manipulation, + &ACTIONS.veneration, + &ACTIONS.waste_not_ii, + &ACTIONS.groundwork, + &ACTIONS.delicate_synthesis, + &ACTIONS.basic_synthesis, + ] + ); + + let route = routes1.pop().unwrap(); + assert_eq!( + route.actions, + vec![ + &ACTIONS.muscle_memory, + &ACTIONS.manipulation, + &ACTIONS.veneration, + &ACTIONS.waste_not_ii, + &ACTIONS.groundwork, + &ACTIONS.careful_synthesis + ] + ); + + let route = routes1.pop().unwrap(); + assert_eq!( + route.actions, + vec![ + &ACTIONS.muscle_memory, + &ACTIONS.manipulation, + &ACTIONS.veneration, + &ACTIONS.waste_not_ii, + &ACTIONS.groundwork, + &ACTIONS.basic_synthesis + ] + ); + + let route = routes1.pop().unwrap(); + assert_eq!( + route.actions, + vec![ + &ACTIONS.muscle_memory, + &ACTIONS.manipulation, + &ACTIONS.veneration, + &ACTIONS.groundwork, + &ACTIONS.delicate_synthesis, + &ACTIONS.delicate_synthesis + ] + ); + + let route = routes1.pop().unwrap(); + assert_eq!( + route.actions, + vec![ + &ACTIONS.muscle_memory, + &ACTIONS.manipulation, + &ACTIONS.veneration, + &ACTIONS.groundwork, + &ACTIONS.delicate_synthesis, + &ACTIONS.basic_synthesis + ] + ); + + let route = routes1.pop().unwrap(); + assert_eq!( + route.actions, + vec![ + &ACTIONS.muscle_memory, + &ACTIONS.manipulation, + &ACTIONS.veneration, + &ACTIONS.groundwork, + &ACTIONS.prudent_synthesis + ] + ); + + let route = routes1.pop().unwrap(); + assert_eq!( + route.actions, + vec![ + &ACTIONS.muscle_memory, + &ACTIONS.manipulation, + &ACTIONS.veneration, + &ACTIONS.groundwork, + &ACTIONS.careful_synthesis + ] + ); + + let route = routes1.pop().unwrap(); + assert_eq!( + route.actions, + vec![ + &ACTIONS.muscle_memory, + &ACTIONS.manipulation, + &ACTIONS.veneration, + &ACTIONS.groundwork, + &ACTIONS.basic_synthesis + ] + ); + + let route = routes1.pop(); + match route { + None => (), + Some(..) => panic!(), + } + } +} -- 2.45.1 From 406bc0e515f5fc5a4cce01bca27b5843c09b5361 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Wed, 8 Mar 2023 06:14:17 +0100 Subject: [PATCH 06/14] Test(Coverage) - Adds solver coverage and fixes tests/ folder being there --- coverage/html/badges/flat.svg | 10 +- coverage/html/badges/flat_square.svg | 8 +- coverage/html/badges/for_the_badge.svg | 8 +- coverage/html/badges/plastic.svg | 10 +- coverage/html/badges/social.svg | 8 +- src/craft.rs | 37 ++- src/solver.rs | 258 +--------------- src/solver/test_solver.rs | 391 +++++++++++++++++++++++++ tests/io.rs | 1 - tests/lib.rs | 1 - 10 files changed, 450 insertions(+), 282 deletions(-) create mode 100644 src/solver/test_solver.rs delete mode 100644 tests/io.rs delete mode 100644 tests/lib.rs diff --git a/coverage/html/badges/flat.svg b/coverage/html/badges/flat.svg index cbcfb5c..b482db6 100644 --- a/coverage/html/badges/flat.svg +++ b/coverage/html/badges/flat.svg @@ -1,6 +1,6 @@ - coverage: 69% + xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="20" role="img" aria-label="coverage: 77%"> + coverage: 77% @@ -10,14 +10,14 @@ - + coverage - - 69% + + 77% \ No newline at end of file diff --git a/coverage/html/badges/flat_square.svg b/coverage/html/badges/flat_square.svg index 36d4829..cc89b0d 100644 --- a/coverage/html/badges/flat_square.svg +++ b/coverage/html/badges/flat_square.svg @@ -1,13 +1,13 @@ - coverage: 69% + xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="20" role="img" aria-label="coverage: 77%"> + coverage: 77% - + coverage - 69% + 77% \ No newline at end of file diff --git a/coverage/html/badges/for_the_badge.svg b/coverage/html/badges/for_the_badge.svg index 0cfc978..427f757 100644 --- a/coverage/html/badges/for_the_badge.svg +++ b/coverage/html/badges/for_the_badge.svg @@ -1,13 +1,13 @@ - COVERAGE: 69% + xmlns:xlink="http://www.w3.org/1999/xlink" width="142.5" height="28" role="img" aria-label="COVERAGE: 77%"> + COVERAGE: 77% - + COVERAGE - 69% + 77% \ No newline at end of file diff --git a/coverage/html/badges/plastic.svg b/coverage/html/badges/plastic.svg index 68d3549..5900c59 100644 --- a/coverage/html/badges/plastic.svg +++ b/coverage/html/badges/plastic.svg @@ -1,6 +1,6 @@ - coverage: 69% + xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="18" role="img" aria-label="coverage: 77%"> + coverage: 77% @@ -12,14 +12,14 @@ - + coverage - - 69% + + 77% \ No newline at end of file diff --git a/coverage/html/badges/social.svg b/coverage/html/badges/social.svg index 45c8c46..8aeabdb 100644 --- a/coverage/html/badges/social.svg +++ b/coverage/html/badges/social.svg @@ -1,6 +1,6 @@ - Coverage: 69% + xmlns:xlink="http://www.w3.org/1999/xlink" width="99" height="20" role="img" aria-label="Coverage: 77%"> + Coverage: 77% @@ -20,8 +20,8 @@ Coverage - - 69% + + 77% \ No newline at end of file diff --git a/src/craft.rs b/src/craft.rs index 9f4cd95..f5788f3 100644 --- a/src/craft.rs +++ b/src/craft.rs @@ -211,8 +211,8 @@ impl<'a> Craft<'a> { ) } - /// Create a "Three start" craft, testing only - pub fn three_star() -> Craft<'a> { + /// Create a "Two start" craft, testing only + pub fn two_star() -> Craft<'a> { Self::new( crate::specs::Recipe { durability: 70, @@ -237,6 +237,33 @@ impl<'a> Craft<'a> { }, ) } + + /// Create a "Zero star" craft for debbuging & testing + pub fn zero_star() -> Craft<'a> { + Self::new( + crate::specs::Recipe { + durability: 70, + progress: 4000, + quality: 10920, + progress_divider: 100, + quality_divider: 100, + progress_modifier: 100, + quality_modifier: 100, + }, + crate::specs::Stats { + craftsmanship: 4000, + control: 4000, + max_cp: 600, + }, + crate::io::Parameters { + threads: 8, + verbose: 2, + depth: 8, + desperate: false, + byregot_step: 10, + }, + ) + } } #[cfg(test)] @@ -245,9 +272,9 @@ mod test { // Struct Test #[test] pub fn struct_tests() { - let craft = crate::craft::Craft::default().clone(); - assert_eq!(craft.get_base_progression(), 22); - assert_eq!(craft.get_base_quality(), 55); + let craft = crate::craft::Craft::zero_star().clone(); + assert_eq!(craft.get_base_progression(), 402); + assert_eq!(craft.get_base_quality(), 435); format!("{}", craft); format!("{:?}", craft); diff --git a/src/solver.rs b/src/solver.rs index bbce062..7c7d569 100644 --- a/src/solver.rs +++ b/src/solver.rs @@ -108,9 +108,10 @@ pub fn generate_routes_phase1<'a>(craft: Craft<'a>) -> Vec> { continue; } else if 0.0 < remaining_prog && remaining_prog <= 1.2 { // pass // Will finish with basicSynth2 (free) - } else if 1.2 < remaining_prog && remaining_prog <= 1.2 { - craft.cp -= 7; // Will finish with carefulSynthesis (7cp) - } else if 1.2 < remaining_prog && remaining_prog <= 2.0 { + // TODO: Test replacing this value with 1.8 that should be the correct value but hasnt be tested + // } else if 1.2 < remaining_prog && remaining_prog <= 1.4 { + // craft.cp -= 7; // Will finish with carefulSynthesis (7cp) + } else if 1.4 < remaining_prog && remaining_prog <= 2.0 { craft.cp -= 12; // Will finish with observe+focusedSynthesis (12cp) } craft.durability -= 10; // Save the final step, since we always aim to end with -5dur, it doesn't matter @@ -247,253 +248,4 @@ pub fn generate_routes_phase2<'a>(craft: Craft<'a>) -> Option>> { Some(top_routes) } -#[cfg(test)] -mod test { - use crate::solver::{generate_routes_phase1, next_action_picker_1, ACTIONS}; - - #[test] - pub fn test_first_step() { - let mut craft = crate::craft::Craft::three_star(); - // Try a failed craft - craft.success = crate::specs::Success::Failure; - let vact = next_action_picker_1(&craft); - assert_eq!(vact, vec![None]); - craft.success = crate::specs::Success::Pending; - - // Try the first 4 steps - let vact = next_action_picker_1(&craft); - assert_eq!(vact, action_vec![ACTIONS.muscle_memory]); - craft.run_action(&ACTIONS.muscle_memory); - - let vact = next_action_picker_1(&craft); - assert_eq!(vact, action_vec![ACTIONS.manipulation]); - craft.run_action(&ACTIONS.manipulation); - - let vact = next_action_picker_1(&craft); - assert_eq!(vact, action_vec![ACTIONS.veneration]); - craft.run_action(&ACTIONS.veneration); - - let vact = next_action_picker_1(&craft); - assert_eq!(vact, action_vec![ACTIONS.waste_not_ii, ACTIONS.groundwork]); - craft.run_action(&ACTIONS.waste_not_ii); - - // Try the steps 5-8, deterministically - let vact = next_action_picker_1(&craft); - assert_eq!(vact, action_vec![ACTIONS.groundwork]); - craft.run_action(&ACTIONS.careful_synthesis); - - let vact = next_action_picker_1(&craft); - assert_eq!( - vact, - action_vec![ - ACTIONS.groundwork, - ACTIONS.basic_synthesis, - ACTIONS.careful_synthesis, - ACTIONS.delicate_synthesis - ] - ); - craft.run_action(&ACTIONS.careful_synthesis); - - let vact = next_action_picker_1(&craft); - assert_eq!( - vact, - action_vec![ - ACTIONS.groundwork, - ACTIONS.basic_synthesis, - ACTIONS.careful_synthesis, - ACTIONS.delicate_synthesis - ] - ); - craft.run_action(&ACTIONS.careful_synthesis); - - let vact = next_action_picker_1(&craft); - assert_eq!( - vact, - action_vec![ - ACTIONS.groundwork, - ACTIONS.basic_synthesis, - ACTIONS.careful_synthesis, - ACTIONS.delicate_synthesis - ] - ); - craft.run_action(&ACTIONS.careful_synthesis); - - // Check odd parameters - craft.buffs.waste_not = 0; - craft.progression = 0; - let vact = next_action_picker_1(&craft); - assert_eq!( - vact, - action_vec![ - ACTIONS.basic_synthesis, - ACTIONS.careful_synthesis, - ACTIONS.prudent_synthesis, - ACTIONS.delicate_synthesis - ] - ); - craft.run_action(&ACTIONS.delicate_synthesis); - - let vact = next_action_picker_1(&craft); - assert_eq!( - vact, - action_vec![ - ACTIONS.basic_synthesis, - ACTIONS.careful_synthesis, - ACTIONS.prudent_synthesis, - ACTIONS.delicate_synthesis, - ACTIONS.waste_not_ii, - ACTIONS.waste_not - ] - ); - - craft.args.desperate = true; - let vact = next_action_picker_1(&craft); - assert_eq!( - vact, - action_vec![ - ACTIONS.basic_synthesis, - ACTIONS.careful_synthesis, - ACTIONS.prudent_synthesis, - ACTIONS.delicate_synthesis, - ACTIONS.groundwork, - ACTIONS.masters_mend, - ACTIONS.waste_not_ii, - ACTIONS.waste_not - ] - ); - } - - #[test] - pub fn test_routes_p1() { - let craft = crate::craft::Craft::three_star(); - let mut routes1 = generate_routes_phase1(craft); - - for route in routes1.iter() { - println!("{:?}", route.actions); - } - // Literrally any change will break it - // An eq should be implmented to just check a vector of vector versus a route - assert_eq!(routes1.len(), 9); - let route = routes1.pop().unwrap(); - assert_eq!( - route.actions, - vec![ - &ACTIONS.muscle_memory, - &ACTIONS.manipulation, - &ACTIONS.veneration, - &ACTIONS.waste_not_ii, - &ACTIONS.groundwork, - &ACTIONS.delicate_synthesis, - &ACTIONS.delicate_synthesis - ] - ); - - let route = routes1.pop().unwrap(); - assert_eq!( - route.actions, - vec![ - &ACTIONS.muscle_memory, - &ACTIONS.manipulation, - &ACTIONS.veneration, - &ACTIONS.waste_not_ii, - &ACTIONS.groundwork, - &ACTIONS.delicate_synthesis, - &ACTIONS.basic_synthesis, - ] - ); - - let route = routes1.pop().unwrap(); - assert_eq!( - route.actions, - vec![ - &ACTIONS.muscle_memory, - &ACTIONS.manipulation, - &ACTIONS.veneration, - &ACTIONS.waste_not_ii, - &ACTIONS.groundwork, - &ACTIONS.careful_synthesis - ] - ); - - let route = routes1.pop().unwrap(); - assert_eq!( - route.actions, - vec![ - &ACTIONS.muscle_memory, - &ACTIONS.manipulation, - &ACTIONS.veneration, - &ACTIONS.waste_not_ii, - &ACTIONS.groundwork, - &ACTIONS.basic_synthesis - ] - ); - - let route = routes1.pop().unwrap(); - assert_eq!( - route.actions, - vec![ - &ACTIONS.muscle_memory, - &ACTIONS.manipulation, - &ACTIONS.veneration, - &ACTIONS.groundwork, - &ACTIONS.delicate_synthesis, - &ACTIONS.delicate_synthesis - ] - ); - - let route = routes1.pop().unwrap(); - assert_eq!( - route.actions, - vec![ - &ACTIONS.muscle_memory, - &ACTIONS.manipulation, - &ACTIONS.veneration, - &ACTIONS.groundwork, - &ACTIONS.delicate_synthesis, - &ACTIONS.basic_synthesis - ] - ); - - let route = routes1.pop().unwrap(); - assert_eq!( - route.actions, - vec![ - &ACTIONS.muscle_memory, - &ACTIONS.manipulation, - &ACTIONS.veneration, - &ACTIONS.groundwork, - &ACTIONS.prudent_synthesis - ] - ); - - let route = routes1.pop().unwrap(); - assert_eq!( - route.actions, - vec![ - &ACTIONS.muscle_memory, - &ACTIONS.manipulation, - &ACTIONS.veneration, - &ACTIONS.groundwork, - &ACTIONS.careful_synthesis - ] - ); - - let route = routes1.pop().unwrap(); - assert_eq!( - route.actions, - vec![ - &ACTIONS.muscle_memory, - &ACTIONS.manipulation, - &ACTIONS.veneration, - &ACTIONS.groundwork, - &ACTIONS.basic_synthesis - ] - ); - - let route = routes1.pop(); - match route { - None => (), - Some(..) => panic!(), - } - } -} +mod test_solver; diff --git a/src/solver/test_solver.rs b/src/solver/test_solver.rs new file mode 100644 index 0000000..1535d72 --- /dev/null +++ b/src/solver/test_solver.rs @@ -0,0 +1,391 @@ +#[allow(unused_imports)] +use super::*; + +#[test] +pub fn test_first_step() { + let mut craft = crate::craft::Craft::two_star(); + // Try a failed craft + craft.success = crate::specs::Success::Failure; + let vact = next_action_picker_1(&craft); + assert_eq!(vact, vec![None]); + craft.success = crate::specs::Success::Pending; + + // Try the first 4 steps + let vact = next_action_picker_1(&craft); + assert_eq!(vact, action_vec![ACTIONS.muscle_memory]); + craft.run_action(&ACTIONS.muscle_memory); + + let vact = next_action_picker_1(&craft); + assert_eq!(vact, action_vec![ACTIONS.manipulation]); + craft.run_action(&ACTIONS.manipulation); + + let vact = next_action_picker_1(&craft); + assert_eq!(vact, action_vec![ACTIONS.veneration]); + craft.run_action(&ACTIONS.veneration); + + let vact = next_action_picker_1(&craft); + assert_eq!(vact, action_vec![ACTIONS.waste_not_ii, ACTIONS.groundwork]); + craft.run_action(&ACTIONS.waste_not_ii); + + // Try the steps 5-8, deterministically + let vact = next_action_picker_1(&craft); + assert_eq!(vact, action_vec![ACTIONS.groundwork]); + craft.run_action(&ACTIONS.careful_synthesis); + + let vact = next_action_picker_1(&craft); + assert_eq!( + vact, + action_vec![ + ACTIONS.groundwork, + ACTIONS.basic_synthesis, + ACTIONS.careful_synthesis, + ACTIONS.delicate_synthesis + ] + ); + craft.run_action(&ACTIONS.careful_synthesis); + + let vact = next_action_picker_1(&craft); + assert_eq!( + vact, + action_vec![ + ACTIONS.groundwork, + ACTIONS.basic_synthesis, + ACTIONS.careful_synthesis, + ACTIONS.delicate_synthesis + ] + ); + craft.run_action(&ACTIONS.careful_synthesis); + + let vact = next_action_picker_1(&craft); + assert_eq!( + vact, + action_vec![ + ACTIONS.groundwork, + ACTIONS.basic_synthesis, + ACTIONS.careful_synthesis, + ACTIONS.delicate_synthesis + ] + ); + craft.run_action(&ACTIONS.careful_synthesis); + + // Check odd parameters + craft.buffs.waste_not = 0; + craft.progression = 0; + let vact = next_action_picker_1(&craft); + assert_eq!( + vact, + action_vec![ + ACTIONS.basic_synthesis, + ACTIONS.careful_synthesis, + ACTIONS.prudent_synthesis, + ACTIONS.delicate_synthesis + ] + ); + craft.run_action(&ACTIONS.delicate_synthesis); + + let vact = next_action_picker_1(&craft); + assert_eq!( + vact, + action_vec![ + ACTIONS.basic_synthesis, + ACTIONS.careful_synthesis, + ACTIONS.prudent_synthesis, + ACTIONS.delicate_synthesis, + ACTIONS.waste_not_ii, + ACTIONS.waste_not + ] + ); + + craft.args.desperate = true; + let vact = next_action_picker_1(&craft); + assert_eq!( + vact, + action_vec![ + ACTIONS.basic_synthesis, + ACTIONS.careful_synthesis, + ACTIONS.prudent_synthesis, + ACTIONS.delicate_synthesis, + ACTIONS.groundwork, + ACTIONS.masters_mend, + ACTIONS.waste_not_ii, + ACTIONS.waste_not + ] + ); + assert_eq!(craft.progression, 250); + assert_eq!(craft.quality, 266); + assert_eq!(craft.cp, 317); +} + +#[test] +pub fn test_routes_p1() { + let craft = crate::craft::Craft::two_star(); + let mut routes1 = generate_routes_phase1(craft); + + for route in routes1.iter() { + println!("{:?}", route.actions); + } + // Literrally any change will break it + // An eq should be implmented to just check a vector of vector versus a route + assert_eq!(routes1.len(), 9); + let route = routes1.pop().unwrap(); + assert_eq!( + route.actions, + vec![ + &ACTIONS.muscle_memory, + &ACTIONS.manipulation, + &ACTIONS.veneration, + &ACTIONS.waste_not_ii, + &ACTIONS.groundwork, + &ACTIONS.delicate_synthesis, + &ACTIONS.delicate_synthesis + ] + ); + + let route = routes1.pop().unwrap(); + assert_eq!( + route.actions, + vec![ + &ACTIONS.muscle_memory, + &ACTIONS.manipulation, + &ACTIONS.veneration, + &ACTIONS.waste_not_ii, + &ACTIONS.groundwork, + &ACTIONS.delicate_synthesis, + &ACTIONS.basic_synthesis, + ] + ); + + let route = routes1.pop().unwrap(); + assert_eq!( + route.actions, + vec![ + &ACTIONS.muscle_memory, + &ACTIONS.manipulation, + &ACTIONS.veneration, + &ACTIONS.waste_not_ii, + &ACTIONS.groundwork, + &ACTIONS.careful_synthesis + ] + ); + + let route = routes1.pop().unwrap(); + assert_eq!( + route.actions, + vec![ + &ACTIONS.muscle_memory, + &ACTIONS.manipulation, + &ACTIONS.veneration, + &ACTIONS.waste_not_ii, + &ACTIONS.groundwork, + &ACTIONS.basic_synthesis + ] + ); + + let route = routes1.pop().unwrap(); + assert_eq!( + route.actions, + vec![ + &ACTIONS.muscle_memory, + &ACTIONS.manipulation, + &ACTIONS.veneration, + &ACTIONS.groundwork, + &ACTIONS.delicate_synthesis, + &ACTIONS.delicate_synthesis + ] + ); + + let route = routes1.pop().unwrap(); + assert_eq!( + route.actions, + vec![ + &ACTIONS.muscle_memory, + &ACTIONS.manipulation, + &ACTIONS.veneration, + &ACTIONS.groundwork, + &ACTIONS.delicate_synthesis, + &ACTIONS.basic_synthesis + ] + ); + + let route = routes1.pop().unwrap(); + assert_eq!( + route.actions, + vec![ + &ACTIONS.muscle_memory, + &ACTIONS.manipulation, + &ACTIONS.veneration, + &ACTIONS.groundwork, + &ACTIONS.prudent_synthesis + ] + ); + + let route = routes1.pop().unwrap(); + assert_eq!( + route.actions, + vec![ + &ACTIONS.muscle_memory, + &ACTIONS.manipulation, + &ACTIONS.veneration, + &ACTIONS.groundwork, + &ACTIONS.careful_synthesis + ] + ); + + let route = routes1.pop().unwrap(); + assert_eq!( + route.actions, + vec![ + &ACTIONS.muscle_memory, + &ACTIONS.manipulation, + &ACTIONS.veneration, + &ACTIONS.groundwork, + &ACTIONS.basic_synthesis + ] + ); + + let route = routes1.pop(); + assert!(route.is_none()); +} + +// Test Custom routes (None and basic synthesis) +#[test] +pub fn test_custom_p1_routes() { + // None route, no more actions + let mut craft = crate::craft::Craft::zero_star(); + craft.success = crate::specs::Success::Failure; + let routes1 = generate_routes_phase1(craft.clone()); + assert!(routes1.is_empty()); +} + +// Test step 2 route-finding +#[test] +pub fn test_second_step() { + let mut craft = crate::craft::Craft::two_star(); + craft.cp = 10000; + let mut routes1 = generate_routes_phase1(craft); + let mut craft2 = routes1.pop().unwrap(); + let vact = next_action_phase_2(&craft2); + assert_eq!(vact, action_vec![ACTIONS.innovation]); + craft2.run_action(&ACTIONS.innovation); + + let vact = next_action_phase_2(&craft2); + assert_eq!( + vact, + action_vec![ACTIONS.basic_touch, ACTIONS.preparatory_touch] + ); + craft2.run_action(&ACTIONS.basic_touch); + + let vact = next_action_phase_2(&craft2); + assert_eq!( + vact, + action_vec![ACTIONS.preparatory_touch, ACTIONS.standard_touch] + ); + craft2.run_action(&ACTIONS.standard_touch); + + let vact = next_action_phase_2(&craft2); + assert_eq!( + vact, + action_vec![ACTIONS.preparatory_touch, ACTIONS.advanced_touch] + ); + craft2.run_action(&ACTIONS.advanced_touch); + + let vact = next_action_phase_2(&craft2); + assert_eq!( + vact, + action_vec![ + ACTIONS.basic_touch, + ACTIONS.preparatory_touch, + ACTIONS.manipulation + ] + ); + craft2.run_action(&ACTIONS.manipulation); + + let vact = next_action_phase_2(&craft2); + assert_eq!(vact, action_vec![ACTIONS.innovation]); + craft2.run_action(&ACTIONS.innovation); + + let vact = next_action_phase_2(&craft2); + assert_eq!( + vact, + action_vec![ACTIONS.basic_touch, ACTIONS.prudent_touch] + ); + craft2.run_action(&ACTIONS.basic_touch); + + let vact = next_action_phase_2(&craft2); + assert_eq!( + vact, + action_vec![ACTIONS.prudent_touch, ACTIONS.standard_touch] + ); + craft2.run_action(&ACTIONS.prudent_touch); + + let vact = next_action_phase_2(&craft2); + assert_eq!( + vact, + action_vec![ACTIONS.basic_touch, ACTIONS.prudent_touch] + ); + craft2.run_action(&ACTIONS.prudent_touch); + + let vact = next_action_phase_2(&craft2); + assert_eq!( + vact, + action_vec![ACTIONS.basic_touch, ACTIONS.prudent_touch] + ); + craft2.run_action(&ACTIONS.prudent_touch); + + let vact = next_action_phase_2(&craft2); + assert_eq!(vact, action_vec![ACTIONS.innovation]); + craft2.run_action(&ACTIONS.innovation); + + let vact = next_action_phase_2(&craft2); + assert_eq!( + vact, + action_vec![ACTIONS.basic_touch, ACTIONS.prudent_touch] + ); + craft2.run_action(&ACTIONS.prudent_touch); + + let vact = next_action_phase_2(&craft2); + assert_eq!( + vact, + action_vec![ + ACTIONS.basic_touch, + ACTIONS.prudent_touch, + ACTIONS.trained_finesse, + ACTIONS.great_strides + ] + ); + craft2.run_action(&ACTIONS.great_strides); + + let vact = next_action_phase_2(&craft2); + assert_eq!( + vact, + action_vec![ + ACTIONS.basic_touch, + ACTIONS.prudent_touch, + ACTIONS.byregot_blessing + ] + ); + + craft2.run_action(&ACTIONS.byregot_blessing); + craft2.success = crate::specs::Success::Success; + assert_eq!(next_action_phase_2(&craft2), vec![None]); + assert_eq!(craft2.progression, 3750); + assert_eq!(craft2.quality, 9899); + assert_eq!(craft2.cp, 9322); +} + +#[test] +pub fn test_generate_routes_p2() { + let craft = crate::craft::Craft::two_star(); + let mut routes1 = generate_routes_phase1(craft); + let craft1 = routes1.pop().unwrap(); + let routes2 = generate_routes_phase2(craft1); + assert_eq!(routes2.unwrap().len(), 241); + + // Any modification on the solving will break this test, same as before, + // maybe having a range of expected solution instead is the way to go. + + // Nonetheless the solver test will add qualitative testing so some + // results will be thoughrouly checked + + // Maybe sampling a handful results and expect them to always exits could also work +} diff --git a/tests/io.rs b/tests/io.rs deleted file mode 100644 index 8b13789..0000000 --- a/tests/io.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/tests/lib.rs b/tests/lib.rs deleted file mode 100644 index 8b13789..0000000 --- a/tests/lib.rs +++ /dev/null @@ -1 +0,0 @@ - -- 2.45.1 From b0cf27f624b6463af405990bf6610aa2d5988c5f Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Thu, 9 Mar 2023 01:32:12 +0100 Subject: [PATCH 07/14] Test(Coverage) - Adds the coverage of lib.rs and purges useless data from the report (python and main) --- Makefile.toml | 3 +- coverage/html/badges/flat.svg | 10 +- coverage/html/badges/flat_square.svg | 8 +- coverage/html/badges/for_the_badge.svg | 8 +- coverage/html/badges/plastic.svg | 10 +- coverage/html/badges/social.svg | 8 +- src/lib.rs | 182 ++++++++++++++++++++++++- 7 files changed, 205 insertions(+), 24 deletions(-) diff --git a/Makefile.toml b/Makefile.toml index 72dcc22..0c25cfa 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -30,8 +30,9 @@ ignore_errors = true script = [ "mkdir -p coverage", "mkdir -p coverage/html", +"mkdir -p coverage/", "CARGO_INCREMENTAL=0 RUSTFLAGS='-Cinstrument-coverage -Ccodegen-units=1 -Copt-level=0 -Coverflow-checks=off' 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/" +"grcov . --binary-path ./target/debug/deps/ -s . -t html --branch --ignore-not-existing --ignore '../*' --ignore '/*' --ignore '*xiv_csolver.rs' --ignore '*python*.rs' -o coverage/html/", ] [tasks.clean] diff --git a/coverage/html/badges/flat.svg b/coverage/html/badges/flat.svg index b482db6..b7c0854 100644 --- a/coverage/html/badges/flat.svg +++ b/coverage/html/badges/flat.svg @@ -1,6 +1,6 @@ - coverage: 77% + xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="20" role="img" aria-label="coverage: 96%"> + coverage: 96% @@ -10,14 +10,14 @@ - + coverage - - 77% + + 96% \ No newline at end of file diff --git a/coverage/html/badges/flat_square.svg b/coverage/html/badges/flat_square.svg index cc89b0d..a18f634 100644 --- a/coverage/html/badges/flat_square.svg +++ b/coverage/html/badges/flat_square.svg @@ -1,13 +1,13 @@ - coverage: 77% + xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="20" role="img" aria-label="coverage: 96%"> + coverage: 96% - + coverage - 77% + 96% \ No newline at end of file diff --git a/coverage/html/badges/for_the_badge.svg b/coverage/html/badges/for_the_badge.svg index 427f757..12a1eb8 100644 --- a/coverage/html/badges/for_the_badge.svg +++ b/coverage/html/badges/for_the_badge.svg @@ -1,13 +1,13 @@ - COVERAGE: 77% + xmlns:xlink="http://www.w3.org/1999/xlink" width="142.5" height="28" role="img" aria-label="COVERAGE: 96%"> + COVERAGE: 96% - + COVERAGE - 77% + 96% \ No newline at end of file diff --git a/coverage/html/badges/plastic.svg b/coverage/html/badges/plastic.svg index 5900c59..2245a14 100644 --- a/coverage/html/badges/plastic.svg +++ b/coverage/html/badges/plastic.svg @@ -1,6 +1,6 @@ - coverage: 77% + xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="18" role="img" aria-label="coverage: 96%"> + coverage: 96% @@ -12,14 +12,14 @@ - + coverage - - 77% + + 96% \ No newline at end of file diff --git a/coverage/html/badges/social.svg b/coverage/html/badges/social.svg index 8aeabdb..f26a8cf 100644 --- a/coverage/html/badges/social.svg +++ b/coverage/html/badges/social.svg @@ -1,6 +1,6 @@ - Coverage: 77% + xmlns:xlink="http://www.w3.org/1999/xlink" width="99" height="20" role="img" aria-label="Coverage: 96%"> + Coverage: 96% @@ -20,8 +20,8 @@ Coverage - - 77% + + 96% \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index b83a71f..ec165d2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -148,7 +148,7 @@ pub fn solve_craft<'a>( } } - // Core algorithm, fill all found routes with the best route (doesn't branch, just replace) + // Core algorithm, fill all found routes with the best route let arc_phase2_routes = Arc::new(Mutex::new(Vec::::new())); for route in phase1_routes { @@ -371,3 +371,183 @@ pub fn find_safe_route(routes: &Option>) -> Option<&SolverResu None => None, } } + +#[cfg(test)] +mod test { + use super::*; + + #[test] + pub fn test_lib_find_route() { + // Supposed to find a route for the base craft + let mut craft = crate::craft::Craft::two_star(); + let res = solve_craft(craft.recipe, craft.stats, craft.args); + assert!(res.unwrap().len() > 2000); + + craft.recipe.progress = 0; + let res = solve_craft(craft.recipe, craft.stats, craft.args); + println!("{:?}", res); + assert!(res.is_none()); + + craft.recipe.progress = 100; + craft.stats.max_cp = 0; + craft.cp = 0; + + let mut res = solve_craft(craft.recipe, craft.stats, craft.args).unwrap(); + println!("{:?}", res); + assert_eq!(res.len(), 1); + assert_eq!(res.pop().unwrap().actions, vec!("basicSynth2")); + } + + #[test] + pub fn test_lib_print_route() { + let craft = crate::craft::Craft::two_star(); + print_routes(&solve_craft(craft.recipe, craft.stats, craft.args)); + print_routes(&None); + } + + #[test] + pub fn test_lib_best_solutions() { + let craft = crate::craft::Craft::two_star(); + let res = solve_craft(craft.recipe, craft.stats, craft.args); + + assert!(find_fast_route(&None).is_none()); + assert!(find_quality_route(&None).is_none()); + assert!(find_safe_route(&None).is_none()); + + assert!(find_fast_route(&Some(vec![])).is_none()); + assert!(find_quality_route(&Some(vec![])).is_none()); + assert!(find_safe_route(&&Some(vec![])).is_none()); + + let sol = find_fast_route(&res).unwrap(); + assert_eq!(sol.steps, 17); + assert_eq!(sol.quality, 11129); + assert_eq!(sol.progression, 3750); + assert_eq!(sol.durability, 0); + assert_eq!(sol.cp, 7); + assert_eq!(sol.step1_solutions, 9); + assert_eq!(sol.step2_solutions, 21193); + assert_eq!(sol.found_100_percent, true); + assert_eq!( + sol.actions, + vec!( + "muscleMemory", + "manipulation", + "veneration", + "wasteNot2", + "groundwork", + "delicateSynthesis", + "delicateSynthesis", + "innovation", + "preparatoryTouch", + "preparatoryTouch", + "preparatoryTouch", + "preparatoryTouch", + "innovation", + "basicTouch", + "standardTouch", + "greatStrides", + "byregotsBlessing", + "basicSynth2" + ) + ); + + let sol = find_quality_route(&res).unwrap(); + assert_eq!(sol.steps, 23); + assert_eq!(sol.quality, 12032); + assert_eq!(sol.progression, 3675); + assert_eq!(sol.durability, -5); + assert_eq!(sol.cp, 3); + assert_eq!(sol.step1_solutions, 9); + assert_eq!(sol.step2_solutions, 21193); + assert_eq!(sol.found_100_percent, true); + assert_eq!( + sol.actions, + vec!( + "muscleMemory", + "manipulation", + "veneration", + "groundwork", + "prudentSynthesis", + "innovation", + "prudentTouch", + "basicTouch", + "standardTouch", + "advancedTouch", + "manipulation", + "innovation", + "prudentTouch", + "basicTouch", + "standardTouch", + "advancedTouch", + "innovation", + "basicTouch", + "standardTouch", + "advancedTouch", + "greatStrides", + "innovation", + "byregotsBlessing", + "basicSynth2" + ) + ); + + let sol = find_safe_route(&res).unwrap(); + assert_eq!(sol.steps, 22); + assert_eq!(sol.quality, 11161); + assert_eq!(sol.progression, 3675); + assert_eq!(sol.durability, 10); + assert_eq!(sol.cp, 4); + assert_eq!(sol.step1_solutions, 9); + assert_eq!(sol.step2_solutions, 21193); + assert_eq!(sol.found_100_percent, true); + assert_eq!( + sol.actions, + vec!( + "muscleMemory", + "manipulation", + "veneration", + "groundwork", + "carefulSynthesis", + "prudentTouch", + "innovation", + "prudentTouch", + "prudentTouch", + "prudentTouch", + "prudentTouch", + "manipulation", + "innovation", + "prudentTouch", + "basicTouch", + "standardTouch", + "advancedTouch", + "innovation", + "basicTouch", + "standardTouch", + "greatStrides", + "byregotsBlessing", + "basicSynth2" + ) + ); + } + + #[test] + pub fn test_load_from_config() { + load_from_config("default_recipe", "craft.toml", "default_character"); + } + + #[should_panic] + #[test] + pub fn test_bad_config_filename() { + load_from_config("default_recipe", "nocrafto.toml", "default_character"); + } + + #[should_panic] + #[test] + pub fn test_bad_config_recipename() { + load_from_config("bad_recipe", "craft.toml", "default_character"); + } + #[should_panic] + #[test] + pub fn test_bad_config_charname() { + load_from_config("default_recipe", "craft.toml", "bad_character"); + } +} -- 2.45.1 From 9a958fd8040228ab6fad35fefb7948bcf191790d Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Thu, 9 Mar 2023 02:02:02 +0100 Subject: [PATCH 08/14] Split Python bindings and finishes coverage --- coverage/html/badges/flat.svg | 8 +- coverage/html/badges/flat_square.svg | 6 +- coverage/html/badges/for_the_badge.svg | 6 +- coverage/html/badges/plastic.svg | 8 +- coverage/html/badges/social.svg | 8 +- src/io.rs | 299 ++++--------------------- src/lib.rs | 4 +- src/python_bindings.rs | 258 ++++++++++++++++++++- 8 files changed, 316 insertions(+), 281 deletions(-) diff --git a/coverage/html/badges/flat.svg b/coverage/html/badges/flat.svg index b7c0854..a43354b 100644 --- a/coverage/html/badges/flat.svg +++ b/coverage/html/badges/flat.svg @@ -1,6 +1,6 @@ - coverage: 96% + xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="20" role="img" aria-label="coverage: 99%"> + coverage: 99% @@ -16,8 +16,8 @@ coverage - - 96% + + 99% \ No newline at end of file diff --git a/coverage/html/badges/flat_square.svg b/coverage/html/badges/flat_square.svg index a18f634..7816a7a 100644 --- a/coverage/html/badges/flat_square.svg +++ b/coverage/html/badges/flat_square.svg @@ -1,13 +1,13 @@ - coverage: 96% + xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="20" role="img" aria-label="coverage: 99%"> + coverage: 99% coverage - 96% + 99% \ No newline at end of file diff --git a/coverage/html/badges/for_the_badge.svg b/coverage/html/badges/for_the_badge.svg index 12a1eb8..a58c41d 100644 --- a/coverage/html/badges/for_the_badge.svg +++ b/coverage/html/badges/for_the_badge.svg @@ -1,13 +1,13 @@ - COVERAGE: 96% + xmlns:xlink="http://www.w3.org/1999/xlink" width="142.5" height="28" role="img" aria-label="COVERAGE: 99%"> + COVERAGE: 99% COVERAGE - 96% + 99% \ No newline at end of file diff --git a/coverage/html/badges/plastic.svg b/coverage/html/badges/plastic.svg index 2245a14..a3720ca 100644 --- a/coverage/html/badges/plastic.svg +++ b/coverage/html/badges/plastic.svg @@ -1,6 +1,6 @@ - coverage: 96% + xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="18" role="img" aria-label="coverage: 99%"> + coverage: 99% @@ -18,8 +18,8 @@ coverage - - 96% + + 99% \ No newline at end of file diff --git a/coverage/html/badges/social.svg b/coverage/html/badges/social.svg index f26a8cf..e26d0fc 100644 --- a/coverage/html/badges/social.svg +++ b/coverage/html/badges/social.svg @@ -1,6 +1,6 @@ - Coverage: 96% + xmlns:xlink="http://www.w3.org/1999/xlink" width="99" height="20" role="img" aria-label="Coverage: 99%"> + Coverage: 99% @@ -20,8 +20,8 @@ Coverage - - 96% + + 99% \ No newline at end of file diff --git a/src/io.rs b/src/io.rs index e4214b7..75817ff 100644 --- a/src/io.rs +++ b/src/io.rs @@ -1,15 +1,8 @@ //! The main IO module -//! For now it contains the python bindings, the Args bindings (for clap) and the struct +//! For now it contains 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; - -// #[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)] @@ -68,149 +61,6 @@ pub struct Args { pub long: bool, } -/// 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> { - write!(f, "{:?}", self.actions) - } -} - -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, - step2_solutions: usize, - found_100_percent: bool, - ) -> SolverResult { - let mut actions = craft - .actions - .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 { - actions.push("basicSynth2".to_string()); - } - if 1.2 <= arg && arg < 1.8 { - actions.push("carefulSynthesis".to_string()); - } - if 1.8 <= arg && arg < 2.0 { - actions.push("observe".to_string()); - actions.push("focusedSynthesis".to_string()); - } - SolverResult { - steps: craft.step_count, - progression: craft.progression, - quality: craft.quality, - durability: craft.durability, - actions: actions, - step1_solutions, - step2_solutions, - found_100_percent, - total_progression: craft.recipe.progress, - total_quality: craft.recipe.quality, - total_durability: craft.recipe.durability, - cp: craft.cp, - total_cp: craft.stats.max_cp, - } - } -} - -#[pymethods] -impl SolverResult { - /// 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 { - steps: 0, - progression: 0, - quality: 0, - durability: 0, - total_progression: 0, - total_quality: 0, - total_durability: 0, - actions: vec!["Act1".to_string(), "Act2".to_string()], - step1_solutions: 0, - step2_solutions: 0, - found_100_percent: false, - cp: 0, - total_cp: 0, - } - } - - /// Implement a pretty_print method - /// Mainly used for debug purposes - pub fn pretty_print(&self) { - println!( - "Quality: [{}/{}] | Durability: [{}/{}] | Cp : [{}/{}] | Steps : {}", - self.quality, - self.total_quality, - self.durability, - self.total_durability, - self.cp, - self.total_cp, - self.steps - ); - println!("{:?}", self.actions); - } -} - impl Parameters { /// Create parameters from the arguments parsed by clap pub fn from_args(args: &Args) -> Self { @@ -224,116 +74,10 @@ impl Parameters { } } -////// Python Bindings ////// - -/// A Python module implemented in Rust. -#[cfg(not(feature = "no_python"))] -#[pymodule] -fn xiv_csolver_lib(_py: Python, m: &PyModule) -> PyResult<()> { - m.add_function(wrap_pyfunction!(test_result, m)?)?; - m.add_function(wrap_pyfunction!(solve_from_python, m)?)?; - Ok(()) -} - -/// A test result, useful for debugging, all values are set to zero as per the -/// [`default`](crate::io::SolverResult::default) -/// ``` -/// # use xiv_csolver_lib::io::SolverResult; -/// SolverResult { -/// steps: 0, -/// progression: 0, -/// quality: 0, -/// durability: 0, -/// total_progression: 0, -/// total_quality: 0, -/// total_durability: 0, -/// actions: vec!["Act1".to_string(), "Act2".to_string()], -/// step1_solutions: 0, -/// step2_solutions: 0, -/// found_100_percent: false, -/// cp: 0, -/// total_cp: 0, -/// }; -/// ``` -#[cfg(not(feature = "no_python"))] -#[pyfunction] -pub fn test_result() -> SolverResult { - SolverResult::default() -} - -/// Create a stat struct stats with the base values -#[cfg(not(feature = "no_python"))] -use crate::{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(py: Python<'_>, values: &PyAny) -> PyResult>> { - // Create Recipe - let recipe = Recipe { - durability: values.getattr("durability")?.extract()?, - progress: values.getattr("progress")?.extract()?, - progress_divider: values.getattr("progress_divider")?.extract()?, - progress_modifier: values.getattr("progress_modifier")?.extract()?, - quality: values.getattr("quality")?.extract()?, - quality_divider: values.getattr("quality_divider")?.extract()?, - quality_modifier: values.getattr("quality_modifier")?.extract()?, - }; - - // Create Stats - let stats = Stats { - craftsmanship: values.getattr("craftsmanship")?.extract()?, - control: values.getattr("control")?.extract()?, - max_cp: values.getattr("max_cp")?.extract()?, - }; - - // Create parameters - let param = Parameters { - depth: values.getattr("depth")?.extract()?, - byregot_step: values.getattr("byregot_step")?.extract()?, - desperate: values.getattr("desperate")?.extract()?, - threads: values.getattr("threads")?.extract()?, - verbose: values.getattr("verbose")?.extract()?, - }; - - // println!("{:?} len: {:?} ",values,values.getattr("len()")); - py.allow_threads(move || { - let res = solve_craft(recipe, stats, param); - Ok(res) - }) -} - #[cfg(test)] mod tests { - use crate::io::Args; - use crate::{Parameters, SolverResult}; + use crate::io::{Args, Parameters}; + use crate::python_bindings::SolverResult; use clap::Parser; use pretty_assertions::{assert_eq, assert_ne}; @@ -391,7 +135,7 @@ mod tests { let a2 = a.clone(); println!("{:?}", a2); // Test Custom recipe - let a3 = Args::parse_from([ + let a3 = crate::io::Args::parse_from([ "ultraman", "-r", "recipe", @@ -431,5 +175,38 @@ mod tests { } #[test] - pub fn test_parameters() {} + pub fn test_parameters() { + // Test a random config + let ar = Args::parse_from([ + "ultraman", + "-r", + "recipe", + "-c", + "dan", + "-f", + "bigfile.toml", + "-d", + "45", + "-t", + "4", + "-D", + "-l", + "-vvv", + ]); + let p = Parameters::from_args(&ar); + assert_eq!(p.depth, 11); + assert_eq!(p.verbose, 3); + assert_eq!(p.threads, 4); + assert_eq!(p.desperate, true); + assert_eq!(p.byregot_step, 6); + + // Test defaults + let ar = Args::parse_from(&["a"]); + let p = Parameters::from_args(&ar); + assert_eq!(p.depth, 8); + assert_eq!(p.verbose, 0); + assert_eq!(p.threads, 4); + assert_eq!(p.desperate, false); + assert_eq!(p.byregot_step, 8); + } } diff --git a/src/lib.rs b/src/lib.rs index ec165d2..57b51b9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -97,7 +97,8 @@ #![warn(missing_docs)] use crate::craft::Craft; -use crate::io::{Parameters, SolverResult}; +use crate::io::Parameters; +use crate::python_bindings::SolverResult; use crate::specs::{Recipe, Stats}; use std::sync::{Arc, Mutex}; use threadpool::ThreadPool; @@ -105,6 +106,7 @@ use threadpool::ThreadPool; pub mod action; pub mod craft; pub mod io; +pub mod python_bindings; mod solver; pub mod specs; diff --git a/src/python_bindings.rs b/src/python_bindings.rs index 44e2247..d8bc847 100644 --- a/src/python_bindings.rs +++ b/src/python_bindings.rs @@ -1,4 +1,260 @@ -#[cfg(not(feature="no_python"))] +//! The binding module +//! It contains the python bindings, and the structs +//! needed to hold all parameters needed at runtime +//! +//! Making the bindings a build feature is a WIP + +use crate::Craft; +#[cfg(not(feature = "no_python"))] +use crate::Parameters; +use core::fmt::Display; use pyo3::prelude::*; +/// 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> { + write!(f, "{:?}", self.actions) + } +} + +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, + step2_solutions: usize, + found_100_percent: bool, + ) -> SolverResult { + let mut actions = craft + .actions + .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 { + actions.push("basicSynth2".to_string()); + } + if 1.2 <= arg && arg < 1.8 { + actions.push("carefulSynthesis".to_string()); + } + if 1.8 <= arg && arg < 2.0 { + actions.push("observe".to_string()); + actions.push("focusedSynthesis".to_string()); + } + SolverResult { + steps: craft.step_count, + progression: craft.progression, + quality: craft.quality, + durability: craft.durability, + actions: actions, + step1_solutions, + step2_solutions, + found_100_percent, + total_progression: craft.recipe.progress, + total_quality: craft.recipe.quality, + total_durability: craft.recipe.durability, + cp: craft.cp, + total_cp: craft.stats.max_cp, + } + } +} + +#[pymethods] +impl SolverResult { + /// 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 { + steps: 0, + progression: 0, + quality: 0, + durability: 0, + total_progression: 0, + total_quality: 0, + total_durability: 0, + actions: vec!["Act1".to_string(), "Act2".to_string()], + step1_solutions: 0, + step2_solutions: 0, + found_100_percent: false, + cp: 0, + total_cp: 0, + } + } + + /// Implement a pretty_print method + /// Mainly used for debug purposes + pub fn pretty_print(&self) { + println!( + "Quality: [{}/{}] | Durability: [{}/{}] | Cp : [{}/{}] | Steps : {}", + self.quality, + self.total_quality, + self.durability, + self.total_durability, + self.cp, + self.total_cp, + self.steps + ); + println!("{:?}", self.actions); + } +} + +////// Python Bindings ////// + +/// A Python module implemented in Rust. +#[cfg(not(feature = "no_python"))] +#[pymodule] +fn xiv_csolver_lib(_py: Python, m: &PyModule) -> PyResult<()> { + m.add_function(wrap_pyfunction!(test_result, m)?)?; + m.add_function(wrap_pyfunction!(solve_from_python, m)?)?; + Ok(()) +} + +/// A test result, useful for debugging, all values are set to zero as per the +/// [`default`](crate::io::SolverResult::default) +/// ``` +/// # use xiv_csolver_lib::python_bindings::SolverResult; +/// SolverResult { +/// steps: 0, +/// progression: 0, +/// quality: 0, +/// durability: 0, +/// total_progression: 0, +/// total_quality: 0, +/// total_durability: 0, +/// actions: vec!["Act1".to_string(), "Act2".to_string()], +/// step1_solutions: 0, +/// step2_solutions: 0, +/// found_100_percent: false, +/// cp: 0, +/// total_cp: 0, +/// }; +/// ``` +#[cfg(not(feature = "no_python"))] +#[pyfunction] +pub fn test_result() -> SolverResult { + SolverResult::default() +} + +/// Create a stat struct stats with the base values +#[cfg(not(feature = "no_python"))] +use crate::{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(py: Python<'_>, values: &PyAny) -> PyResult>> { + // Create Recipe + let recipe = Recipe { + durability: values.getattr("durability")?.extract()?, + progress: values.getattr("progress")?.extract()?, + progress_divider: values.getattr("progress_divider")?.extract()?, + progress_modifier: values.getattr("progress_modifier")?.extract()?, + quality: values.getattr("quality")?.extract()?, + quality_divider: values.getattr("quality_divider")?.extract()?, + quality_modifier: values.getattr("quality_modifier")?.extract()?, + }; + + // Create Stats + let stats = Stats { + craftsmanship: values.getattr("craftsmanship")?.extract()?, + control: values.getattr("control")?.extract()?, + max_cp: values.getattr("max_cp")?.extract()?, + }; + + // Create parameters + let param = Parameters { + depth: values.getattr("depth")?.extract()?, + byregot_step: values.getattr("byregot_step")?.extract()?, + desperate: values.getattr("desperate")?.extract()?, + threads: values.getattr("threads")?.extract()?, + verbose: values.getattr("verbose")?.extract()?, + }; + + // println!("{:?} len: {:?} ",values,values.getattr("len()")); + py.allow_threads(move || { + let res = solve_craft(recipe, stats, param); + Ok(res) + }) +} -- 2.45.1 From 4808b5f82f0c71694f5a9ce3139d996c1829cf2d Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Thu, 9 Mar 2023 04:21:09 +0100 Subject: [PATCH 09/14] Test(Coverage) - Adds the final coverage for bindings and corrects the python's side of implementation --- python/src/xiv_csolver/example.py | 4 +- python/src/xiv_csolver/modules/solver.py | 3 +- src/bin/xiv_csolver.rs | 26 +++--- src/io.rs | 3 +- src/lib.rs | 99 +++++++++----------- src/python_bindings.rs | 111 +++++++++++++++++++---- 6 files changed, 157 insertions(+), 89 deletions(-) diff --git a/python/src/xiv_csolver/example.py b/python/src/xiv_csolver/example.py index cda7867..5148822 100644 --- a/python/src/xiv_csolver/example.py +++ b/python/src/xiv_csolver/example.py @@ -2,9 +2,9 @@ import xiv_csolver_lib import rich rich.inspect(xiv_csolver_lib) -rich.inspect(xiv_csolver_lib.test_result) -rich.inspect(xiv_csolver_lib.test_result()) rich.inspect(xiv_csolver_lib.test_result()) +rich.inspect(xiv_csolver_lib.test_info()) +rich.inspect(xiv_csolver_lib.test_final_results()) class FeedMeDaddy: diff --git a/python/src/xiv_csolver/modules/solver.py b/python/src/xiv_csolver/modules/solver.py index e10c52c..c4ec249 100644 --- a/python/src/xiv_csolver/modules/solver.py +++ b/python/src/xiv_csolver/modules/solver.py @@ -116,6 +116,7 @@ class Solver: self.loggers = loggers self.solutions = [] + self.info = None self.best_quality = None self.least_steps = None self.safe_50 = None @@ -124,7 +125,7 @@ class Solver: self.compute_all() def solve(self) -> str: - self.solutions = xcs.solve_from_python(self) + self.solutions,self.info = xcs.solve_from_python(self) return self.solutions def compute_all(self) -> True: diff --git a/src/bin/xiv_csolver.rs b/src/bin/xiv_csolver.rs index 9549faf..fe884ad 100644 --- a/src/bin/xiv_csolver.rs +++ b/src/bin/xiv_csolver.rs @@ -131,26 +131,26 @@ fn main() { Some(ref res) => { // Show best results if args.verbose > 0 { - println!("[Final] {} results were found:", res.len()); + println!("[Final] {} results were found:", res.0.len()); #[cfg(feature = "verbose")] if args.verbose > 1 { xiv_csolver_lib::print_routes(&results); } } + println!("\n > SOLUTION [Least steps] <"); + xiv_csolver_lib::find_fast_route(&res) + .unwrap() + .pretty_print(); + println!("\n > SOLUTION [Most durability] <"); + xiv_csolver_lib::find_safe_route(&res) + .unwrap() + .pretty_print(); + println!("\n > SOLUTION [Most quality] < "); + xiv_csolver_lib::find_quality_route(&res) + .unwrap() + .pretty_print(); } } - println!("\n > SOLUTION [Least steps] <"); - xiv_csolver_lib::find_fast_route(&results) - .unwrap() - .pretty_print(); - println!("\n > SOLUTION [Most durability] <"); - xiv_csolver_lib::find_safe_route(&results) - .unwrap() - .pretty_print(); - println!("\n > SOLUTION [Most quality] < "); - xiv_csolver_lib::find_quality_route(&results) - .unwrap() - .pretty_print(); // #[cfg(feature = "verbose")] // if params.verbose>2{ diff --git a/src/io.rs b/src/io.rs index 75817ff..4c24a90 100644 --- a/src/io.rs +++ b/src/io.rs @@ -116,7 +116,8 @@ mod tests { #[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 }"); + 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] diff --git a/src/lib.rs b/src/lib.rs index 57b51b9..02b7eb8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -98,7 +98,7 @@ use crate::craft::Craft; use crate::io::Parameters; -use crate::python_bindings::SolverResult; +use crate::python_bindings::{Info, SolverResult}; use crate::specs::{Recipe, Stats}; use std::sync::{Arc, Mutex}; use threadpool::ThreadPool; @@ -115,7 +115,7 @@ pub fn solve_craft<'a>( recipe: Recipe, stats: Stats, params: Parameters, -) -> Option> { +) -> Option<(Vec, Info)> { // Load the craft with given arguments let craft = Craft::new(recipe, stats, params); @@ -196,17 +196,17 @@ pub fn solve_craft<'a>( for route in phase2_routes.iter() { if route.quality >= route.recipe.quality { // valid_routes.push(route.clone()); - valid_solutions.push(SolverResult::from_craft(route, nb_p1, nb_p2, true)); + valid_solutions.push(SolverResult::from_craft(route)); //nb_p1, nb_p2, true } } // If no craft can make it to 100% HQ, fallback to base results if valid_solutions.len() == 0 { for route in phase2_routes.iter() { - valid_solutions.push(SolverResult::from_craft(route, nb_p1, nb_p2, false)); + valid_solutions.push(SolverResult::from_craft(route)); } } - Some(valid_solutions) + Some((valid_solutions, Info::new(nb_p1, nb_p2, true))) } /// Load the config from args and make a craft from it @@ -323,9 +323,9 @@ pub fn load_from_config<'a>( } /// Print all routes in the vect, verbose -pub fn print_routes<'a>(routes: &Option>) { +pub fn print_routes<'a>(routes: &Option<(Vec, Info)>) { match routes { - Some(r) => { + Some((r, _)) => { println!("Showing {} routes", r.len()); for c in r.iter() { println!( @@ -339,38 +339,28 @@ pub fn print_routes<'a>(routes: &Option>) { } /// Find the route with the least amount of steps -pub fn find_fast_route(routes: &Option>) -> Option<&SolverResult> { - match routes { - Some(_routes) => { - if _routes.len() > 0 { - _routes.iter().min_by_key(|key| key.steps) - } else { - None - } - } - None => None, +pub fn find_fast_route<'a>(routes: &'a (Vec, Info)) -> Option<&'a SolverResult> { + let (_routes, _info) = routes; + if _routes.len() > 0 { + _routes.iter().min_by_key(|key| key.steps) + } else { + None } } /// Find the route with the maximum amount of quality -pub fn find_quality_route(routes: &Option>) -> Option<&SolverResult> { - match routes { - Some(_routes) => _routes.iter().max_by_key(|key| key.quality), - None => None, - } +pub fn find_quality_route<'a>(routes: &'a (Vec, Info)) -> Option<&'a SolverResult> { + let (_routes, _info) = routes; + _routes.iter().max_by_key(|key| key.quality) } /// Find the route with the maximum of durability left -pub fn find_safe_route(routes: &Option>) -> Option<&SolverResult> { - match routes { - Some(_routes) => { - if _routes.len() > 0 { - _routes.iter().max_by_key(|key| key.durability) - } else { - None - } - } - None => None, +pub fn find_safe_route(routes: &(Vec, Info)) -> Option<&SolverResult> { + let (_routes, _info) = routes; + if _routes.len() > 0 { + _routes.iter().max_by_key(|key| key.durability) + } else { + None } } @@ -383,7 +373,7 @@ mod test { // Supposed to find a route for the base craft let mut craft = crate::craft::Craft::two_star(); let res = solve_craft(craft.recipe, craft.stats, craft.args); - assert!(res.unwrap().len() > 2000); + assert!(res.unwrap().0.len() > 2000); craft.recipe.progress = 0; let res = solve_craft(craft.recipe, craft.stats, craft.args); @@ -396,8 +386,8 @@ mod test { let mut res = solve_craft(craft.recipe, craft.stats, craft.args).unwrap(); println!("{:?}", res); - assert_eq!(res.len(), 1); - assert_eq!(res.pop().unwrap().actions, vec!("basicSynth2")); + assert_eq!(res.0.len(), 1); + assert_eq!(res.0.pop().unwrap().actions, vec!("basicSynth2")); } #[test] @@ -410,25 +400,24 @@ mod test { #[test] pub fn test_lib_best_solutions() { let craft = crate::craft::Craft::two_star(); - let res = solve_craft(craft.recipe, craft.stats, craft.args); + let routes = solve_craft(craft.recipe, craft.stats, craft.args).unwrap(); + // assert!(find_fast_route(&(None)).is_none()); + // assert!(find_quality_route(&None).is_none()); + // assert!(find_safe_route(&None).is_none()); - assert!(find_fast_route(&None).is_none()); - assert!(find_quality_route(&None).is_none()); - assert!(find_safe_route(&None).is_none()); + assert!(find_fast_route(&((vec![], Info::default()))).is_none()); + assert!(find_quality_route(&((vec![], Info::default()))).is_none()); + assert!(find_safe_route(&((vec![], Info::default()))).is_none()); - assert!(find_fast_route(&Some(vec![])).is_none()); - assert!(find_quality_route(&Some(vec![])).is_none()); - assert!(find_safe_route(&&Some(vec![])).is_none()); - - let sol = find_fast_route(&res).unwrap(); + let sol = find_fast_route(&routes).unwrap(); assert_eq!(sol.steps, 17); assert_eq!(sol.quality, 11129); assert_eq!(sol.progression, 3750); assert_eq!(sol.durability, 0); assert_eq!(sol.cp, 7); - assert_eq!(sol.step1_solutions, 9); - assert_eq!(sol.step2_solutions, 21193); - assert_eq!(sol.found_100_percent, true); + assert_eq!(routes.1.step1_solutions, 9); + assert_eq!(routes.1.step2_solutions, 21193); + assert_eq!(routes.1.found_100_percent, true); assert_eq!( sol.actions, vec!( @@ -453,15 +442,15 @@ mod test { ) ); - let sol = find_quality_route(&res).unwrap(); + let sol = find_quality_route(&routes).unwrap(); assert_eq!(sol.steps, 23); assert_eq!(sol.quality, 12032); assert_eq!(sol.progression, 3675); assert_eq!(sol.durability, -5); assert_eq!(sol.cp, 3); - assert_eq!(sol.step1_solutions, 9); - assert_eq!(sol.step2_solutions, 21193); - assert_eq!(sol.found_100_percent, true); + assert_eq!(routes.1.step1_solutions, 9); + assert_eq!(routes.1.step2_solutions, 21193); + assert_eq!(routes.1.found_100_percent, true); assert_eq!( sol.actions, vec!( @@ -492,15 +481,15 @@ mod test { ) ); - let sol = find_safe_route(&res).unwrap(); + let sol = find_safe_route(&routes).unwrap(); assert_eq!(sol.steps, 22); assert_eq!(sol.quality, 11161); assert_eq!(sol.progression, 3675); assert_eq!(sol.durability, 10); assert_eq!(sol.cp, 4); - assert_eq!(sol.step1_solutions, 9); - assert_eq!(sol.step2_solutions, 21193); - assert_eq!(sol.found_100_percent, true); + assert_eq!(routes.1.step1_solutions, 9); + assert_eq!(routes.1.step2_solutions, 21193); + assert_eq!(routes.1.found_100_percent, true); assert_eq!( sol.actions, vec!( diff --git a/src/python_bindings.rs b/src/python_bindings.rs index d8bc847..43ac060 100644 --- a/src/python_bindings.rs +++ b/src/python_bindings.rs @@ -12,7 +12,6 @@ use pyo3::prelude::*; /// 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 { @@ -46,6 +45,21 @@ pub struct SolverResult { /// 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, +} + +/// Global info on the execution +#[derive(Debug)] +#[pyclass] +pub struct Info { /// The amount of solutions found during the first step of the solving (Used for debug) (Deprecated) #[pyo3(get)] pub step1_solutions: usize, @@ -57,6 +71,31 @@ pub struct SolverResult { pub found_100_percent: bool, } +/// Solution information, contains information about the execution +impl Info { + /// Make a new information struct + pub fn new( + step1_solutions: usize, + step2_solutions: usize, + found_100_percent: bool, + // params: &'Parameters + ) -> Self { + Self { + step1_solutions, + step2_solutions, + found_100_percent, + } + } + + /// Default value of the info, only used for debug purposes + pub fn default() -> Self { + Self { + step1_solutions: 0, + step2_solutions: 0, + found_100_percent: false, + } + } +} /// Pretty display for SolverResult impl Display for SolverResult { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { @@ -67,12 +106,7 @@ impl Display for SolverResult { 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, - step2_solutions: usize, - found_100_percent: bool, - ) -> SolverResult { + pub fn from_craft(craft: &Craft) -> SolverResult { let mut actions = craft .actions .iter() @@ -97,9 +131,6 @@ impl SolverResult { quality: craft.quality, durability: craft.durability, actions: actions, - step1_solutions, - step2_solutions, - found_100_percent, total_progression: craft.recipe.progress, total_quality: craft.recipe.quality, total_durability: craft.recipe.durability, @@ -128,9 +159,6 @@ impl SolverResult { total_quality: 0, total_durability: 0, actions: vec!["Act1".to_string(), "Act2".to_string()], - step1_solutions: 0, - step2_solutions: 0, - found_100_percent: false, cp: 0, total_cp: 0, } @@ -160,6 +188,8 @@ impl SolverResult { #[pymodule] fn xiv_csolver_lib(_py: Python, m: &PyModule) -> PyResult<()> { m.add_function(wrap_pyfunction!(test_result, m)?)?; + m.add_function(wrap_pyfunction!(test_final_results, m)?)?; + m.add_function(wrap_pyfunction!(test_info, m)?)?; m.add_function(wrap_pyfunction!(solve_from_python, m)?)?; Ok(()) } @@ -177,9 +207,6 @@ fn xiv_csolver_lib(_py: Python, m: &PyModule) -> PyResult<()> { /// total_quality: 0, /// total_durability: 0, /// actions: vec!["Act1".to_string(), "Act2".to_string()], -/// step1_solutions: 0, -/// step2_solutions: 0, -/// found_100_percent: false, /// cp: 0, /// total_cp: 0, /// }; @@ -190,6 +217,41 @@ pub fn test_result() -> SolverResult { SolverResult::default() } +/// A test info, useful for debugging, all values are set to zero as per the +/// [`default`](crate::io::Info::default) +/// ``` +/// # use xiv_csolver_lib::python_bindings::Info; +/// Info { +/// step1_solutions: 0, +/// step2_solutions: 0, +/// found_100_percent: false, +/// }; +/// ``` +#[cfg(not(feature = "no_python"))] +#[pyfunction] +pub fn test_info() -> Info { + Info::default() +} + +/// A test result array, useful for debugging, all values are set to zero as per the +/// [`default`](crate::io::Parameters::default) +/// ``` +/// # use xiv_csolver_lib::python_bindings::{Info}; +/// # use xiv_csolver_lib::python_bindings::SolverResult; +/// ( +/// vec![SolverResult::default(), SolverResult::default()], +/// Info::default(), +/// ); +/// ``` +#[cfg(not(feature = "no_python"))] +#[pyfunction] +pub fn test_final_results() -> (Vec, Info) { + ( + vec![SolverResult::default(), SolverResult::default()], + Info::default(), + ) +} + /// Create a stat struct stats with the base values #[cfg(not(feature = "no_python"))] use crate::{solve_craft, Recipe, Stats}; @@ -224,7 +286,10 @@ use crate::{solve_craft, Recipe, Stats}; #[cfg(not(feature = "no_python"))] #[pyfunction] -pub fn solve_from_python(py: Python<'_>, values: &PyAny) -> PyResult>> { +pub fn solve_from_python( + py: Python<'_>, + values: &PyAny, +) -> PyResult, Info)>> { // Create Recipe let recipe = Recipe { durability: values.getattr("durability")?.extract()?, @@ -258,3 +323,15 @@ pub fn solve_from_python(py: Python<'_>, values: &PyAny) -> PyResult Date: Thu, 9 Mar 2023 04:27:34 +0100 Subject: [PATCH 10/14] Typo(Doc) - Fixes a broken doc reference --- src/python_bindings.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/python_bindings.rs b/src/python_bindings.rs index 43ac060..ea492a1 100644 --- a/src/python_bindings.rs +++ b/src/python_bindings.rs @@ -195,7 +195,7 @@ fn xiv_csolver_lib(_py: Python, m: &PyModule) -> PyResult<()> { } /// A test result, useful for debugging, all values are set to zero as per the -/// [`default`](crate::io::SolverResult::default) +/// [`default`](crate::python_bindings::SolverResult::default()) /// ``` /// # use xiv_csolver_lib::python_bindings::SolverResult; /// SolverResult { @@ -218,7 +218,7 @@ pub fn test_result() -> SolverResult { } /// A test info, useful for debugging, all values are set to zero as per the -/// [`default`](crate::io::Info::default) +/// [`default`](crate::python_bindings::Info::default()) /// ``` /// # use xiv_csolver_lib::python_bindings::Info; /// Info { @@ -234,7 +234,7 @@ pub fn test_info() -> Info { } /// A test result array, useful for debugging, all values are set to zero as per the -/// [`default`](crate::io::Parameters::default) +/// [`default`](crate::python_bindings::Info::default()) /// ``` /// # use xiv_csolver_lib::python_bindings::{Info}; /// # use xiv_csolver_lib::python_bindings::SolverResult; -- 2.45.1 From 6ce1bc1e71394dff36a235a63cf8debf1185c793 Mon Sep 17 00:00:00 2001 From: beffroi Date: Thu, 25 May 2023 11:33:16 +0200 Subject: [PATCH 11/14] Adds a lot to the todo list, and adds a fast and wonky autoretry fix the gitignore and ignore file --- .gitignore | 1 + .ignore | 2 ++ Todo.md | 10 +++++++++- python/src/xiv_csolver/configs/recipes.yaml | 8 ++++++-- python/src/xiv_csolver/configs/users.yaml | 5 ++--- src/lib.rs | 22 ++++++++++++++++++--- src/python_bindings.rs | 2 +- 7 files changed, 40 insertions(+), 10 deletions(-) create mode 100644 .ignore diff --git a/.gitignore b/.gitignore index 04a3981..d19296a 100644 --- a/.gitignore +++ b/.gitignore @@ -163,3 +163,4 @@ dmypy.json # Cython debug symbols cython_debug/ +Cargo.lock \ No newline at end of file diff --git a/.ignore b/.ignore new file mode 100644 index 0000000..91cdc0f --- /dev/null +++ b/.ignore @@ -0,0 +1,2 @@ +*.ico +*.png \ No newline at end of file diff --git a/Todo.md b/Todo.md index 17d54e4..e4431bf 100644 --- a/Todo.md +++ b/Todo.md @@ -16,7 +16,15 @@ ### Features 🟩 (GUI) Refactor code 🟩 (GUI) Restore GUI state - + 🟩 (GUI) Bugfix the gui and clean it up + 🟩 (LIB) Restructure code, cleanup the mess + 🟩 (LIB) Have an autoretry + 🟩 (LIB) Have the autoretry be smart and/or threaded with interrupts + 🟩 (LIB) Cleanup the Toml to have one unique Food/Receipe/Craftsman with the gui + 🟩 (LIB) Be more aggressive with the mem optimisations + 🟩 (LIB) Have a thread interrupt mode for fast mode + 🟩 (LIB) Cleanup features (verbose doesn't really make sense) + # Roadmap ## v1.0.0 diff --git a/python/src/xiv_csolver/configs/recipes.yaml b/python/src/xiv_csolver/configs/recipes.yaml index ab50162..3dbdcd4 100644 --- a/python/src/xiv_csolver/configs/recipes.yaml +++ b/python/src/xiv_csolver/configs/recipes.yaml @@ -4,5 +4,9 @@ # If this seems super convoluted, and you'd rather it was just the three in-game values, know that me too. # Unfortunately that is how the craft system works in FFXIV. -Grade 7 Tincture of Strength: [5060, 12628, 70, 130, 115, 80, 70] -Grade 5 Strength Alkahest: [1300, 6200, 40, 123, 107, 100, 100] +Lvl88: [1650, 7000, 40, 128, 112, 100, 100] +Patch6.3_precrafts: [3696, 8200, 35, 130, 115, 80, 70] +Patch6.3_gear: [5060, 12628, 70, 130, 115, 80, 70] +Patch6.3_gatherer: [5720, 12900, 70, 130, 115, 80, 70] +Patch6.4_precrafts: [4488, 9090, 35, 130, 115, 80, 70] +Patch6.4_gear: [6600, 14040, 70, 130, 115, 80, 70] \ No newline at end of file diff --git a/python/src/xiv_csolver/configs/users.yaml b/python/src/xiv_csolver/configs/users.yaml index 02c7a0c..9b0c4ce 100644 --- a/python/src/xiv_csolver/configs/users.yaml +++ b/python/src/xiv_csolver/configs/users.yaml @@ -4,6 +4,5 @@ # The top line will always be selected by default -Vicky Crosia: [4021, 3933, 587] -Dandaedre Zadiel: [0, 0, 0] -Sekundes Dullahan: [2566, 2443, 522] +Vicky Crosia: [4021, 3987, 601] +Ladisla Kociann: [4021, 3951, 580] \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 02b7eb8..07d8792 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -168,9 +168,25 @@ pub fn solve_craft<'a>( let phase2_routes = arc_phase2_routes.lock().unwrap(); let nb_p2 = phase2_routes.len(); - // Drop on empty results + // Drop on empty results. // TODO: Retry automatically with better parameters if phase2_routes.len() == 0 { - return None; + // No solutions were found + if params.desperate { + // But everything was tested + return Some((Vec::::new(), Info::new(0, 0, false))); + } else { + // And not everything was tested + return solve_craft( + recipe, + stats, + Parameters { + depth: 11, + byregot_step: 6, + desperate: true, + ..params + }, + ); + } } // Print the results if verbose @@ -378,7 +394,7 @@ mod test { craft.recipe.progress = 0; let res = solve_craft(craft.recipe, craft.stats, craft.args); println!("{:?}", res); - assert!(res.is_none()); + assert!(res.unwrap().0.len() == 0); craft.recipe.progress = 100; craft.stats.max_cp = 0; diff --git a/src/python_bindings.rs b/src/python_bindings.rs index ea492a1..a2b4cd1 100644 --- a/src/python_bindings.rs +++ b/src/python_bindings.rs @@ -130,7 +130,7 @@ impl SolverResult { progression: craft.progression, quality: craft.quality, durability: craft.durability, - actions: actions, + actions, total_progression: craft.recipe.progress, total_quality: craft.recipe.quality, total_durability: craft.recipe.durability, -- 2.45.1 From 099ea3fcbaff4672a94cf33680d58e601d235c02 Mon Sep 17 00:00:00 2001 From: beffroi Date: Thu, 25 May 2023 11:51:58 +0200 Subject: [PATCH 12/14] "Fixes" a logging error by masking it --- python/src/xiv_csolver/modules/solver.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/python/src/xiv_csolver/modules/solver.py b/python/src/xiv_csolver/modules/solver.py index c4ec249..31c9d67 100644 --- a/python/src/xiv_csolver/modules/solver.py +++ b/python/src/xiv_csolver/modules/solver.py @@ -67,8 +67,9 @@ Remaining CP: {self.remaining_cp}""" if self.steps != 15 and self.steps != 29 and self.steps != 44: saved_lines.append('/echo Craft complete ! ') - else: - self.loggers.log(f'No completion message in macro because rotation is exactly {self.steps} steps.') + # else: + # TODO: Add a callback to the parent object for logging + # self.loggers.add_log(f'No completion message in macro because rotation is exactly {self.steps} steps.') if self.steps > 15: saved_lines.insert(14, '/echo Macro 1 complete ') @@ -170,5 +171,3 @@ class Solver: self.least_steps = Result(output, 'Least steps') return self.least_steps - - -- 2.45.1 From 89856681f79af13123b3e77ac7a1899ef77ae1df Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Thu, 25 May 2023 19:23:35 +0200 Subject: [PATCH 13/14] Test WinR --- python/src/xiv_csolver/modules/printer.py | 12 ++++++------ python/src/xiv_csolver/modules/solver.py | 10 +++++----- python/src/xiv_csolver/modules/translator.py | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/python/src/xiv_csolver/modules/printer.py b/python/src/xiv_csolver/modules/printer.py index 0db5795..ee9cfd8 100644 --- a/python/src/xiv_csolver/modules/printer.py +++ b/python/src/xiv_csolver/modules/printer.py @@ -33,18 +33,18 @@ class Printer: } def save_users(self, user_name: str = None, user_stats: list = None) -> dict: - output = self.help_text_dict['users'] + '\n\n' + output = self.help_text_dict['users'] + '\r\n\r\n' if user_name.title() == '': for user, stats in self.full_config.get_users_dict().items(): if user != ' ': - output += f'{user}: [{stats[0]}, {stats[1]}, {stats[2]}]\n' + output += f'{user}: [{stats[0]}, {stats[1]}, {stats[2]}]\r\n' else: self.full_config.get_users_dict()[user_name] = user_stats for user, stats in self.full_config.get_users_dict().items(): if user != ' ': - output += f'{user}: [{stats[0]}, {stats[1]}, {stats[2]}]\n' + output += f'{user}: [{stats[0]}, {stats[1]}, {stats[2]}]\r\n' self.print_users(output) return self.full_config.get_users_dict() @@ -55,18 +55,18 @@ class Printer: return True def save_recipe(self, recipe_name: str = None, recipe_basic_stats: list = None, recipe_advanced_stats: list = None) -> dict: - output = self.help_text_dict['recipe'] + '\n\n' + output = self.help_text_dict['recipe'] + '\r\n\r\n' if recipe_name.title() == '': for recipe, stats in self.full_config.get_recipes_dict().items(): if recipe != ' ': - output += f'{recipe}: [{stats[0]}, {stats[1]}, {stats[2]}, {stats[3]}, {stats[4]}, {stats[5]}, {stats[6]}]\n' + output += f'{recipe}: [{stats[0]}, {stats[1]}, {stats[2]}, {stats[3]}, {stats[4]}, {stats[5]}, {stats[6]}]\r\n' else: self.full_config.get_recipes_dict()[recipe_name] = recipe_basic_stats[:-1] + recipe_advanced_stats for recipe, stats in self.full_config.get_recipes_dict().items(): if recipe != ' ': - output += f'{recipe}: [{stats[0]}, {stats[1]}, {stats[2]}, {stats[3]}, {stats[4]}, {stats[5]}, {stats[6]}]\n' + output += f'{recipe}: [{stats[0]}, {stats[1]}, {stats[2]}, {stats[3]}, {stats[4]}, {stats[5]}, {stats[6]}]\r\n' self.print_recipe(output) return self.full_config.get_recipes_dict() diff --git a/python/src/xiv_csolver/modules/solver.py b/python/src/xiv_csolver/modules/solver.py index 31c9d67..347bca6 100644 --- a/python/src/xiv_csolver/modules/solver.py +++ b/python/src/xiv_csolver/modules/solver.py @@ -50,7 +50,7 @@ Remaining CP: {self.remaining_cp}""" saved_lines.append(line) for line in saved_lines: - justified_text += line + '\n' + justified_text += line + '\r\n' return justified_text[:-1] @@ -82,11 +82,11 @@ Remaining CP: {self.remaining_cp}""" for line in saved_lines: count += 1 if count < 16: - self.macro1 += line + '\n' + self.macro1 += line + '\r\n' elif 15 < count < 31: - self.macro2 += line + '\n' + self.macro2 += line + '\r\n' elif 30 < count < 46: - self.macro3 += line + '\n' + self.macro3 += line + '\r\n' self.macro1 = self.macro1[:-1] self.macro2 = self.macro2[:-1] @@ -155,7 +155,7 @@ class Solver: break if not done: - self.loggers.add_log('Could not find a rotation for a 50% Safe Margin.\n' + self.loggers.add_log('Could not find a rotation for a 50% Safe Margin.\r\n' ' Defaulting to Best Quality.') self.safe_50 = self.best_quality diff --git a/python/src/xiv_csolver/modules/translator.py b/python/src/xiv_csolver/modules/translator.py index 4897cf9..29c28f9 100644 --- a/python/src/xiv_csolver/modules/translator.py +++ b/python/src/xiv_csolver/modules/translator.py @@ -48,7 +48,7 @@ def translate_list(actions: list, lang: str): output.append(dictionary[action]) except KeyError: output.append(supported_languages["en"][action]) - loggers.log('Translation not found. Defaulting to English.\n' + loggers.log('Translation not found. Defaulting to English.\r\n' ' Macros will probably be broken because of this.') else: -- 2.45.1 From d0cacd765ce60cdeec161139c4fbacbb8543b54a Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Thu, 25 May 2023 19:58:30 +0200 Subject: [PATCH 14/14] v0.1.8 --- .bumpversion.cfg | 9 +++++++++ Cargo.toml | 2 +- pyproject.toml | 2 +- python/pyproject.toml | 2 +- 4 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 .bumpversion.cfg diff --git a/.bumpversion.cfg b/.bumpversion.cfg new file mode 100644 index 0000000..81a1ac1 --- /dev/null +++ b/.bumpversion.cfg @@ -0,0 +1,9 @@ +[bumpversion] +current_version = 0.1.8 +tag = True + +[bumpversion:file:python/pyproject.toml] + +[bumpversion:file:Cargo.toml] + +[bumpversion:file:pyproject.toml] diff --git a/Cargo.toml b/Cargo.toml index f0d1f67..35105e8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "xiv_csolver" -version = "0.1.7" +version = "0.1.8" edition = "2021" authors = ["谭俊健","Dandaedre","Vkyfox"] description = "Small XIV solver library in rust, with python and rust bindings" diff --git a/pyproject.toml b/pyproject.toml index 19a619f..8f57511 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.7" +version = "0.1.8" classifiers = [ "Programming Language :: Rust", "Programming Language :: Python :: Implementation :: CPython", diff --git a/python/pyproject.toml b/python/pyproject.toml index efed611..706bdf4 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -9,7 +9,7 @@ authors = [ {name="Dandaedre"}, ] requires-python = ">=3.7" -version = "0.1.7" +version = "0.1.8" license = {text="Mozilla Public License Version 2.0"} classifiers = [ "Programming Language :: Rust", -- 2.45.1