This commit is contained in:
parent
32883b2a1b
commit
3f91660583
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user