Skip to content

Commit 139f39d

Browse files
committed
fix: fix potential crash issue when solving
1 parent ae422e0 commit 139f39d

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/solver/state.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,14 @@ impl State {
253253

254254
/// Calculates and returns the lower bound value for the current state.
255255
fn calculate_lower_bound(&self, solver: &Solver) -> usize {
256-
self.crate_positions
257-
.iter()
258-
.map(|crate_position| solver.lower_bounds()[&crate_position])
259-
.sum()
256+
let mut sum: usize = 0;
257+
for crate_position in &self.crate_positions {
258+
match solver.lower_bounds().get(&crate_position) {
259+
Some(lower_bound) => sum += lower_bound,
260+
None => return 10_000 - 1,
261+
}
262+
}
263+
sum
260264
}
261265

262266
/// Checks if a position can block the player's movement.

0 commit comments

Comments
 (0)