remove unused code

This commit is contained in:
Max Känner 2024-10-03 04:27:20 +02:00
parent 6123ca177e
commit 4afbb37db7

View File

@ -24,73 +24,9 @@ use serde_json::{json, Value};
use crate::{
simulation::{self, SnakeToken},
Action, Battlesnake, Board, Direction, Game, MAX_HEALTH,
Action, Battlesnake, Board, Direction, Game,
};
impl Battlesnake {
fn possible_actions_without_heads<'a>(
&'a self,
game: &'a Game,
board: &'a Board,
) -> impl Iterator<Item = Direction> + 'a {
enum_iterator::all::<Direction>()
.filter(|direction| {
// filter out directions that would go outside the field
let target = self.head.move_to(*direction);
(0..board.width).contains(&target.x) && (0..board.height).contains(&target.y)
})
.filter(|direction| {
let target = self.head.move_to(*direction);
// don't collide with any snake
!board
.snakes
.iter()
.filter(|snake| {
// filter out snakes that are in our squad if body collisions are allowed
!(game.ruleset.settings.squad.allow_body_collisions
&& self.squad == snake.squad
&& self.id != snake.id)
})
.flat_map(|snake| {
// get all coordinates of the snake body. The tail of the body can be ignored
// if the snake hasn't just eaten, as it will move out of the way
let has_eaten = snake.health == MAX_HEALTH;
snake.body[..snake.body.len() - usize::from(!has_eaten)].iter()
})
.any(|&coord| coord == target)
})
}
#[must_use]
pub fn possible_actions(&self, game: &Game, board: &Board) -> Vec<Direction> {
self.possible_actions_without_heads(game, board)
.filter(|direction| {
// don't go into spots where a bigger snake must go
let target = self.head.move_to(*direction);
!board
.snakes
.iter()
.filter(|snake| {
// The other snake must be bigger than we are
snake.length > self.length
})
.filter_map(|snake| {
// get all snakes movement options
let actions = snake
.possible_actions_without_heads(game, board)
.collect::<Vec<_>>();
// only snakes that have a single option
match actions[..] {
[direction] => Some(snake.head.move_to(direction)),
_ => None,
}
})
.any(|coord| coord == target)
})
.collect()
}
}
// info is called when you create your Battlesnake on play.battlesnake.com
// and controls your Battlesnake's appearance
// TIP: If you open your Battlesnake URL in a browser you should see this data