Fix self-nibbling
This commit is contained in:
@ -96,7 +96,15 @@ impl Map {
|
||||
match tile {
|
||||
Tile::Empty { coordinate: _ } => true,
|
||||
Tile::Food { coordinate: _ } => true,
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
||||
pub fn tile_is_nibbleable_snake(&self, nibbler: &SnakeInfo, coordinate: (i32,i32)) -> bool {
|
||||
let tile = self.get_tile_at(coordinate);
|
||||
match tile {
|
||||
Tile::SnakeBody { coordinate: _, snake } => {
|
||||
snake.id != nibbler.id &&
|
||||
snake.tailProtectedForGameTicks == 0 &&
|
||||
coordinate == translate_position(*snake.positions.last().unwrap(), self.width)
|
||||
},
|
||||
@ -108,7 +116,9 @@ impl Map {
|
||||
let (xd,yd) = direction.as_movement_delta();
|
||||
let (x,y) = util::translate_position(snake.positions[0], self.width);
|
||||
|
||||
self.is_tile_available_for_movement((x+xd,y+yd))
|
||||
let tile_coord = (x+xd,y+yd);
|
||||
self.is_tile_available_for_movement(tile_coord) ||
|
||||
self.tile_is_nibbleable_snake(snake, (tile_coord))
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
|
||||
Reference in New Issue
Block a user