From 6b8c71c635539a8609f82aa6eb52ea56c2c41c0c Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Sat, 20 May 2017 22:20:47 +0200 Subject: Finished up efficient elimination of found ships --- src/math.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/math.rs') diff --git a/src/math.rs b/src/math.rs index 2ef1013..ce9d885 100644 --- a/src/math.rs +++ b/src/math.rs @@ -116,10 +116,19 @@ impl Point { }; let corrected_parr_ship = match reverse { - true => parr_ship - length + 1, + true => 1 + parr_ship - length, false => parr_ship }; same_cross && parr_self >= corrected_parr_ship && parr_self < corrected_parr_ship + length } + + pub fn is_adjacent(&self, other: Point) -> bool { + let dx = if self.x > other.x {self.x - other.x} else {other.x - self.x}; + let dy = if self.y > other.y {self.y - other.y} else {other.y - self.y}; + + (dx == 0 && dy == 1) || + (dx == 1 && dy == 0) + + } } -- cgit v1.2.3