2019-12-17 23:58:57 +00:00
|
|
|
#[derive(Default, Debug, Clone, PartialEq, serde_derive::Serialize, serde_derive::Deserialize)]
|
|
|
|
pub struct MoveResponse {
|
|
|
|
#[serde(rename = "move")]
|
|
|
|
pub move_field: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Default, Debug, Clone, PartialEq, serde_derive::Serialize, serde_derive::Deserialize)]
|
|
|
|
pub struct StartResponse {
|
|
|
|
pub color: String,
|
|
|
|
#[serde(rename = "HeadType")]
|
|
|
|
pub head_type: String,
|
|
|
|
#[serde(rename = "TailType")]
|
|
|
|
pub tail_type: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Default, Debug, Clone, PartialEq, serde_derive::Serialize, serde_derive::Deserialize)]
|
|
|
|
pub struct SnakeRequest {
|
|
|
|
pub game: Game,
|
|
|
|
pub turn: i64,
|
|
|
|
pub board: Board,
|
|
|
|
pub you: Snake,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Default, Debug, Clone, PartialEq, serde_derive::Serialize, serde_derive::Deserialize)]
|
|
|
|
pub struct Game {
|
|
|
|
pub id: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Default, Debug, Clone, PartialEq, serde_derive::Serialize, serde_derive::Deserialize)]
|
|
|
|
pub struct Board {
|
|
|
|
pub height: usize,
|
|
|
|
pub width: usize,
|
|
|
|
pub food: Vec<Coord>,
|
|
|
|
pub snakes: Vec<Snake>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Default, Debug, Clone, PartialEq, serde_derive::Serialize, serde_derive::Deserialize)]
|
|
|
|
pub struct Coord {
|
|
|
|
pub x: usize,
|
|
|
|
pub y: usize,
|
|
|
|
}
|
|
|
|
|
2019-12-18 00:29:00 +00:00
|
|
|
pub struct Line<'a> {
|
|
|
|
pub start: &'a Coord,
|
|
|
|
pub end: &'a Coord,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Line {
|
|
|
|
fn manhattan<'a>(self: &'a Line) -> u32 {
|
|
|
|
let abs_x = (self.end.x as i32 - self.start.y as i32).abs();
|
|
|
|
let abs_y = (self.end.y as i32 - self.start.y as i32).abs();
|
|
|
|
|
|
|
|
(abs_x - abs_y) as u32
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-17 23:58:57 +00:00
|
|
|
#[derive(Default, Debug, Clone, PartialEq, serde_derive::Serialize, serde_derive::Deserialize)]
|
|
|
|
pub struct Snake {
|
|
|
|
pub id: String,
|
|
|
|
pub name: String,
|
|
|
|
pub health: usize,
|
|
|
|
pub body: Vec<Coord>,
|
|
|
|
}
|