diff --git a/tidepool/src/main.rs b/tidepool/src/main.rs index 30e320a..7871063 100644 --- a/tidepool/src/main.rs +++ b/tidepool/src/main.rs @@ -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; } }