docker.nix
This commit is contained in:
parent
030fce4bb9
commit
97d8ec4ee8
|
@ -0,0 +1,22 @@
|
|||
{ system ? builtins.currentSystem }:
|
||||
|
||||
let
|
||||
sources = import ./nix/sources.nix;
|
||||
pkgs = import sources.nixpkgs { };
|
||||
callPackage = pkgs.lib.callPackageWith pkgs;
|
||||
pneuma = callPackage ./pneuma.nix { };
|
||||
|
||||
dockerImage = pkg:
|
||||
pkgs.dockerTools.buildImage {
|
||||
name = "xena/pneuma";
|
||||
tag = pkg.version;
|
||||
|
||||
contents = [ pkg ];
|
||||
|
||||
config = {
|
||||
Cmd = [ "/bin/pneuma" ];
|
||||
WorkingDir = "/";
|
||||
};
|
||||
};
|
||||
|
||||
in dockerImage pneuma
|
11
shell.nix
11
shell.nix
|
@ -3,12 +3,7 @@ let
|
|||
niv = import sources.niv { };
|
||||
pkgs = import sources.nixpkgs { };
|
||||
rust = import ./nix/rust.nix { inherit sources; };
|
||||
in
|
||||
pkgs.mkShell {
|
||||
buildInputs = [
|
||||
rust.rust
|
||||
niv.niv
|
||||
|
||||
pkgs.glibc
|
||||
];
|
||||
in pkgs.mkShell {
|
||||
buildInputs = [ rust.rust niv.niv ];
|
||||
nativeBuildInputs = [ pkgs.removeReferencesTo ];
|
||||
}
|
||||
|
|
48
src/main.rs
48
src/main.rs
|
@ -1,14 +1,12 @@
|
|||
#![feature(proc_macro_hygiene, decl_macro)]
|
||||
|
||||
#[macro_use] extern crate rocket;
|
||||
#[macro_use] extern crate rocket_contrib;
|
||||
#[macro_use] extern crate serde_derive;
|
||||
#[macro_use]
|
||||
extern crate rocket;
|
||||
|
||||
use rocket::State;
|
||||
use rocket_contrib::json::Json;
|
||||
use pathfinding::grid::Grid;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::sync::Mutex;
|
||||
|
||||
mod battlesnake;
|
||||
|
||||
|
@ -31,7 +29,10 @@ fn ping() -> &'static str {
|
|||
}
|
||||
|
||||
#[post("/start", format = "json", data = "<msg>")]
|
||||
fn start(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 target = find_target(&msg);
|
||||
let path = find_path(&msg, &head, &target);
|
||||
|
@ -55,7 +56,7 @@ fn start(cache: State<Cache>, msg: Json<battlesnake::SnakeRequest>) -> Json<batt
|
|||
fn find_path(
|
||||
msg: &battlesnake::SnakeRequest,
|
||||
head: &battlesnake::Coord,
|
||||
target: &battlesnake::Coord
|
||||
target: &battlesnake::Coord,
|
||||
) -> Option<Vec<battlesnake::Coord>> {
|
||||
let path = pathfinding::directed::astar::astar(
|
||||
head,
|
||||
|
@ -68,15 +69,12 @@ fn find_path(
|
|||
None => return None,
|
||||
Some(x) => {
|
||||
return Some(x.0);
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[post("/end", format = "json", data = "<msg>")]
|
||||
fn end(
|
||||
cache_state: State<Cache>,
|
||||
msg: Json<battlesnake::SnakeRequest>,
|
||||
) -> String {
|
||||
fn end(cache_state: State<Cache>, msg: Json<battlesnake::SnakeRequest>) -> String {
|
||||
cache_state
|
||||
.lock()
|
||||
.expect("wanted cache to be lockable")
|
||||
|
@ -119,18 +117,23 @@ fn make_move(
|
|||
let next_move = battlesnake::Line {
|
||||
start: &head,
|
||||
end: &next,
|
||||
}.direction().to_string();
|
||||
println!("moving to {} {:?}, target: {:?}", next_move, next, gs.target);
|
||||
}
|
||||
.direction()
|
||||
.to_string();
|
||||
println!(
|
||||
"moving to {} {:?}, target: {:?}",
|
||||
next_move, next, gs.target
|
||||
);
|
||||
Json(battlesnake::MoveResponse {
|
||||
move_field: next_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();
|
||||
|
||||
|
@ -143,21 +146,16 @@ 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() {
|
||||
let map = HashMap::<String, GameState>::new();
|
||||
let mutex_map = Mutex::from(map);
|
||||
rocket::ignite().mount("/", routes![
|
||||
index,
|
||||
start,
|
||||
ping,
|
||||
make_move,
|
||||
end,
|
||||
])
|
||||
rocket::ignite()
|
||||
.mount("/", routes![index, start, ping, make_move, end,])
|
||||
.manage(mutex_map)
|
||||
.launch();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue