From 3f916605835544eea8fa97e5f7a99cc7175a4fac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20K=C3=A4nner?= Date: Wed, 22 Jan 2025 01:33:45 +0100 Subject: [PATCH] improve scoring system --- battlesnake/src/main.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/battlesnake/src/main.rs b/battlesnake/src/main.rs index aa60bcc..2fb265f 100644 --- a/battlesnake/src/main.rs +++ b/battlesnake/src/main.rs @@ -68,7 +68,7 @@ async fn get_move(request: Json) -> response::Json { 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::>(); if actions.len() <= 1 { info!( @@ -95,9 +95,9 @@ async fn get_move(request: Json) -> response::Json { } }, _ => &|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) -> response::Json { 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 {