diff --git a/bench/src/main.rs b/bench/src/main.rs index a6b106a..7a47e90 100644 --- a/bench/src/main.rs +++ b/bench/src/main.rs @@ -35,7 +35,8 @@ fn main() { let optimiser = Optimiser::new(&config, initial_set, &items).unwrap(); let final_state = optimiser.optimise().unwrap(); - println!("Set Energy: {}", -final_state.energy(&config, &items)); + let sets = final_state.sets(&items); + println!("Set Energy: {}", -final_state.energy(&config, &sets)); } } diff --git a/dofus_set/src/dofus_set.rs b/dofus_set/src/dofus_set.rs index 5fd3ee8..45c117b 100644 --- a/dofus_set/src/dofus_set.rs +++ b/dofus_set/src/dofus_set.rs @@ -120,11 +120,13 @@ impl State { fn valid(&self, config: &config::Config, items: &Items, leniency: i32) -> bool { let mut total_set_bonuses = 0; - for set_bonus in self.sets(items) { + let sets = self.sets(items); + + for set_bonus in &sets { total_set_bonuses += set_bonus.number_of_items - 1; } - let stats = self.stats(config, items); + let stats = self.stats(config, &sets); for item in self.items(items) { if item.level > config.max_level { @@ -165,8 +167,12 @@ impl State { true } - pub fn energy(&self, config: &config::Config, items: &Items) -> f64 { - let stats = self.stats(config, items); + pub fn energy( + &self, + config: &config::Config, + sets: &heapless::Vec, MAX_SETS>, + ) -> f64 { + let stats = self.stats(config, sets); // need to take the negative due to being a minimiser let energy_non_element = stats .iter() @@ -232,10 +238,14 @@ impl State { self.cached_totals += &item.stats; } - pub fn stats(&self, config: &config::Config, items: &Items) -> Characteristic { + pub fn stats( + &self, + config: &config::Config, + sets: &heapless::Vec, MAX_SETS>, + ) -> Characteristic { let mut stat = self.cached_totals.clone(); - for set_bonus in self.sets(items) { + for set_bonus in sets { stat += set_bonus.bonus; } @@ -397,7 +407,8 @@ impl<'a> anneal::Anneal for Optimiser<'a> { } fn energy(&self, state: &State) -> f64 { - state.energy(self.config, self.items) + let sets = state.sets(self.items); + state.energy(self.config, &sets) } fn temperature(&self, iteration: f64, _energy: f64) -> f64 { diff --git a/dofus_set/src/main.rs b/dofus_set/src/main.rs index cd00a0c..3922487 100644 --- a/dofus_set/src/main.rs +++ b/dofus_set/src/main.rs @@ -35,7 +35,8 @@ fn main() { let final_state = optimiser.optimise().unwrap(); print_state(&final_state, &config, &items); - println!("Set Energy: {}", -final_state.energy(&config, &items)); + let sets = final_state.sets(&items); + println!("Set Energy: {}", -final_state.energy(&config, &sets)); } pub fn print_state(state: &State, config: &config::Config, items: &Items) { @@ -53,7 +54,8 @@ pub fn print_state(state: &State, config: &config::Config, items: &Items) { } println!("Stats"); println!("-----------------------------"); - print_stats(&state.stats(config, items)); + let sets = state.sets(items); + print_stats(&state.stats(config, &sets)); println!("\nSet bonuses"); println!("-----------------------------"); for set_bonus in state.sets(items) { diff --git a/server/src/main.rs b/server/src/main.rs index cae42e8..7c1bd75 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -111,8 +111,9 @@ fn create_optimised_set( let final_state = optimiser.optimise()?; - let set_bonuses = final_state - .sets(items) + let sets = final_state.sets(items); + + let set_bonuses = sets .iter() .map(|set| OptimiseResponseSetBonus { name: set.name.to_owned(), @@ -122,8 +123,8 @@ fn create_optimised_set( .collect(); Ok(OptimiseResponse { - energy: -final_state.energy(&dofus_set_config, items), - overall_characteristics: final_state.stats(&dofus_set_config, items).clone(), + energy: -final_state.energy(&dofus_set_config, &sets), + overall_characteristics: final_state.stats(&dofus_set_config, &sets).clone(), items: final_state .set() .map(|idx| {