Added a lot of comments and tweaks, no real progress tho

This commit is contained in:
Dandaedre 2023-02-18 07:46:43 +01:00
parent 7aa09aa347
commit 32f7ae7aef
7 changed files with 145 additions and 57 deletions

2
Cargo.lock generated
View File

@ -372,7 +372,7 @@ checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd"
[[package]]
name = "xiv_craft_simulator"
version = "0.1.1"
version = "0.1.2"
dependencies = [
"clap",
"lazy_static",

View File

@ -1,7 +1,8 @@
[package]
name = "xiv_craft_simulator"
version = "0.1.1"
version = "0.1.2"
edition = "2021"
author = "谭俊健 & Dandaedre"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@ -13,4 +14,6 @@ toml = "0.5.9"
clap = {version = "4.1.6", features = ["derive"]}
[profile.release]
panic = 'abort'
panic = 'abort'
opt-level = 3
lto = true

View File

@ -15,22 +15,16 @@ Note: The recipe data can be retrieved from [FFXIV Crafting Optimizer](https://y
with checking of **Custom Recipe** after selecting the recipe.
![img.png](img.png)
```toml
[recipe]
[default_recipe]
durability = 70
progress = 5060
quality = 12628
progress_divider = 130 # as Progress Difficulty
quality_divider = 115 # as Quality Difficulty
progress_modifier = 80 # as Extra Progress Difficulty
quality_modifier = 70 # as Extra Quality Difficulty
quality = 10920
progress_divider = 130
quality_divider = 115
progress_modifier = 80
quality_modifier = 70
[stats] # including food and potion
craftsmanship = 3745
control = 3636
max_cp = 670
[recipe]
[recipe_35]
durability = 35
progress = 3696
quality = 8200
@ -39,7 +33,7 @@ quality_divider = 115
progress_modifier = 80
quality_modifier = 70
[stats]
[default_character]
craftsmanship = 4041
control = 3959
max_cp = 602

View File

@ -1,13 +1,31 @@
[default_recipe]
durability = 70
progress = 5060
progress = 3900
quality = 10920
progress_divider = 130
quality_divider = 115
progress_modifier = 80
quality_modifier = 70
[recipe_35]
[two_star_70]
durability = 70
progress = 3900
quality = 10920
progress_divider = 130
quality_divider = 115
progress_modifier = 80
quality_modifier = 70
[three_star_70]
durability = 70
progress = 5060
quality = 12628
progress_divider = 130
quality_divider = 115
progress_modifier = 80
quality_modifier = 70
[three_star_35]
durability = 35
progress = 3696
quality = 8200
@ -16,7 +34,22 @@ quality_divider = 115
progress_modifier = 80
quality_modifier = 70
[two_star_35]
durability = 35
progress = 2925
quality = 7800
progress_divider = 130
quality_divider = 115
progress_modifier = 80
quality_modifier = 70
[default_character]
craftsmanship = 4041
control = 3959
max_cp = 602
max_cp = 602
[cero]
craftsmanship = 1818
control = 1983
max_cp = 467
_max_cp = 600

View File

@ -2,6 +2,8 @@ use std::fmt::{Debug, Formatter,Display};
use crate::action::Action;
use crate::specs::{Buff, BuffState, Recipe, Stats, Success};
#[derive(Clone)]
pub struct Craft<'a> {
pub recipe: &'a Recipe,
@ -14,10 +16,11 @@ pub struct Craft<'a> {
pub cp: i32,
pub success: Success,
pub actions: Vec<&'a Action>,
pub depth: u32,
}
impl<'a> Craft<'a> {
pub fn new(recipe: &'a Recipe, stats: &'a Stats) -> Craft<'a> {
pub fn new(recipe: &'a Recipe, stats: &'a Stats, depth: &'a u32) -> Craft<'a> {
Self {
recipe,
stats,
@ -29,6 +32,7 @@ impl<'a> Craft<'a> {
cp: stats.max_cp as i32,
success: Success::Pending,
actions: Vec::new(),
depth: *depth,
}
}

View File

@ -11,18 +11,25 @@ mod solver;
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Args {
/// Name of the receipe
#[arg(short, long, default_value_t = String::from("default_recipe"))]
recipe_name: String,
/// Name of the receipe
#[arg(short, long, default_value_t = String::from("default_recipe"))]
recipe_name: String,
/// Name of the character
#[arg(short, long, default_value_t = String::from("default_character"))]
character_name: String,
/// Name of the character
#[arg(short, long, default_value_t = String::from("default_character"))]
character_name: String,
/// The ml file name
/// The ml file name
#[arg(short, long, default_value_t = String::from("craft.toml"))]
file_name: String,
/// The verbose flag
#[arg(short, long, action = clap::ArgAction::Count)]
verbose: u8,
/// The depth of the first pass
#[arg(short, long, default_value_t = 8)]
depth: u32,
}
#[derive(Debug)]
@ -94,16 +101,27 @@ fn main() {
&args.character_name,&args.file_name))
.as_integer().expect("Can't convert max_cp as an integer") as u32,
};
let craft = Craft::new(&recipe, &stats);
println!("Solving...\n");
println!("[P1] Starting phase 1...");
let phase1_routes = generate_routes_phase1(craft);
println!("[P1] Found {} routes, testing them all...",phase1_routes.len());
for r in &phase1_routes{
println!("[P1] {:?}",r);
};
let craft = Craft::new(&recipe, &stats, &args.depth);
// panic!("");
if args.verbose>0{
println!("Solving...\n");
println!("[P1] Starting phase 1...");
}
let phase1_routes = generate_routes_phase1(craft);
if args.verbose>1{
println!("[P1] Found {} routes, testing them all...",phase1_routes.len());
for r in &phase1_routes{
println!("[P1] {:?} p:{}% q:{}% c:{} d:{}",
r.actions,
r.progression * 100 / r.recipe.progress,
r.quality * 100 / r.recipe.quality,
r.cp,
r.durability,
);
// println!("[P1] {}",r);
};
}
let mut phase2_routes = Vec::new();
for route in phase1_routes {
@ -111,16 +129,26 @@ fn main() {
phase2_routes.push(route);
}
}
// println!("{:?}", phase2_routes);
// let top_route = match phase2_routes.iter().max_by_key(|route| route.quality) {
// Some(top) => top,
// None => return,
// };
println!("{:?}", phase2_routes);
let top_route = match phase2_routes.iter().min_by_key(|route| route.step_count) {
if args.verbose>1{
println!("[P2] Found {} solutions, sorting",phase2_routes.len());
for r in &phase2_routes{
println!("[P2] {:?} p:{}% q:{}% d:{}",
r.actions,
r.progression * 100 / r.recipe.progress,
r.quality * 100 / r.recipe.quality,
r.durability);
};
}
let top_route = match phase2_routes.iter().max_by_key(|route| route.quality) {
Some(top) => top,
None => return,
};
// let top_route = match phase2_routes.iter().min_by_key(|route| route.step_count) {
// Some(top) => top,
// None => return,
// };
let mut content = (&top_route.actions)
.iter()
@ -135,9 +163,15 @@ fn main() {
content.push("\"observe\"".to_string());
content.push("\"focusedSynthesis\"".to_string());
}
if args.verbose>2{
println!("[F] Top route {:?}",top_route);
}
println!("Quality: {}/{}", top_route.quality, top_route.recipe.quality);
println!("\t[{}]", content.join(", "));
// wait for enter
// Wait for enter
println!();
println!("Press enter to exit...");
let mut input = String::new();

View File

@ -11,17 +11,29 @@ pub fn next_action_picker_1<'a>(craft: &Craft) -> Vec<Option<&'a Action>> {
if craft.success != Success::Pending { return vec![None]; }
let mut available_actions = Vec::<Option<&'a Action>>::new();
let mut forbidden_actions = Vec::<Option<&'a Action>>::new();
// Optimize the first three steps for massive time save
if craft.step_count == 0 { return action_vec![ACTIONS.muscle_memory]; }
if craft.step_count == 1 { return action_vec![ACTIONS.manipulation]; }
// Prune some actions if not requested by --long
if craft.step_count == 2 { return action_vec![ACTIONS.waste_not, ACTIONS.waste_not_ii, ACTIONS.veneration]; }
if craft.step_count == 3 { available_actions.append(&mut action_vec![ACTIONS.waste_not_ii,ACTIONS.waste_not]) }
// Forbidding actions depending on buffs
// Groundwork mostly for wn / mm
if craft.buffs.waste_not > 0 || craft.buffs.muscle_memory > 0 { available_actions.append(&mut action_vec![ACTIONS.groundwork]) }
// Forbidding actions depending on buffs
if craft.buffs.muscle_memory > 0 { forbidden_actions.append(&mut action_vec![ACTIONS.basic_synthesis,ACTIONS.careful_synthesis,ACTIONS.prudent_synthesis,ACTIONS.delicate_synthesis]) }
if craft.buffs.waste_not > 0 { forbidden_actions.append(&mut action_vec![ACTIONS.prudent_synthesis]) }
available_actions.append(&mut action_vec![ACTIONS.basic_synthesis,ACTIONS.careful_synthesis,ACTIONS.prudent_synthesis,ACTIONS.delicate_synthesis]);
// ACTIONS.groundwork for the --pls
// available_actions.append(&mut action_vec![ACTIONS.groundwork]);
// For long first run
if craft.step_count > 8 {available_actions.append(&mut action_vec![ACTIONS.waste_not_ii, ACTIONS.waste_not])};
// Pruning the actions with the forbidden ones
let mut result_actions = Vec::<Option<&'a Action>>::new();
for action in available_actions {
@ -29,43 +41,47 @@ pub fn next_action_picker_1<'a>(craft: &Craft) -> Vec<Option<&'a Action>> {
result_actions.push(action);
}
}
// println!("Av: {:?}",result_actions);
result_actions
}
pub fn generate_routes_phase1(craft: Craft) -> Vec<Craft> {
let mut queue = Vec::new();
// let mut nb=0;
// if craft.verbose>2 {print!("#")};
queue.push(craft);
let mut routes = Vec::new();
while !queue.is_empty() {
let craft = queue.pop().unwrap();
for action in next_action_picker_1(&craft) {
let mut craft = craft.clone();
// println!("Iter {} : {:?}",nb,action);
// nb+=1;
match action{
Some(a) => craft.run_action(a),
None => break,
};
// craft.run_action(action.unwrap());
let remaining_prog = (craft.recipe.progress as f32 - craft.progression as f32) / craft.get_base_progression() as f32;
if remaining_prog <= 2.0 {
if remaining_prog <= 0.0 {
continue;
} else if 0.0 < remaining_prog && remaining_prog <= 1.2 {
// pass
// pass // Will finish with basicSynth2 (free)
} else if 1.2 < remaining_prog && remaining_prog <= 1.2 {
craft.cp -= 7;
craft.cp -= 7; // Will finish with carefulSynthesis (7cp)
} else if 1.2 < remaining_prog && remaining_prog <= 2.0 {
craft.cp -= 12;
craft.cp -= 12; // Will finish with observe+focusedSynthesis (12cp)
}
craft.durability -= 10;
craft.durability -= 10; // Save the final step, since we always aim to end with -5dur, it doesn't matter
routes.push(craft);
continue;
}
if craft.step_count < 8 { queue.push(craft); }
// Keep adding initial routes with several pass, we must be able to finish in one step
// 8 Seemed to be a good initial guess with enouth to use a good amount of WN / WNII to get close
// A higher value will yield more initial guesses with minimal benefits
// A lover value will yield less initial guesses and might spent too much CP to get to the required progression
// TODO: Pass a flag to get more attempts
if craft.step_count < craft.depth { queue.push(craft); }
}
}
routes
@ -73,7 +89,7 @@ pub fn generate_routes_phase1(craft: Craft) -> Vec<Craft> {
pub fn next_action_phase_2<'a>(craft: &Craft) -> Vec<Option<&'a Action>> {
println!("State of craft {:}",craft);
// println!("State of craft {:}",craft);
let mut available_actions = vec![&ACTIONS.basic_touch, &ACTIONS.prudent_touch, &ACTIONS.preparatory_touch];
let mut forbidden_actions = Vec::new();
@ -134,8 +150,12 @@ pub fn next_action_phase_2<'a>(craft: &Craft) -> Vec<Option<&'a Action>> {
pub fn generate_routes_phase2(craft: Craft) -> Option<Craft> {
let mut queue = VecDeque::new();
// println!("{}", ACTIONS.careful_synthesis.can_use(&craft));
let mut top_route: Option<Craft> = Some(craft.clone()); // Default route, no hq on that one
queue.push_back(craft);
let mut top_route: Option<Craft> = None;
while !queue.is_empty() {
let _craft = queue.pop_front().unwrap();
for action in next_action_phase_2(&_craft) {