summaryrefslogtreecommitdiff
path: root/src/math.rs
diff options
context:
space:
mode:
authorJustin Worthe <justin.worthe@gmail.com>2017-05-20 22:20:47 +0200
committerJustin Worthe <justin.worthe@gmail.com>2017-05-20 22:20:47 +0200
commit6b8c71c635539a8609f82aa6eb52ea56c2c41c0c (patch)
tree23da0d8ae0d15ebc1e9b48797965f58958e9c34d /src/math.rs
parent973f7be695f7c3308d384e1ee30066547e4a07c7 (diff)
Finished up efficient elimination of found ships
Diffstat (limited to 'src/math.rs')
-rw-r--r--src/math.rs11
1 files changed, 10 insertions, 1 deletions
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)
+
+ }
}