fix bug with handling early exits by breaking out of the correct loop

This commit is contained in:
tali 2023-04-16 19:48:39 -04:00
parent 0ab1cf2200
commit 6e7d6213aa
1 changed files with 9 additions and 6 deletions

View File

@ -350,9 +350,9 @@ fn run_simulation(
let time_start = Instant::now();
while sim.lines_left() > 0 {
'playing: while sim.lines_left() > 0 {
if exit_early.load(atomic::Ordering::Relaxed) {
break;
break 'playing;
}
// initialize the bot for the current state
@ -373,8 +373,11 @@ fn run_simulation(
bot.think_for(gas);
// send a heartbeat back to the main thread to test if its still alive
if exit_early.load(atomic::Ordering::Relaxed) || tx.send(Msg::Heartbeat(id)).is_err() {
break;
if tx.send(Msg::Heartbeat(id)).is_err() {
break 'playing;
}
if exit_early.load(atomic::Ordering::Relaxed) {
break 'playing;
}
}
@ -382,7 +385,7 @@ fn run_simulation(
// this should never fail unless something went wrong e.g. not enough iters,
// impossible board state, or buggy bot
tracing::warn!("gave up :( pieces={}, id={id}", sim.pieces());
break;
break 'playing;
};
sim.play(placement);
@ -399,7 +402,7 @@ fn run_simulation(
time: Instant::now() - time_start,
};
if tx.send(Msg::Status(id, status.into())).is_err() {
break;
break 'playing;
}
}