Walls are counted as non-movable
This commit is contained in:
@ -3,6 +3,7 @@ use util;
|
||||
|
||||
#[derive(PartialEq, Debug)]
|
||||
pub enum Tile<'a> {
|
||||
Wall,
|
||||
Food { coordinate: (i32,i32) },
|
||||
Obstacle { coordinate: (i32,i32) },
|
||||
Empty { coordinate: (i32,i32) },
|
||||
@ -39,6 +40,13 @@ pub fn direction_as_movement_delta(direction: &Direction) -> (i32,i32) {
|
||||
}
|
||||
|
||||
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> {
|
||||
self.snakeInfos.iter().find(|s| &s.id == id)
|
||||
}
|
||||
@ -58,6 +66,8 @@ impl Map {
|
||||
} else {
|
||||
Tile::SnakeBody { coordinate: coordinate, snake: s }
|
||||
}
|
||||
} else if !self.inside_map(coordinate) {
|
||||
Tile::Wall
|
||||
} else {
|
||||
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::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 };
|
||||
|
||||
const LOG_TARGET: &'static str = "snake";
|
||||
pub const TRAINING_VENUE: &'static str = "training";
|
||||
pub const TRAINING_VENUE: &'static str = "tournament";
|
||||
|
||||
pub struct Snake;
|
||||
|
||||
|
||||
@ -133,11 +133,19 @@ pub struct GameLink {
|
||||
pub struct TournamentEnded {
|
||||
#[serde(rename="type")]
|
||||
pub type_: String,
|
||||
pub playerWinnerId: String,
|
||||
pub gameId: String,
|
||||
pub gameResult: String,
|
||||
pub tournamentName: String,
|
||||
pub receivingPlayerId: 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)]
|
||||
|
||||
Reference in New Issue
Block a user