summaryrefslogtreecommitdiff
path: root/src/math.rs
diff options
context:
space:
mode:
authorJustin Worthe <justin.worthe@gmail.com>2017-05-20 22:46:00 +0200
committerJustin Worthe <justin.worthe@gmail.com>2017-05-20 22:46:00 +0200
commitb6a295a9eaf5fec16f72870baae84e6eadd1be33 (patch)
tree6ebe3b0c388d74b4ef48babd00a09cb9a5413dc0 /src/math.rs
parent6b8c71c635539a8609f82aa6eb52ea56c2c41c0c (diff)
Implemented lattice restricted battleship searching
Diffstat (limited to 'src/math.rs')
-rw-r--r--src/math.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/math.rs b/src/math.rs
index ce9d885..da06622 100644
--- a/src/math.rs
+++ b/src/math.rs
@@ -131,4 +131,24 @@ impl Point {
(dx == 1 && dy == 0)
}
+
+ pub fn is_on_lattice(&self, lattice_size: u16) -> bool {
+ (self.x + self.y) % lattice_size == 0
+ }
+}
+
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn point_on_lattice_works() {
+ assert_eq!(true, Point::new(0,0).is_on_lattice(4));
+ assert_eq!(true, Point::new(4,0).is_on_lattice(4));
+ assert_eq!(true, Point::new(0,4).is_on_lattice(4));
+ assert_eq!(true, Point::new(4,4).is_on_lattice(4));
+ assert_eq!(true, Point::new(1,3).is_on_lattice(4));
+ assert_eq!(true, Point::new(3,1).is_on_lattice(4));
+ }
}