From 56e3971f876ac7feee7e2be672b93cc8e2df584b Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Wed, 18 Dec 2019 08:00:44 -0500 Subject: [PATCH] fixes --- src/main.rs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index 263ddcc..0fbd3c9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,8 +30,8 @@ fn ping() -> &'static str { "OK - Pneuma online" } -#[post("/begin", format = "json", data = "")] -fn begin(cache: State, msg: Json) -> Json { +#[post("/start", format = "json", data = "")] +fn start(cache: State, msg: Json) -> Json { let head = msg.you.body[0]; let target = find_target(&msg); let path = find_path(&msg, &head, &target); @@ -102,8 +102,14 @@ fn make_move( match gs.path.as_mut().unwrap().pop() { None => { gs.path = None; + let target = msg.board.safe_neighbors(&head)[0].0; Json(battlesnake::MoveResponse { - move_field: "up".to_string(), + move_field: battlesnake::Line{ + start: &head, + end: &target, + } + .direction() + .to_string(), }) } Some(next) => Json(battlesnake::MoveResponse { @@ -119,7 +125,7 @@ fn make_move( fn find_target<'a>(gs: &'a battlesnake::SnakeRequest) -> &'a battlesnake::Coord { let head = &gs.you.body[0]; - if gs.you.health > 30 { + //if gs.you.health > 30 { let mut lowest_score: u32 = 99999; let mut coord: &battlesnake::Coord = &gs.you.body.last().unwrap(); @@ -132,9 +138,9 @@ fn find_target<'a>(gs: &'a battlesnake::SnakeRequest) -> &'a battlesnake::Coord } return coord; - } + //} - return gs.you.body.last().unwrap(); + //return gs.you.body.last().unwrap(); } fn main() { @@ -142,9 +148,10 @@ fn main() { let mutex_map = Mutex::from(map); rocket::ignite().mount("/", routes![ index, - begin, + start, ping, make_move, + end, ]) .manage(mutex_map) .launch();