From 90956050927382eeb2300bc11747dc1336963b68 Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Wed, 25 Aug 2021 12:48:00 -0500 Subject: [PATCH] Guard against overflows. --- src/map.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/map.rs b/src/map.rs index e89fc63..91a669c 100644 --- a/src/map.rs +++ b/src/map.rs @@ -111,15 +111,15 @@ impl Map { let mut exits = Vec::new(); // Cardinal directions - if self.is_exit_valid(x-1, y) { exits.push((x-1, y, 1.0)) }; + if x > 0 && self.is_exit_valid(x-1, y) { exits.push((x-1, y, 1.0)) }; if self.is_exit_valid(x+1, y) { exits.push((x+1, y, 1.0)) }; - if self.is_exit_valid(x, y-1) { exits.push((x, y-1, 1.0)) }; + if y > 0 && self.is_exit_valid(x, y-1) { exits.push((x, y-1, 1.0)) }; if self.is_exit_valid(x, y+1) { exits.push((x, y+1, 1.0)) }; // Diagonals - if self.is_exit_valid(x-1, y-1) { exits.push((x-1, y-1, 1.45)); } - if self.is_exit_valid(x+1, y-1) { exits.push((x+1, y-1, 1.45)); } - if self.is_exit_valid(x-1, y+1) { exits.push((x-1, y+1, 1.45)); } + if x > 0 && y > 0 && self.is_exit_valid(x-1, y-1) { exits.push((x-1, y-1, 1.45)); } + if y > 0 && self.is_exit_valid(x+1, y-1) { exits.push((x+1, y-1, 1.45)); } + if x > 0 && self.is_exit_valid(x-1, y+1) { exits.push((x-1, y+1, 1.45)); } if self.is_exit_valid(x+1, y+1) { exits.push((x+1, y+1, 1.45)); } exits