diff options
author | Andinus <andinus@nand.sh> | 2021-01-26 17:17:30 +0530 |
---|---|---|
committer | Andinus <andinus@nand.sh> | 2021-01-26 17:17:30 +0530 |
commit | a818d6a1c132c943966d5ee60547cc1630f13a0d (patch) | |
tree | 6b460edc58aa8b99b94fa716e74abbcf171da6b9 /lib/Octans/Neighbors.rakumod | |
parent | e68e68efe0040e88794a612db02bfc5d660ec02c (diff) | |
download | octans-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.rakumod | 9 |
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; |