fix bug with handling early exits by breaking out of the correct loop
This commit is contained in:
parent
0ab1cf2200
commit
6e7d6213aa
|
@ -350,9 +350,9 @@ fn run_simulation(
|
||||||
|
|
||||||
let time_start = Instant::now();
|
let time_start = Instant::now();
|
||||||
|
|
||||||
while sim.lines_left() > 0 {
|
'playing: while sim.lines_left() > 0 {
|
||||||
if exit_early.load(atomic::Ordering::Relaxed) {
|
if exit_early.load(atomic::Ordering::Relaxed) {
|
||||||
break;
|
break 'playing;
|
||||||
}
|
}
|
||||||
|
|
||||||
// initialize the bot for the current state
|
// initialize the bot for the current state
|
||||||
|
@ -373,8 +373,11 @@ fn run_simulation(
|
||||||
bot.think_for(gas);
|
bot.think_for(gas);
|
||||||
|
|
||||||
// send a heartbeat back to the main thread to test if its still alive
|
// 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() {
|
if tx.send(Msg::Heartbeat(id)).is_err() {
|
||||||
break;
|
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,
|
// this should never fail unless something went wrong e.g. not enough iters,
|
||||||
// impossible board state, or buggy bot
|
// impossible board state, or buggy bot
|
||||||
tracing::warn!("gave up :( pieces={}, id={id}", sim.pieces());
|
tracing::warn!("gave up :( pieces={}, id={id}", sim.pieces());
|
||||||
break;
|
break 'playing;
|
||||||
};
|
};
|
||||||
|
|
||||||
sim.play(placement);
|
sim.play(placement);
|
||||||
|
@ -399,7 +402,7 @@ fn run_simulation(
|
||||||
time: Instant::now() - time_start,
|
time: Instant::now() - time_start,
|
||||||
};
|
};
|
||||||
if tx.send(Msg::Status(id, status.into())).is_err() {
|
if tx.send(Msg::Status(id, status.into())).is_err() {
|
||||||
break;
|
break 'playing;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue