fix computation time calculation

This commit is contained in:
Max Känner 2024-10-05 18:32:10 +02:00
parent 5cb9c3d202
commit da8edf92d6

View File

@ -121,25 +121,14 @@ pub fn get_move(game: &Game, turn: i32, board: &Board, you: &Battlesnake) -> Opt
} }
// do some latency compensation // do some latency compensation
let deadline = start let latency = you.latency.parse().unwrap_or_else(|e| {
+ game_info.calculation_time.lock().map_or_else( error!("Unable to parse latency: {e}");
|_| Duration::from_millis(u64::from(game.timeout) / 2), game.timeout
|mut guard| { }) + 100;
let new_duration = *guard let target_latency = game.timeout * 3 / 4;
+ Duration::from_millis( let computation_time = target_latency - latency;
u64::from(game.timeout) * 7 / 8 let deadline =
- you start + Duration::from_millis(u64::from(computation_time.clamp(1, game.timeout)));
.latency
.parse()
.unwrap_or(u64::from(game.timeout) * 7 / 8),
);
*guard = new_duration.clamp(
Duration::from_millis(1),
Duration::from_millis(u64::from(game.timeout) * 7 / 8),
);
*guard
},
);
let mut tree = Node::default(); let mut tree = Node::default();