fixes
This commit is contained in:
parent
9219e0b364
commit
56e3971f87
21
src/main.rs
21
src/main.rs
|
@ -30,8 +30,8 @@ fn ping() -> &'static str {
|
||||||
"OK - Pneuma online"
|
"OK - Pneuma online"
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/begin", format = "json", data = "<msg>")]
|
#[post("/start", format = "json", data = "<msg>")]
|
||||||
fn begin(cache: State<Cache>, msg: Json<battlesnake::SnakeRequest>) -> Json<battlesnake::StartResponse> {
|
fn start(cache: State<Cache>, msg: Json<battlesnake::SnakeRequest>) -> Json<battlesnake::StartResponse> {
|
||||||
let head = msg.you.body[0];
|
let head = msg.you.body[0];
|
||||||
let target = find_target(&msg);
|
let target = find_target(&msg);
|
||||||
let path = find_path(&msg, &head, &target);
|
let path = find_path(&msg, &head, &target);
|
||||||
|
@ -102,8 +102,14 @@ fn make_move(
|
||||||
match gs.path.as_mut().unwrap().pop() {
|
match gs.path.as_mut().unwrap().pop() {
|
||||||
None => {
|
None => {
|
||||||
gs.path = None;
|
gs.path = None;
|
||||||
|
let target = msg.board.safe_neighbors(&head)[0].0;
|
||||||
Json(battlesnake::MoveResponse {
|
Json(battlesnake::MoveResponse {
|
||||||
move_field: "up".to_string(),
|
move_field: battlesnake::Line{
|
||||||
|
start: &head,
|
||||||
|
end: &target,
|
||||||
|
}
|
||||||
|
.direction()
|
||||||
|
.to_string(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
Some(next) => Json(battlesnake::MoveResponse {
|
Some(next) => Json(battlesnake::MoveResponse {
|
||||||
|
@ -119,7 +125,7 @@ fn make_move(
|
||||||
|
|
||||||
fn find_target<'a>(gs: &'a battlesnake::SnakeRequest) -> &'a battlesnake::Coord {
|
fn find_target<'a>(gs: &'a battlesnake::SnakeRequest) -> &'a battlesnake::Coord {
|
||||||
let head = &gs.you.body[0];
|
let head = &gs.you.body[0];
|
||||||
if gs.you.health > 30 {
|
//if gs.you.health > 30 {
|
||||||
let mut lowest_score: u32 = 99999;
|
let mut lowest_score: u32 = 99999;
|
||||||
let mut coord: &battlesnake::Coord = &gs.you.body.last().unwrap();
|
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 coord;
|
||||||
}
|
//}
|
||||||
|
|
||||||
return gs.you.body.last().unwrap();
|
//return gs.you.body.last().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -142,9 +148,10 @@ fn main() {
|
||||||
let mutex_map = Mutex::from(map);
|
let mutex_map = Mutex::from(map);
|
||||||
rocket::ignite().mount("/", routes![
|
rocket::ignite().mount("/", routes![
|
||||||
index,
|
index,
|
||||||
begin,
|
start,
|
||||||
ping,
|
ping,
|
||||||
make_move,
|
make_move,
|
||||||
|
end,
|
||||||
])
|
])
|
||||||
.manage(mutex_map)
|
.manage(mutex_map)
|
||||||
.launch();
|
.launch();
|
||||||
|
|
Loading…
Reference in New Issue