Fix(clone) - removed a bunch of clones
This commit is contained in:
parent
35de543b06
commit
b1ebe772b9
|
|
@ -2,7 +2,8 @@
|
||||||
name = "xiv_craft_simulator"
|
name = "xiv_craft_simulator"
|
||||||
version = "0.1.2"
|
version = "0.1.2"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
author = "谭俊健 & Dandaedre"
|
authors = ["谭俊健","Dandaedre"]
|
||||||
|
description = "Small XIV solver library in rust, with python and rust bindings"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
|
|
||||||
45
src/libs.rs
45
src/libs.rs
|
|
@ -46,33 +46,31 @@ pub struct Args {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Solve the craft with given arguments
|
/// Solve the craft with given arguments
|
||||||
pub fn solve_craft<'a>() -> Option<Vec<String>>{
|
pub fn solve_craft<'a>(recipe: Recipe, stats: Stats, params: Parameters) -> Option<Vec<String>>{
|
||||||
let args = Args::parse();
|
// let params = Parameters{
|
||||||
let params = Parameters{
|
// depth: args.depth,
|
||||||
depth: args.depth,
|
// threads: args.threads,
|
||||||
threads: args.threads,
|
// verbose: args.verbose,
|
||||||
verbose: args.verbose,
|
// };
|
||||||
};
|
|
||||||
|
|
||||||
// Load the craft with given arguments
|
// // Load the craft with given arguments
|
||||||
let craft = load_config(&args.recipe_name, &args.file_name, &args.character_name,params);
|
// let craft = make_craft_from_config(&args.recipe_name, &args.file_name, &args.character_name,params);
|
||||||
|
let craft = Craft::new(recipe,stats,params);
|
||||||
// Start timer
|
// Start timer
|
||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
let craft = craft.clone();
|
|
||||||
|
|
||||||
// Start a threadpool
|
// Start a threadpool
|
||||||
let pool = ThreadPool::new(args.threads);
|
let pool = ThreadPool::new(params.threads);
|
||||||
|
|
||||||
if args.verbose>0{
|
if params.verbose>0{
|
||||||
println!("Solving...\n");
|
println!("Solving...\n");
|
||||||
println!("[P1] Starting phase 1...");
|
println!("[P1] Starting phase 1...");
|
||||||
}
|
}
|
||||||
let phase1_routes = generate_routes_phase1(craft.clone());
|
let phase1_routes = generate_routes_phase1(craft);
|
||||||
|
|
||||||
if args.verbose>0{
|
if params.verbose>0{
|
||||||
println!("[P1] Found {} routes, testing them all...",phase1_routes.len());
|
println!("[P1] Found {} routes, testing them all...",phase1_routes.len());
|
||||||
if args.verbose>1{
|
if params.verbose>1{
|
||||||
for r in &phase1_routes{
|
for r in &phase1_routes{
|
||||||
println!("[P1] {:?} p:{}% q:{}% c:{} d:{}",
|
println!("[P1] {:?} p:{}% q:{}% c:{} d:{}",
|
||||||
r.actions,
|
r.actions,
|
||||||
|
|
@ -102,10 +100,10 @@ pub fn solve_craft<'a>() -> Option<Vec<String>>{
|
||||||
let phase2_routes = arc_phase2_routes.lock().unwrap();
|
let phase2_routes = arc_phase2_routes.lock().unwrap();
|
||||||
|
|
||||||
// Print the results if verbose
|
// Print the results if verbose
|
||||||
if args.verbose>0{
|
if params.verbose>0{
|
||||||
println!("[P2] Found {} solutions, sorting",phase2_routes.len());
|
println!("[P2] Found {} solutions, sorting",phase2_routes.len());
|
||||||
|
|
||||||
if args.verbose>1{
|
if params.verbose>1{
|
||||||
for r in phase2_routes.iter(){
|
for r in phase2_routes.iter(){
|
||||||
println!("[P2] {:?} p:{}% q:{}% d:{}",
|
println!("[P2] {:?} p:{}% q:{}% d:{}",
|
||||||
r.actions,
|
r.actions,
|
||||||
|
|
@ -138,7 +136,7 @@ pub fn solve_craft<'a>() -> Option<Vec<String>>{
|
||||||
content.push("\"focusedSynthesis\"".to_string());
|
content.push("\"focusedSynthesis\"".to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
if args.verbose>2{
|
if params.verbose>2{
|
||||||
println!("[F] Top route {:?}",top_route);
|
println!("[F] Top route {:?}",top_route);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -159,7 +157,7 @@ pub fn solve_craft<'a>() -> Option<Vec<String>>{
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Load the config from args and make a craft from it
|
/// Load the config from args and make a craft from it
|
||||||
pub fn load_config<'a>(recipe_name: &str, file_name: &str, character_name: &str, params: Parameters) -> Craft<'a> {
|
pub fn load_from_config<'a>(recipe_name: &str, file_name: &str, character_name: &str) -> (Recipe,Stats) {
|
||||||
//read craft.toml
|
//read craft.toml
|
||||||
let config: toml::Value = toml::from_str(
|
let config: toml::Value = toml::from_str(
|
||||||
&std::fs::read_to_string(file_name)
|
&std::fs::read_to_string(file_name)
|
||||||
|
|
@ -221,10 +219,9 @@ pub fn load_config<'a>(recipe_name: &str, file_name: &str, character_name: &str,
|
||||||
character_name,file_name))
|
character_name,file_name))
|
||||||
.as_integer().expect("Can't convert max_cp as an integer") as u32,
|
.as_integer().expect("Can't convert max_cp as an integer") as u32,
|
||||||
};
|
};
|
||||||
let craft = Craft::new(recipe, stats, params);
|
(recipe,stats)
|
||||||
craft
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_craft_from_values(){
|
// fn make_craft_from_values(){
|
||||||
|
|
||||||
}
|
// }
|
||||||
17
src/main.rs
17
src/main.rs
|
|
@ -1,8 +1,10 @@
|
||||||
|
use crate::libs::Parameters;
|
||||||
|
use crate::libs::load_from_config;
|
||||||
|
use clap::Parser;
|
||||||
|
use crate::libs::Args;
|
||||||
use crate::craft::Craft;
|
use crate::craft::Craft;
|
||||||
use crate::libs::{Args,};
|
|
||||||
use crate::specs::{Recipe, Stats};
|
use crate::specs::{Recipe, Stats};
|
||||||
|
|
||||||
use clap::Parser;
|
|
||||||
|
|
||||||
mod specs;
|
mod specs;
|
||||||
pub mod action;
|
pub mod action;
|
||||||
|
|
@ -14,8 +16,15 @@ pub mod libs;
|
||||||
struct CustomError(String);
|
struct CustomError(String);
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
let args = Args::parse();
|
||||||
libs::solve_craft();
|
let params = Parameters{
|
||||||
|
depth: args.depth,
|
||||||
|
threads: args.threads,
|
||||||
|
verbose: args.verbose,
|
||||||
|
};
|
||||||
|
|
||||||
|
let (recipe,stats) = load_from_config(&args.recipe_name, &args.file_name, &args.character_name);
|
||||||
|
libs::solve_craft(recipe,stats,params);
|
||||||
|
|
||||||
()
|
()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ macro_rules! action_vec {
|
||||||
($($tt:expr),*) => { vec![ $(Some(&$tt),)*]};
|
($($tt:expr),*) => { vec![ $(Some(&$tt),)*]};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn next_action_picker_1<'a>(craft: Craft<'a>) -> Vec<Option<&'a Action>> {
|
pub fn next_action_picker_1<'a>(craft: & Craft<'a>) -> Vec<Option<&'a Action>> {
|
||||||
if craft.success != Success::Pending { return vec![None]; }
|
if craft.success != Success::Pending { return vec![None]; }
|
||||||
let mut available_actions = Vec::<Option<&'a Action>>::new();
|
let mut available_actions = Vec::<Option<&'a Action>>::new();
|
||||||
let mut forbidden_actions = Vec::<Option<&'a Action>>::new();
|
let mut forbidden_actions = Vec::<Option<&'a Action>>::new();
|
||||||
|
|
@ -43,18 +43,18 @@ pub fn next_action_picker_1<'a>(craft: Craft<'a>) -> Vec<Option<&'a Action>> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// println!("Av: {:?}",result_actions);
|
|
||||||
result_actions
|
result_actions
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn generate_routes_phase1<'a>(craft: Craft<'a>) -> Vec<Craft<'a>> {
|
pub fn generate_routes_phase1<'a>(craft: Craft<'a>) -> Vec<Craft<'a>> {
|
||||||
let mut queue = Vec::new();
|
let mut queue = Vec::new();
|
||||||
queue.push(craft.clone());
|
queue.push(craft);
|
||||||
let mut routes = Vec::new();
|
let mut routes = Vec::new();
|
||||||
while !queue.is_empty() {
|
while !queue.is_empty() {
|
||||||
let craft = queue.pop().unwrap();
|
let craft = queue.pop().unwrap();
|
||||||
for action in next_action_picker_1(craft.clone()) {
|
for action in next_action_picker_1(& craft) {
|
||||||
let mut craft = craft.clone();
|
let mut craft = craft.clone();
|
||||||
|
|
||||||
match action{
|
match action{
|
||||||
Some(a) => craft.run_action(a),
|
Some(a) => craft.run_action(a),
|
||||||
None => break,
|
None => break,
|
||||||
|
|
@ -88,7 +88,7 @@ pub fn generate_routes_phase1<'a>(craft: Craft<'a>) -> Vec<Craft<'a>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn next_action_phase_2<'a>(craft: Craft<'a>) -> Vec<Option<&'a Action>> {
|
pub fn next_action_phase_2<'a>(craft: & Craft<'a>) -> 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 available_actions = vec![&ACTIONS.basic_touch, &ACTIONS.prudent_touch, &ACTIONS.preparatory_touch];
|
||||||
|
|
@ -159,7 +159,7 @@ pub fn generate_routes_phase2<'a>(craft: Craft<'a>) -> Option<Craft<'a>> {
|
||||||
|
|
||||||
while !queue.is_empty() {
|
while !queue.is_empty() {
|
||||||
let _craft = queue.pop_front().unwrap();
|
let _craft = queue.pop_front().unwrap();
|
||||||
for action in next_action_phase_2(_craft.clone()) {
|
for action in next_action_phase_2(&_craft) {
|
||||||
if _craft.success != Success::Pending || action.is_none() || !action.unwrap().can_use(&_craft) {
|
if _craft.success != Success::Pending || action.is_none() || !action.unwrap().can_use(&_craft) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Reference in New Issue