diff options
author | Andinus <andinus@nand.sh> | 2021-03-02 23:55:59 +0530 |
---|---|---|
committer | Andinus <andinus@nand.sh> | 2021-03-02 23:57:54 +0530 |
commit | edf8a7290888977ff0bc625f02a81abbc37fb984 (patch) | |
tree | ce9bf475eea0a423aff9852875413f4d89989581 | |
parent | b88fb075c4485154f72fb72354f8bf8004d71f72 (diff) | |
download | octans-edf8a7290888977ff0bc625f02a81abbc37fb984.tar.gz |
Re-structure code
These changes should make it easier to read the code.
-rw-r--r-- | lib/Octans/CLI.rakumod | 35 | ||||
-rw-r--r-- | lib/Octans/Neighbors.rakumod | 4 |
2 files changed, 21 insertions, 18 deletions
diff --git a/lib/Octans/CLI.rakumod b/lib/Octans/CLI.rakumod index 3e15dcf..744fba8 100644 --- a/lib/Octans/CLI.rakumod +++ b/lib/Octans/CLI.rakumod @@ -30,12 +30,13 @@ multi sub MAIN ( # set-gray-squares also removes asterisks from @puzzle. @gray-squares = set-gray-squares(@puzzle); # ($y, $x) - if $verbose { + if so $verbose { # Don't print path if using the dictionary included with the # program. - say "Dictionary: ", $dict.Str - unless ($dict.Str - eq %?RESOURCES<mwords/354984si.ngl>.Str); + unless $dict.Str eq %?RESOURCES<mwords/354984si.ngl>.Str { + say "Dictionary: " ~ $dict.Str; + } + say "Gray squares: ", @gray-squares; say "Puzzle"; " $_".say for @puzzle; @@ -54,7 +55,7 @@ multi sub MAIN ( # gather all the words that word-search finds starting from # $pos. - for gather word-search( + word: for gather word-search( @dict, @puzzle, $pos[0], $pos[1], ) -> ( # word-search returns the word along with @visited which @@ -62,24 +63,26 @@ multi sub MAIN ( # word was found. $word, @visited ) { - # Print the word, along with the time taken (if $verbose). - say ($verbose - ?? "\n" ~ $word ~ " [" ~ DateTime.now - $initial ~ "π ]" - !! $word); + # If not $verbose then print the word. + unless so $verbose { + say $word; + next word; + } + + # Print the word, along with the time taken. + say "\n" ~ $word ~ " [" ~ DateTime.now - $initial ~ "π ]"; # Print the puzzle, highlighting the path. - if $verbose { - for ^@puzzle.elems -> $y { - print " " x 3; - for ^@puzzle[$y].elems -> $x { - print " ", ( + for ^@puzzle.elems -> $y { + print " " x 3; + for ^@puzzle[$y].elems -> $x { + print " " ~ ( @visited[$y][$x] ?? (%π»πΆππΈπ-πΈπ½πΆππ{@puzzle[$y][$x]} // @puzzle[$y][$x]) !! @puzzle[$y][$x] ); - } - print "\n"; } + print "\n"; } } } diff --git a/lib/Octans/Neighbors.rakumod b/lib/Octans/Neighbors.rakumod index 33dd834..0c90b0c 100644 --- a/lib/Octans/Neighbors.rakumod +++ b/lib/Octans/Neighbors.rakumod @@ -34,13 +34,13 @@ sub neighbors ( # each direction according to the values specified in # @directions array. In this case we're just trying to # move in 4 directions (top, bottom, left & right). - DIRECTION: for @directions -> $direction { + direction: for @directions -> $direction { $pos-y = $y + $direction[0]; $pos-x = $x + $direction[1]; # If movement in this direction is out of puzzle grid # boundary then move on to next direction. - next DIRECTION unless @puzzle[$pos-y][$pos-x]; + next direction unless @puzzle[$pos-y][$pos-x]; # If neighbors exist in this direction then add them # to @neighbors[$y][$x] array. |