improve scoring system
All checks were successful
Build / build (push) Successful in 1m59s

This commit is contained in:
Max Känner 2025-01-22 01:33:45 +01:00
parent 32883b2a1b
commit 3f91660583

View File

@ -68,7 +68,7 @@ async fn get_move(request: Json<Request>) -> response::Json<Response> {
error!("My id is not in the simulation board");
0
});
info!("got move request: {board}");
debug!("got move request: {board}");
let actions = board.valid_actions(id).collect::<Vec<_>>();
if actions.len() <= 1 {
info!(
@ -95,9 +95,9 @@ async fn get_move(request: Json<Request>) -> response::Json<Response> {
}
},
_ => &|board: &Board| {
if !board.alive(id) || board.turn() > base_turns + u32::from(request.you.length) * 3
if board.num_snakes() <= 1 || board.turn() > base_turns + u32::from(request.you.length) * 3
{
Some(board.turn())
Some(u32::from(board.alive(id)))
} else {
None
}
@ -110,17 +110,18 @@ async fn get_move(request: Json<Request>) -> response::Json<Response> {
let mut board = board.clone();
let action = *actions.choose(&mut thread_rng()).unwrap_or(&Direction::Up);
board.next_turn(&[(id, action)]);
let turns = board.simulate_random(end_condition);
let score = board.simulate_random(end_condition);
let action_data = &mut action_data[usize::from(action)];
action_data.0 += turns - base_turns;
action_data.0 += score;
action_data.1 += 1;
total_simulations += 1;
}
debug!("action data: {action_data:?}");
let action = actions.into_iter().max_by_key(|action| {
let action_data = action_data[usize::from(*action)];
(action_data.0 / action_data.1, action_data.0 % action_data.1)
let action = actions.into_iter().max_by(|lhs, rhs| {
let lhs_data = action_data[usize::from(*lhs)];
let rhs_data = action_data[usize::from(*rhs)];
(u64::from(lhs_data.0) * u64::from(rhs_data.1)).cmp(&(u64::from(rhs_data.0) * u64::from(lhs_data.1)))
});
if let Some(action) = action {