From bdb1dbcea8c4ab9270caeacf6bfb448c35824a90 Mon Sep 17 00:00:00 2001 From: Andinus Date: Thu, 4 Mar 2021 14:26:19 +0530 Subject: Mark visited gray squares with "*" --- lib/Octans/CLI.rakumod | 6 +++++- lib/Octans/Puzzle.rakumod | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/Octans/CLI.rakumod b/lib/Octans/CLI.rakumod index 0672761..3a5be30 100644 --- a/lib/Octans/CLI.rakumod +++ b/lib/Octans/CLI.rakumod @@ -51,7 +51,11 @@ multi sub MAIN( print " " x 3; for ^$puzzle.grids[$y].elems -> $x { printf " {$puzzle.grids[$y][$x]}%s", - @visited[$y][$x] ?? "/" !! " "; + @visited[$y][$x] + # visited gray squares get marked with "*", + # visited squares with "/" & unvisited with " ". + ?? ($puzzle.is-gray-square($y, $x) ?? "*" !! "/") + !! " "; } print "\n"; } diff --git a/lib/Octans/Puzzle.rakumod b/lib/Octans/Puzzle.rakumod index 731cc8e..e88a74a 100644 --- a/lib/Octans/Puzzle.rakumod +++ b/lib/Octans/Puzzle.rakumod @@ -17,4 +17,10 @@ class Puzzle is export { # Accessor for @!gray-squares. method gray-squares() { @!gray-squares; } + + # Given $y, $x where $y is row index & $x is column index, + # is-gray-square returns if the cell is a gray square. + method is-gray-square(Int $y, Int $x) { + return so @!gray-squares.grep(($y, $x)); + } } -- cgit 1.4.1-2-gfad0