about summary refs log tree commit diff stats
path: root/lib/Octans/Neighbors.rakumod
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2021-01-26 17:17:30 +0530
committerAndinus <andinus@nand.sh>2021-01-26 17:17:30 +0530
commita818d6a1c132c943966d5ee60547cc1630f13a0d (patch)
tree6b460edc58aa8b99b94fa716e74abbcf171da6b9 /lib/Octans/Neighbors.rakumod
parente68e68efe0040e88794a612db02bfc5d660ec02c (diff)
downloadoctans-a818d6a1c132c943966d5ee60547cc1630f13a0d.tar.gz
When computing neighbors, set it to an empty array
If we don't find any neighbors then we shouldn't have to recompute
this result.
Diffstat (limited to 'lib/Octans/Neighbors.rakumod')
-rw-r--r--lib/Octans/Neighbors.rakumod9
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/Octans/Neighbors.rakumod b/lib/Octans/Neighbors.rakumod
index c6f1c00..33dd834 100644
--- a/lib/Octans/Neighbors.rakumod
+++ b/lib/Octans/Neighbors.rakumod
@@ -20,10 +20,13 @@ sub neighbors (
     state Array @neighbors;
 
     if @puzzle[$y][$x] {
-
-        # If we've already computed the neighbors then no need to do
-        # it again.
+        # Don't re-compute neighbors.
         unless @neighbors[$y][$x] {
+            # Set it to an empty array because otherwise if it has no
+            # neighbors then it would've be recomputed everytime
+            # neighbors() was called.
+            @neighbors[$y][$x] = [];
+
             my Int $pos-x;
             my Int $pos-y;