Skip to content

Commit

Permalink
routerをPreprocessに入れたよ
Browse files Browse the repository at this point in the history
  • Loading branch information
iwiwi committed Jul 20, 2020
1 parent b845dae commit 894fd8b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
13 changes: 4 additions & 9 deletions src/chokudAI.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ pub fn run_chokudai() {
// run(client, join_resp);
}

pub fn run(client: Client, join_resp: Response, prep: Preprocess){


let mut router = super::routing::Router::new();

pub fn run(client: Client, join_resp: Response, mut prep: Preprocess){
let all = join_resp.info.ability.potential;
let shoot = 64;
let mut heal = 10;
Expand All @@ -51,8 +47,7 @@ pub fn run(client: Client, join_resp: Response, prep: Preprocess){

//COMMANDS
while resp.stage != 2 {

resp = client.command(&chokud_ai(&resp, &id, &my_role, &mut e_data, &prep, &mut router));
resp = client.command(&chokud_ai(&resp, &id, &my_role, &mut e_data, &mut prep));
//dbg!(&resp);
}
}
Expand All @@ -62,7 +57,7 @@ fn dist(a: &Ship, b: &Ship) -> i32{
return (a.pos.0 - b.pos.0).abs() + (a.pos.1 - b.pos.1).abs();
}

fn chokud_ai(resp: &Response, id: &i32, my_role: &i32, e_data: &mut EnemyData, prep: &Preprocess, router: &mut super::routing::Router) -> Vec<Command> {
fn chokud_ai(resp: &Response, id: &i32, my_role: &i32, e_data: &mut EnemyData, prep: &mut Preprocess) -> Vec<Command> {

let mut myship = resp.state.ships[0].clone();
let mut enemyship = resp.state.ships[0].clone();
Expand Down Expand Up @@ -156,7 +151,7 @@ fn chokud_ai(resp: &Response, id: &i32, my_role: &i32, e_data: &mut EnemyData, p

if e_data.go_near {
eprintln!("Go Near!");
let (dvx, dvy) = router.doit(&myship, &enemyship);
let (dvx, dvy) = prep.router.doit(&myship, &enemyship);
addx = dvx;
addy = dvy;
}
Expand Down
7 changes: 5 additions & 2 deletions src/wata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ pub fn test_naive(mut x: i32, mut y: i32, mut dx: i32, mut dy: i32, gx: &Vec<Vec
pub struct Preprocess {
gx: Vec<Vec<i32>>,
gy: Vec<Vec<i32>>,
dp: Vec<Vec<Vec<Vec<i32>>>>
dp: Vec<Vec<Vec<Vec<i32>>>>,
pub router: crate::routing::Router,
}

fn preprocess() -> Preprocess {
Expand Down Expand Up @@ -157,8 +158,10 @@ fn preprocess() -> Preprocess {
}
}
eprintln!("preprocessed: {}", count);

let router = crate::routing::Router::new();
eprintln!("time: {:.3}", get_time() - stime);
Preprocess { gx, gy, dp }
Preprocess { gx, gy, dp, router }
}

fn rec(x: i32, y: i32, dx: i32, dy: i32, last_ax: i32, last_ay: i32, d: usize, prep: &Preprocess) -> (i32, usize) {
Expand Down

0 comments on commit 894fd8b

Please sign in to comment.