From d46e2d8163ef14bdef24a6681aa33e3e2534278b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20K=C3=A4nner?= Date: Wed, 22 Jan 2025 00:59:55 +0100 Subject: [PATCH] correct food spawning algorithm --- battlesnake/src/types/simulation.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/battlesnake/src/types/simulation.rs b/battlesnake/src/types/simulation.rs index 2f1522b..89dfed7 100644 --- a/battlesnake/src/types/simulation.rs +++ b/battlesnake/src/types/simulation.rs @@ -459,6 +459,17 @@ impl Board { .iter() .all(|snake| self.coord_to_linear(snake.tail()) != *i) }) + .filter(|i| { + self.snakes + .iter() + .flat_map(|snake| { + let head = snake.head(); + enum_iterator::all::() + .map(move |direction| head.wrapping_apply(direction)) + .filter(|tile| self.is_in_bounds(*tile)) + }) + .all(|action| *i != self.coord_to_linear(action)) + }) .filter(|i| !self.food[*i]) .choose_multiple(&mut thread_rng(), needed_food); for index in food_spots {