Compare commits
No commits in common. "3d58e5331b2ebacbbeb3a837ff7c69f82c21945d" and "12276bc3544e5b5d45959ab4a8c536d1f20329ce" have entirely different histories.
3d58e5331b
...
12276bc354
@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
use core::f64;
|
use core::f64;
|
||||||
use std::{
|
use std::{
|
||||||
|
cell::Cell,
|
||||||
collections::{BTreeMap, HashMap},
|
collections::{BTreeMap, HashMap},
|
||||||
sync::{Arc, LazyLock, Mutex},
|
sync::{Arc, LazyLock, Mutex},
|
||||||
time::{Duration, Instant},
|
time::{Duration, Instant},
|
||||||
@ -41,9 +42,9 @@ pub fn info() -> Value {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||||
struct GameInfo {
|
struct GameInfo {
|
||||||
calculation_time: Arc<Mutex<Duration>>,
|
calculation_time: Cell<Duration>,
|
||||||
token_mapping: Arc<BTreeMap<String, SnakeToken>>,
|
token_mapping: Arc<BTreeMap<String, SnakeToken>>,
|
||||||
my_token: SnakeToken,
|
my_token: SnakeToken,
|
||||||
}
|
}
|
||||||
@ -63,9 +64,7 @@ pub fn start(game: &Game, _turn: i32, board: &Board, you: &Battlesnake) {
|
|||||||
game_infos.insert(
|
game_infos.insert(
|
||||||
(game.id.clone(), you.id.clone()),
|
(game.id.clone(), you.id.clone()),
|
||||||
GameInfo {
|
GameInfo {
|
||||||
calculation_time: Arc::new(Mutex::new(Duration::from_millis(
|
calculation_time: Cell::new(Duration::from_millis(50)),
|
||||||
u64::from(game.timeout) / 2,
|
|
||||||
))),
|
|
||||||
token_mapping,
|
token_mapping,
|
||||||
my_token,
|
my_token,
|
||||||
},
|
},
|
||||||
@ -95,9 +94,7 @@ pub fn get_move(game: &Game, turn: i32, board: &Board, you: &Battlesnake) -> Opt
|
|||||||
let token_mapping = Arc::new(SnakeToken::from_board(board));
|
let token_mapping = Arc::new(SnakeToken::from_board(board));
|
||||||
let my_token = token_mapping[&you.id];
|
let my_token = token_mapping[&you.id];
|
||||||
GameInfo {
|
GameInfo {
|
||||||
calculation_time: Arc::new(Mutex::new(Duration::from_millis(
|
calculation_time: Cell::new(Duration::from_millis(50)),
|
||||||
u64::from(game.timeout) / 2,
|
|
||||||
))),
|
|
||||||
token_mapping,
|
token_mapping,
|
||||||
my_token,
|
my_token,
|
||||||
}
|
}
|
||||||
@ -120,25 +117,15 @@ pub fn get_move(game: &Game, turn: i32, board: &Board, you: &Battlesnake) -> Opt
|
|||||||
}
|
}
|
||||||
|
|
||||||
// do some latency compensation
|
// do some latency compensation
|
||||||
let deadline = start
|
game_info.calculation_time.set(
|
||||||
+ game_info.calculation_time.lock().map_or_else(
|
game_info.calculation_time.get()
|
||||||
|_| Duration::from_millis(u64::from(game.timeout) / 2),
|
|
||||||
|mut guard| {
|
|
||||||
let new_duration = *guard
|
|
||||||
+ Duration::from_millis(
|
+ Duration::from_millis(
|
||||||
u64::from(game.timeout) * 7 / 8
|
u64::from(
|
||||||
- you
|
game.timeout * 3 / 4 - you.latency.parse().unwrap_or(game.timeout * 3 / 4),
|
||||||
.latency
|
) / 3,
|
||||||
.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 deadline = start + game_info.calculation_time.get();
|
||||||
|
|
||||||
let mut tree = Node::default();
|
let mut tree = Node::default();
|
||||||
|
|
||||||
|
@ -252,7 +252,6 @@ fn run_production(port: u16) -> Result<Child, DynError> {
|
|||||||
format!("ROCKET_PORT={}", port).as_str(),
|
format!("ROCKET_PORT={}", port).as_str(),
|
||||||
"--network=host",
|
"--network=host",
|
||||||
"-i",
|
"-i",
|
||||||
"--rm",
|
|
||||||
"docker.mkaenner.de/snake:latest",
|
"docker.mkaenner.de/snake:latest",
|
||||||
])
|
])
|
||||||
.spawn()?;
|
.spawn()?;
|
||||||
|
Loading…
Reference in New Issue
Block a user