add constrictor mode

This commit is contained in:
Max Känner 2024-10-03 06:09:06 +02:00
parent 6bcce03d2a
commit 075a08a78c
2 changed files with 7 additions and 1 deletions

View File

@ -109,6 +109,7 @@ pub fn get_move(game: &Game, turn: i32, board: &Board, you: &Battlesnake) -> Opt
turn,
game.ruleset.settings.food_spawn_chance,
game.ruleset.settings.minimum_food,
game.ruleset.name == "constrictor",
);
let possible_actions = board.possible_actions().get(&game_info.my_token).cloned()?;
if possible_actions.len() == 1 {

View File

@ -46,6 +46,9 @@ pub struct Board {
min_food: u8,
/// Alive snakes
snakes: BTreeMap<SnakeToken, Battlesnake>,
/// True when playing constrictor mode. In this mode the snakes don't loose health and grow
/// every turn
constrictor: bool,
}
impl Board {
@ -55,6 +58,7 @@ impl Board {
turn: i32,
food_chance: u8,
min_food: u8,
constrictor: bool,
) -> Self {
let width = board.width;
debug_assert!(width > 0);
@ -78,6 +82,7 @@ impl Board {
food_chance,
min_food,
snakes,
constrictor,
}
}
@ -107,7 +112,7 @@ impl Board {
// feed snakes
for snake in &mut self.snakes.values_mut() {
let head = snake.head();
if self.food.remove(head) {
if self.constrictor || self.food.remove(head) {
snake.health = MAX_HEALTH;
}
}