Skip to content

Commit 09ecf5f

Browse files
committed
bomb
1 parent 575c80c commit 09ecf5f

File tree

1 file changed

+35
-32
lines changed

1 file changed

+35
-32
lines changed

src/wata.rs

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -377,42 +377,45 @@ pub fn run() {
377377
let stime = get_time();
378378
let mut map = std::collections::BTreeMap::new();
379379
let mut commands = vec![];
380-
for ship in &resp.state.ships {
381-
if ship.role == resp.info.role {
382-
map.entry((ship.pos, ship.v)).or_insert(vec![]).push(ship.clone());
383-
}
384-
}
385380
let mut killed = std::collections::BTreeSet::new();
386-
if resp.info.role == 0 {
387-
for ship in &resp.state.ships {
388-
if ship.role == resp.info.role && ship.status.power == 0 && ship.status.life <= 2 {
389-
let x = ship.pos.0;
390-
let y = ship.pos.1;
391-
let dx = ship.v.0;
392-
let dy = ship.v.1;
393-
let (gx, gy) = get_g(x, y);
394-
let x = x + dx + gx;
395-
let y = y + dy + gy;
396-
let mut bomb = false;
397-
for ship2 in &resp.state.ships {
398-
if ship2.role != resp.info.role && killed.contains(&ship2.id) {
399-
let x2 = ship2.pos.0;
400-
let y2 = ship2.pos.1;
401-
let dx2 = ship2.v.0;
402-
let dy2 = ship2.v.1;
403-
let (gx2, gy2) = get_g(x2, y2);
404-
let x2 = x2 + dx2 + gx2;
405-
let y2 = y2 + dy2 + gy2;
406-
if (x - x2).abs().max((y - y2).abs()) <= 2 {
407-
killed.insert(ship2.id);
408-
bomb = true;
409-
}
381+
for ship in &resp.state.ships {
382+
if ship.role == resp.info.role && ship.status.power == 0 && ship.status.life <= 2 {
383+
let x = ship.pos.0;
384+
let y = ship.pos.1;
385+
let dx = ship.v.0;
386+
let dy = ship.v.1;
387+
let (gx, gy) = get_g(x, y);
388+
let x = x + dx + gx;
389+
let y = y + dy + gy;
390+
let mut bomb = false;
391+
for ship2 in &resp.state.ships {
392+
if ship2.role != resp.info.role && !killed.contains(&ship2.id) {
393+
if resp.info.role == 1 && ship2.status.energy < 5 {
394+
continue;
395+
}
396+
let x2 = ship2.pos.0;
397+
let y2 = ship2.pos.1;
398+
let dx2 = ship2.v.0;
399+
let dy2 = ship2.v.1;
400+
let (gx2, gy2) = get_g(x2, y2);
401+
let x2 = x2 + dx2 + gx2;
402+
let y2 = y2 + dy2 + gy2;
403+
if (x - x2).abs().max((y - y2).abs()) <= 3 {
404+
killed.insert(ship2.id);
405+
bomb = true;
410406
}
411407
}
412-
if bomb {
413-
414-
}
415408
}
409+
if bomb {
410+
eprintln!("BOMB!!!!!!!!!!!!!!!!!!: {:?}", ship);
411+
killed.insert(ship.id);
412+
commands.push(Command::Detonate(ship.id, None));
413+
}
414+
}
415+
}
416+
for ship in &resp.state.ships {
417+
if ship.role == resp.info.role && !killed.contains(&ship.id) {
418+
map.entry((ship.pos, ship.v)).or_insert(vec![]).push(ship.clone());
416419
}
417420
}
418421
let mut new_ships = vec![];

0 commit comments

Comments
 (0)