Move manhattan metric function to trait.

This commit is contained in:
2018-12-22 09:40:09 +01:00
parent ba321caa37
commit 3b825ac933
5 changed files with 53 additions and 38 deletions

View File

@@ -6,7 +6,7 @@ use std::io::BufRead;
use std::io::BufReader;
use std::io::Read;
use common::manhattan_distance;
use common::Point;
use common::Solution;
type Coordinate = (usize, usize);
@@ -122,7 +122,7 @@ impl Day15 {
let to_attack = self.units.iter()
.enumerate()
.filter(|(_, x)| x.faction != faction && x.is_alive())
.filter(|(_, x)| manhattan_distance(x.pos, initial) == 1)
.filter(|(_, x)| x.pos.manhattan(initial) == 1)
.min_by(|&(_, a), &(_, b)| a.hp.cmp(&b.hp).then(a.pos.cmp(&b.pos)));
if let Some((index, _)) = to_attack {