correct food spawning algorithm

This commit is contained in:
Max Känner 2025-01-22 00:59:55 +01:00
parent 5b440bc7db
commit d46e2d8163

View File

@ -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::<Direction>()
.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 {