diff --git a/battlesnake/src/main.rs b/battlesnake/src/main.rs index 702f16b..14bbc51 100644 --- a/battlesnake/src/main.rs +++ b/battlesnake/src/main.rs @@ -1,6 +1,6 @@ #![allow(clippy::needless_pass_by_value)] -use battlesnake::{logic, Action, GameState}; +use battlesnake::{logic, Action, Direction, GameState}; use log::{error, info}; use rocket::{ fairing::AdHoc, get, http::Status, launch, post, routes, serde::json::Json, tokio::task, @@ -26,7 +26,7 @@ fn handle_start(start_req: Json) -> Status { } #[post("/move", format = "json", data = "")] -async fn handle_move(move_req: Json) -> Option> { +async fn handle_move(move_req: Json) -> Json { let start = Instant::now(); let response = task::spawn_blocking(move || { logic::get_move( @@ -40,9 +40,13 @@ async fn handle_move(move_req: Json) -> Option> { .await .inspect_err(|e| error!("failed to join compute thread: {e}")) .ok() - .flatten()?; + .flatten() + .unwrap_or(Action { + r#move: Direction::Up, + shout: Some("I am so dead".to_owned()), + }); - Some(Json(response)) + Json(response) } #[post("/end", format = "json", data = "")]