Coverage to 69% #28
|
|
@ -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"
|
||||
path = "src/bin/xiv_csolver.rs"
|
||||
|
||||
|
|
|
|||
|
|
@ -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 --config imports_granularity=Module"
|
||||
]
|
||||
|
||||
[tasks.testcov]
|
||||
script_runner = "@shell"
|
||||
|
|
@ -29,7 +30,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/"
|
||||
]
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
||||

|
||||

|
||||
|
||||
### Basic RUST CLI Usage
|
||||
Everything is done through the regular cargo interface
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="20" role="img" aria-label="coverage: 48%">
|
||||
<title>coverage: 48%</title>
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="20" role="img" aria-label="coverage: 69%">
|
||||
<title>coverage: 69%</title>
|
||||
<linearGradient id="s" x2="0" y2="100%">
|
||||
<stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
|
||||
<stop offset="1" stop-opacity=".1"/>
|
||||
|
|
@ -16,8 +16,8 @@
|
|||
<g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110">
|
||||
<text aria-hidden="true" x="315" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="510">coverage</text>
|
||||
<text x="315" y="140" transform="scale(.1)" fill="#fff" textLength="510">coverage</text>
|
||||
<text aria-hidden="true" x="775" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="250">48%</text>
|
||||
<text x="775" y="140" transform="scale(.1)" fill="#fff" textLength="250">48%</text>
|
||||
<text aria-hidden="true" x="775" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="250">69%</text>
|
||||
<text x="775" y="140" transform="scale(.1)" fill="#fff" textLength="250">69%</text>
|
||||
</g>
|
||||
<script xmlns=""/>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
|
|
@ -1,13 +1,13 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="20" role="img" aria-label="coverage: 48%">
|
||||
<title>coverage: 48%</title>
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="20" role="img" aria-label="coverage: 69%">
|
||||
<title>coverage: 69%</title>
|
||||
<g shape-rendering="crispEdges">
|
||||
<rect width="61" height="20" fill="#555"/>
|
||||
<rect x="61" width="35" height="20" fill="#e05d44"/>
|
||||
</g>
|
||||
<g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110">
|
||||
<text x="315" y="140" transform="scale(.1)" fill="#fff" textLength="510">coverage</text>
|
||||
<text x="775" y="140" transform="scale(.1)" fill="#fff" textLength="250">48%</text>
|
||||
<text x="775" y="140" transform="scale(.1)" fill="#fff" textLength="250">69%</text>
|
||||
</g>
|
||||
<script xmlns=""/>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 712 B After Width: | Height: | Size: 712 B |
|
|
@ -1,13 +1,13 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink" width="142.5" height="28" role="img" aria-label="COVERAGE: 48%">
|
||||
<title>COVERAGE: 48%</title>
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink" width="142.5" height="28" role="img" aria-label="COVERAGE: 69%">
|
||||
<title>COVERAGE: 69%</title>
|
||||
<g shape-rendering="crispEdges">
|
||||
<rect width="91" height="28" fill="#555"/>
|
||||
<rect x="91" width="51.5" height="28" fill="#e05d44"/>
|
||||
</g>
|
||||
<g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="100">
|
||||
<text fill="#fff" x="455" y="175" transform="scale(.1)" textLength="670">COVERAGE</text>
|
||||
<text fill="#fff" x="1167.5" y="175" font-weight="bold" transform="scale(.1)" textLength="275">48%</text>
|
||||
<text fill="#fff" x="1167.5" y="175" font-weight="bold" transform="scale(.1)" textLength="275">69%</text>
|
||||
</g>
|
||||
<script xmlns=""/>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 739 B After Width: | Height: | Size: 739 B |
|
|
@ -1,6 +1,6 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="18" role="img" aria-label="coverage: 48%">
|
||||
<title>coverage: 48%</title>
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="18" role="img" aria-label="coverage: 69%">
|
||||
<title>coverage: 69%</title>
|
||||
<linearGradient id="s" x2="0" y2="100%">
|
||||
<stop offset="0" stop-color="#fff" stop-opacity=".7"/>
|
||||
<stop offset=".1" stop-color="#aaa" stop-opacity=".1"/>
|
||||
|
|
@ -18,8 +18,8 @@
|
|||
<g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110">
|
||||
<text aria-hidden="true" x="315" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="510">coverage</text>
|
||||
<text x="315" y="130" transform="scale(.1)" fill="#fff" textLength="510">coverage</text>
|
||||
<text aria-hidden="true" x="775" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="250">48%</text>
|
||||
<text x="775" y="130" transform="scale(.1)" fill="#fff" textLength="250">48%</text>
|
||||
<text aria-hidden="true" x="775" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="250">69%</text>
|
||||
<text x="775" y="130" transform="scale(.1)" fill="#fff" textLength="250">69%</text>
|
||||
</g>
|
||||
<script xmlns=""/>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
|
|
@ -1,6 +1,6 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink" width="99" height="20" role="img" aria-label="Coverage: 48%">
|
||||
<title>Coverage: 48%</title>
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink" width="99" height="20" role="img" aria-label="Coverage: 69%">
|
||||
<title>Coverage: 69%</title>
|
||||
<style>a:hover #llink{fill:url(#b);stroke:#ccc}a:hover #rlink{fill:#4183c4}</style>
|
||||
<linearGradient id="a" x2="0" y2="100%">
|
||||
<stop offset="0" stop-color="#fcfcfc" stop-opacity="0"/>
|
||||
|
|
@ -20,8 +20,8 @@
|
|||
<rect id="llink" stroke="#d5d5d5" fill="url(#a)" x=".5" y=".5" width="61" height="19" rx="2"/>
|
||||
<text aria-hidden="true" x="305" y="150" fill="#fff" transform="scale(.1)" textLength="510">Coverage</text>
|
||||
<text x="305" y="140" transform="scale(.1)" textLength="510">Coverage</text>
|
||||
<text aria-hidden="true" x="825" y="150" fill="#fff" transform="scale(.1)" textLength="230">48%</text>
|
||||
<text id="rlink" x="825" y="140" transform="scale(.1)" textLength="230">48%</text>
|
||||
<text aria-hidden="true" x="825" y="150" fill="#fff" transform="scale(.1)" textLength="230">69%</text>
|
||||
<text id="rlink" x="825" y="140" transform="scale(.1)" textLength="230">69%</text>
|
||||
</g>
|
||||
<script xmlns=""/>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
|
|
@ -10,4 +10,7 @@ classifiers = [
|
|||
"Programming Language :: Rust",
|
||||
"Programming Language :: Python :: Implementation :: CPython",
|
||||
"Programming Language :: Python :: Implementation :: PyPy",
|
||||
]
|
||||
]
|
||||
|
||||
[tool.maturin]
|
||||
features = ["pyo3/extension-module"]
|
||||
|
|
@ -0,0 +1 @@
|
|||
reorder_imports = true
|
||||
|
|
@ -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();
|
||||
|
|
@ -145,9 +144,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 +159,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 +419,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 +515,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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
//!
|
||||
|
|
|
|||
70
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};
|
||||
|
|
@ -211,14 +210,79 @@ 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)]
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
22
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<Option<Vec<SolverResult>>> {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
263
src/solver.rs
|
|
@ -16,7 +16,7 @@ pub fn next_action_picker_1<'a>(craft: &Craft<'a>) -> Vec<Option<&'a Action>> {
|
|||
let mut available_actions = Vec::<Option<&'a Action>>::new();
|
||||
let mut forbidden_actions = Vec::<Option<&'a Action>>::new();
|
||||
|
||||
// Optimize the first three steps for massive time save
|
||||
// Optimize the first four steps for massive time save
|
||||
if craft.step_count == 0 {
|
||||
return action_vec![ACTIONS.muscle_memory];
|
||||
}
|
||||
|
|
@ -26,11 +26,11 @@ pub fn next_action_picker_1<'a>(craft: &Craft<'a>) -> Vec<Option<&'a Action>> {
|
|||
|
||||
// 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 */
|
||||
])
|
||||
}
|
||||
|
||||
|
|
@ -61,10 +61,11 @@ pub fn next_action_picker_1<'a>(craft: &Craft<'a>) -> Vec<Option<&'a Action>> {
|
|||
// 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
|
||||
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])
|
||||
};
|
||||
|
||||
|
|
@ -191,6 +192,9 @@ pub fn next_action_phase_2<'a>(craft: &Craft<'a>) -> Vec<Option<&'a Action>> {
|
|||
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<Option<&Action>> = Vec::new();
|
||||
|
||||
for action in available_actions {
|
||||
|
|
@ -242,3 +246,254 @@ pub fn generate_routes_phase2<'a>(craft: Craft<'a>) -> Option<Vec<Craft<'a>>> {
|
|||
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!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||