correct food spawning algorithm
This commit is contained in:
parent
5b440bc7db
commit
d46e2d8163
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user