Skip to content

Commit

Permalink
Merge durability-restoring actions for step lower bound solver
Browse files Browse the repository at this point in the history
  • Loading branch information
KonaeAkira committed Sep 2, 2024
1 parent db21691 commit e1847e2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
32 changes: 25 additions & 7 deletions solvers/src/step_lower_bound_solver/solver.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,40 @@
use crate::utils::{ParetoFrontBuilder, ParetoFrontId, ParetoValue};
use simulator::{Condition, Settings, SimulationState};
use simulator::{Action, Condition, Settings, SimulationState};

use rustc_hash::FxHashMap as HashMap;

use super::state::ReducedState;

pub struct StepLowerBoundSolver {
settings: Settings,
bonus_durability_restore: i8,
solved_states: HashMap<ReducedState, ParetoFrontId>,
pareto_front_builder: ParetoFrontBuilder<u16, u16>,
}

impl StepLowerBoundSolver {
pub fn new(settings: Settings) -> Self {
pub fn new(mut settings: Settings) -> Self {
dbg!(std::mem::size_of::<ReducedState>());
dbg!(std::mem::align_of::<ReducedState>());
let mut bonus_durability_restore = 0;
if settings.allowed_actions.has(Action::Manipulation) {
bonus_durability_restore = std::cmp::max(bonus_durability_restore, 10);
}
if settings.allowed_actions.has(Action::ImmaculateMend) {
bonus_durability_restore =
std::cmp::max(bonus_durability_restore, settings.max_durability - 35);
}
if settings.allowed_actions.has(Action::Manipulation) {
settings.max_durability += 40;
}
Self {
settings: Settings {
allowed_actions: ReducedState::optimize_action_mask(settings.allowed_actions),
allowed_actions: ReducedState::optimize_action_mask(settings.allowed_actions)
.remove(Action::Manipulation)
.remove(Action::ImmaculateMend),
..settings
},
bonus_durability_restore,
solved_states: HashMap::default(),
pareto_front_builder: ParetoFrontBuilder::new(
settings.max_progress,
Expand Down Expand Up @@ -82,8 +97,11 @@ impl StepLowerBoundSolver {
{
let action_progress = new_full_state.progress;
let action_quality = new_full_state.quality;
let new_reduced_state =
let mut new_reduced_state =
ReducedState::from_state(new_full_state, reduced_state.steps_budget - 1);
if action == Action::MasterMend {
new_reduced_state.durability += self.bonus_durability_restore;
}
if new_reduced_state.steps_budget != 0 && !new_full_state.is_final(&self.settings) {
match self.solved_states.get(&new_reduced_state) {
Some(id) => self.pareto_front_builder.push_from_id(*id),
Expand Down Expand Up @@ -220,7 +238,7 @@ mod tests {
Action::Groundwork,
],
);
assert_eq!(result, 14);
assert_eq!(result, 15);
}

#[test]
Expand Down Expand Up @@ -250,7 +268,7 @@ mod tests {
Action::Groundwork,
],
);
assert_eq!(result, 14);
assert_eq!(result, 15);
}

#[test]
Expand Down Expand Up @@ -340,7 +358,7 @@ mod tests {
adversarial: false,
};
let result = solve(settings, &[Action::MuscleMemory]);
assert_eq!(result, 18);
assert_eq!(result, 19);
}

#[test]
Expand Down
18 changes: 5 additions & 13 deletions solvers/src/step_lower_bound_solver/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,13 @@ pub struct ReducedState {

impl ReducedState {
pub fn optimize_action_mask(mut action_mask: ActionMask) -> ActionMask {
action_mask = action_mask.remove(Action::TrainedPerfection);
// No CP cost so Observe is useless
action_mask = action_mask.remove(Action::Observe);
// Non-combo version is just as good as the combo version because there is no CP cost
action_mask = action_mask
.remove(Action::ComboStandardTouch)
.remove(Action::ComboAdvancedTouch);
// ImmaculateMend is always better than MasterMend because there is no CP cost
if action_mask.has(Action::ImmaculateMend) {
action_mask = action_mask.remove(Action::MasterMend);
}
// WasteNot2 is always better than WasteNot because there is no CP cost
if action_mask.has(Action::WasteNot2) {
action_mask = action_mask.remove(Action::WasteNot);
Expand All @@ -44,19 +41,14 @@ impl ReducedState {
0
};
let waste_not = if state.effects.waste_not() != 0 { 8 } else { 0 };
let manipulation = if state.effects.manipulation() != 0 {
8
} else {
0
};
let trained_perfection = match state.effects.trained_perfection() {
SingleUse::Unavailable => SingleUse::Available,
SingleUse::Available => SingleUse::Available,
SingleUse::Unavailable => SingleUse::Unavailable,
SingleUse::Available => SingleUse::Unavailable,
SingleUse::Active => SingleUse::Active,
};
Self {
steps_budget,
durability: state.durability,
durability: state.durability + 5 * state.effects.manipulation() as i8,
combo: match state.combo {
Combo::None => Combo::None,
Combo::SynthesisBegin => Combo::SynthesisBegin,
Expand All @@ -71,7 +63,7 @@ impl ReducedState {
.with_veneration(veneration)
.with_great_strides(great_strides)
.with_waste_not(waste_not)
.with_manipulation(manipulation)
.with_manipulation(0)
.with_trained_perfection(trained_perfection)
.with_guard(1),
}
Expand Down

0 comments on commit e1847e2

Please sign in to comment.