forked from cadey/pneuma
it compiles now
This commit is contained in:
parent
67f127df21
commit
45e5505c9c
File diff suppressed because it is too large
Load Diff
56
src/main.rs
56
src/main.rs
|
@ -72,46 +72,30 @@ fn find_path(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/move", format = "json", data = "<msg>")]
|
#[post("/move", format = "json", data = "<msg>")]
|
||||||
fn make_move(cache: State<Cache>, msg: Json<battlesnake::SnakeRequest>) -> Json<battlesnake::MoveResponse> {
|
fn make_move(cache_state: State<Cache>, msg: Json<battlesnake::SnakeRequest>) -> Json<battlesnake::MoveResponse> {
|
||||||
let head = msg.you.body[0];
|
let head = msg.you.body[0];
|
||||||
if let Some(mut gs) = cache.lock().expect("wanted cache to be unlockable").get(&msg.game.id) {
|
|
||||||
let gs_path = gs.path.as_ref().or_else(|| {
|
|
||||||
let target = find_target(&msg);
|
|
||||||
let path = find_path(&msg, &head, &target);
|
|
||||||
gs = &GameState{
|
|
||||||
target: *target,
|
|
||||||
path: path,
|
|
||||||
};
|
|
||||||
|
|
||||||
path.as_ref()
|
let mut cache = cache_state.lock().expect("wanted cache to be unlockable");
|
||||||
});
|
let gs = cache.get_mut(&msg.game.id).unwrap();
|
||||||
let mut inner = gs_path.expect("what");
|
if gs.path.is_none() {
|
||||||
let next = inner[0];
|
gs.target = *find_target(&msg);
|
||||||
inner.pop();
|
gs.path = find_path(&msg, &head, &gs.target);
|
||||||
|
|
||||||
if inner.len() == 0 {
|
|
||||||
gs.path = None;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Json(battlesnake::MoveResponse{
|
|
||||||
move_field: battlesnake::Line{
|
|
||||||
start: &head,
|
|
||||||
end: &next,
|
|
||||||
}.direction().to_string(),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let target = find_target(&msg);
|
match gs.path.as_mut().unwrap().pop() {
|
||||||
let path = find_path(&msg, &head, &target);
|
None => {
|
||||||
let gs = GameState{
|
gs.path = None;
|
||||||
target: *target,
|
Json(battlesnake::MoveResponse {
|
||||||
path: path,
|
move_field: "up".to_string(),
|
||||||
};
|
})
|
||||||
println!("{:?}", gs);
|
},
|
||||||
|
Some(next) => Json(battlesnake::MoveResponse{
|
||||||
Json(battlesnake::MoveResponse {
|
move_field: battlesnake::Line{
|
||||||
move_field: "up".to_string(),
|
start: &head,
|
||||||
})
|
end: &next,
|
||||||
|
}.direction().to_string(),
|
||||||
|
}),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_target<'a>(gs: &'a battlesnake::SnakeRequest) -> &'a battlesnake::Coord {
|
fn find_target<'a>(gs: &'a battlesnake::SnakeRequest) -> &'a battlesnake::Coord {
|
||||||
|
|
Loading…
Reference in New Issue