fix latency calculation
standard Duration can't go negative
This commit is contained in:
parent
5cb9c3d202
commit
c5b0319ac4
@ -125,18 +125,16 @@ pub fn get_move(game: &Game, turn: i32, board: &Board, you: &Battlesnake) -> Opt
|
|||||||
+ game_info.calculation_time.lock().map_or_else(
|
+ game_info.calculation_time.lock().map_or_else(
|
||||||
|_| Duration::from_millis(u64::from(game.timeout) / 2),
|
|_| Duration::from_millis(u64::from(game.timeout) / 2),
|
||||||
|mut guard| {
|
|mut guard| {
|
||||||
let new_duration = *guard
|
let target_latency = game.timeout * 3 / 4;
|
||||||
+ Duration::from_millis(
|
let latency = you.latency.parse().unwrap_or_else(|e| {
|
||||||
u64::from(game.timeout) * 7 / 8
|
error!("Unable to parse latency: {e}");
|
||||||
- you
|
target_latency
|
||||||
.latency
|
});
|
||||||
.parse()
|
let last_computation_time = u32::try_from(guard.as_millis()).unwrap_or(0);
|
||||||
.unwrap_or(u64::from(game.timeout) * 7 / 8),
|
let computation_time =
|
||||||
);
|
(last_computation_time + target_latency).saturating_sub(latency);
|
||||||
*guard = new_duration.clamp(
|
*guard =
|
||||||
Duration::from_millis(1),
|
Duration::from_millis(u64::from(computation_time.clamp(1, target_latency)));
|
||||||
Duration::from_millis(u64::from(game.timeout) * 7 / 8),
|
|
||||||
);
|
|
||||||
*guard
|
*guard
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user