Compare commits
No commits in common. "af0baffde09a91f552224ed9c4d242cecc5365d1" and "27d60845b57e017213f7699cdc271dc842331fa3" have entirely different histories.
af0baffde0
...
27d60845b5
@ -14,7 +14,7 @@ use log::info;
|
|||||||
use rand::seq::SliceRandom;
|
use rand::seq::SliceRandom;
|
||||||
use serde_json::{json, Value};
|
use serde_json::{json, Value};
|
||||||
|
|
||||||
use crate::{Battlesnake, Board, Coord, Direction, Game, Move};
|
use crate::{Battlesnake, Board, Direction, Game, Move};
|
||||||
|
|
||||||
impl Battlesnake {
|
impl Battlesnake {
|
||||||
/// Check if moving the snake in `direction` is safe.
|
/// Check if moving the snake in `direction` is safe.
|
||||||
@ -68,46 +68,6 @@ impl Battlesnake {
|
|||||||
}
|
}
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub fn health_cost(&self, tile: Coord, game: &Game, board: &Board) -> i32 {
|
|
||||||
// we can't leave the board
|
|
||||||
if !((0..board.width).contains(&tile.x) && (0..board.height).contains(&tile.y)) {
|
|
||||||
return self.health;
|
|
||||||
}
|
|
||||||
|
|
||||||
// we can't move into other snakes
|
|
||||||
if board
|
|
||||||
.snakes
|
|
||||||
.iter()
|
|
||||||
.filter(|snake| {
|
|
||||||
!(game.ruleset.settings.squad.allow_body_collisions && self.squad == snake.squad)
|
|
||||||
})
|
|
||||||
.flat_map(|snake| snake.body.iter())
|
|
||||||
.any(|&coord| tile == coord)
|
|
||||||
{
|
|
||||||
return self.health;
|
|
||||||
}
|
|
||||||
|
|
||||||
// every step costs us one health point
|
|
||||||
let mut cost = 1;
|
|
||||||
|
|
||||||
// hazards increase the health loss
|
|
||||||
if board.hazards.iter().any(|&hazard| tile == hazard) {
|
|
||||||
cost += game.ruleset.settings.hazard_damage_per_turn;
|
|
||||||
}
|
|
||||||
|
|
||||||
// check for bigger snakes that can move into this square
|
|
||||||
for snake in board
|
|
||||||
.snakes
|
|
||||||
.iter()
|
|
||||||
.filter(|snake| snake.id != self.id && self.length <= snake.length)
|
|
||||||
{
|
|
||||||
let moves = enum_iterator::all().map(|dir| snake.head.move_to(dir));
|
|
||||||
}
|
|
||||||
|
|
||||||
cost
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// info is called when you create your Battlesnake on play.battlesnake.com
|
// info is called when you create your Battlesnake on play.battlesnake.com
|
||||||
|
@ -16,15 +16,18 @@ mod logic;
|
|||||||
// See https://docs.battlesnake.com/api
|
// See https://docs.battlesnake.com/api
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy, Deserialize, Serialize, Sequence)]
|
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy, Deserialize, Serialize, Sequence)]
|
||||||
#[serde(rename_all = "lowercase")]
|
|
||||||
pub enum Direction {
|
pub enum Direction {
|
||||||
/// Move left (-x)
|
/// Move left (-x)
|
||||||
|
#[serde(rename = "left")]
|
||||||
Left,
|
Left,
|
||||||
/// Move up (+y)
|
/// Move up (+y)
|
||||||
|
#[serde(rename = "up")]
|
||||||
Up,
|
Up,
|
||||||
/// Move right (+x)
|
/// Move right (+x)
|
||||||
|
#[serde(rename = "right")]
|
||||||
Right,
|
Right,
|
||||||
/// Move down (-y)
|
/// Move down (-y)
|
||||||
|
#[serde(rename = "down")]
|
||||||
Down,
|
Down,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user