Walls are counted as non-movable
This commit is contained in:
@ -3,6 +3,7 @@ use util;
|
|||||||
|
|
||||||
#[derive(PartialEq, Debug)]
|
#[derive(PartialEq, Debug)]
|
||||||
pub enum Tile<'a> {
|
pub enum Tile<'a> {
|
||||||
|
Wall,
|
||||||
Food { coordinate: (i32,i32) },
|
Food { coordinate: (i32,i32) },
|
||||||
Obstacle { coordinate: (i32,i32) },
|
Obstacle { coordinate: (i32,i32) },
|
||||||
Empty { coordinate: (i32,i32) },
|
Empty { coordinate: (i32,i32) },
|
||||||
@ -39,6 +40,13 @@ pub fn direction_as_movement_delta(direction: &Direction) -> (i32,i32) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Map {
|
impl Map {
|
||||||
|
pub fn inside_map(&self, coordinate: (i32, i32)) -> bool {
|
||||||
|
let (x,y) = coordinate;
|
||||||
|
let inside_x = x >= 0 && x < self.width;
|
||||||
|
let inside_y = y >= 0 && y < self.height;
|
||||||
|
inside_x && inside_y
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_snake_by_id<'a>(&'a self, id: &String) -> Option<&'a SnakeInfo> {
|
pub fn get_snake_by_id<'a>(&'a self, id: &String) -> Option<&'a SnakeInfo> {
|
||||||
self.snakeInfos.iter().find(|s| &s.id == id)
|
self.snakeInfos.iter().find(|s| &s.id == id)
|
||||||
}
|
}
|
||||||
@ -58,6 +66,8 @@ impl Map {
|
|||||||
} else {
|
} else {
|
||||||
Tile::SnakeBody { coordinate: coordinate, snake: s }
|
Tile::SnakeBody { coordinate: coordinate, snake: s }
|
||||||
}
|
}
|
||||||
|
} else if !self.inside_map(coordinate) {
|
||||||
|
Tile::Wall
|
||||||
} else {
|
} else {
|
||||||
Tile::Empty { coordinate: coordinate }
|
Tile::Empty { coordinate: coordinate }
|
||||||
}
|
}
|
||||||
@ -190,4 +200,13 @@ mod test {
|
|||||||
assert_eq!(false, map.can_snake_move_in_direction(&snake, Direction::Left));
|
assert_eq!(false, map.can_snake_move_in_direction(&snake, Direction::Left));
|
||||||
assert_eq!(false, map.can_snake_move_in_direction(&snake, Direction::Right));
|
assert_eq!(false, map.can_snake_move_in_direction(&snake, Direction::Right));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn can_not_move_to_walls() {
|
||||||
|
let map = get_test_map();
|
||||||
|
let id = &get_snake_two().id;
|
||||||
|
let snake = map.get_snake_by_id(id).unwrap();
|
||||||
|
|
||||||
|
assert_eq!(false, map.can_snake_move_in_direction(&snake, Direction::Down));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,7 @@ use maputil::{ Direction };
|
|||||||
use util::{ translate_positions };
|
use util::{ translate_positions };
|
||||||
|
|
||||||
const LOG_TARGET: &'static str = "snake";
|
const LOG_TARGET: &'static str = "snake";
|
||||||
pub const TRAINING_VENUE: &'static str = "training";
|
pub const TRAINING_VENUE: &'static str = "tournament";
|
||||||
|
|
||||||
pub struct Snake;
|
pub struct Snake;
|
||||||
|
|
||||||
|
|||||||
@ -133,11 +133,19 @@ pub struct GameLink {
|
|||||||
pub struct TournamentEnded {
|
pub struct TournamentEnded {
|
||||||
#[serde(rename="type")]
|
#[serde(rename="type")]
|
||||||
pub type_: String,
|
pub type_: String,
|
||||||
pub playerWinnerId: String,
|
pub receivingPlayerId: String,
|
||||||
pub gameId: String,
|
|
||||||
pub gameResult: String,
|
|
||||||
pub tournamentName: String,
|
|
||||||
pub tournamentId: String,
|
pub tournamentId: String,
|
||||||
|
pub tournamentName: String,
|
||||||
|
pub gameResult: Vec<GameResultSnake>,
|
||||||
|
pub gameId: String,
|
||||||
|
pub playerWinnerId: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
pub struct GameResultSnake {
|
||||||
|
pub points: i32,
|
||||||
|
pub playerId: String,
|
||||||
|
pub name: String
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
|||||||
Reference in New Issue
Block a user