Compare commits

..

No commits in common. "60bd5acd35ed8363bcb727ea75d581c3820413d0" and "290b793b94bfdb85b6b365bf25df8f99fd042be4" have entirely different histories.

3 changed files with 18 additions and 22 deletions

View File

@ -1,8 +1,8 @@
FROM rust:1.80
COPY battlesnake/ /usr/app
COPY . /usr/app
WORKDIR /usr/app
RUN cargo install --path .
RUN cargo install --path battlesnake
CMD ["battlesnake"]

View File

@ -20,11 +20,25 @@ impl Battlesnake {
/// Check if moving the snake in `direction` is safe.
#[must_use]
pub fn is_direction_safe(&self, direction: Direction, game: &Game, board: &Board) -> bool {
if self.is_direction_death(direction, game, board) {
let target = self.head.move_to(direction);
// check if target is out of bounds
if !((0..board.width).contains(&target.x) && (0..board.height).contains(&target.y)) {
return false;
}
let target = self.head.move_to(direction);
// check if target is inside a snake
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| target == coord)
{
return false;
}
// check if a bigger snake could move to this square
if board

View File

@ -21,7 +21,6 @@ fn try_main() -> Result<(), DynError> {
match task.as_deref() {
Some("local") => local()?,
Some("local2") => local2()?,
Some("docker") => docker()?,
_ => print_help(),
}
Ok(())
@ -33,8 +32,6 @@ fn print_help() {
local runs the snake on a local game
local2 runs the snake twice on a local game
docker package docker image and upload to docker.mkaenner.de/snake
"
)
}
@ -123,21 +120,6 @@ fn run_snake(port: u16) -> Result<Child, DynError> {
}
}
fn docker() -> Result<(), DynError> {
if !Command::new("docker")
.current_dir(project_root())
.args(["build", ".", "-t", "docker.mkaenner.de/snake"])
.status()?
.success()
{
Err("Build of docker image failed")?;
}
Command::new("docker")
.args(["push", "docker.mkaenner.de/snake"])
.status()?;
Ok(())
}
fn project_root() -> PathBuf {
Path::new(&env!("CARGO_MANIFEST_DIR"))
.ancestors()