about summary refs log tree commit diff stats
path: root/lib/Octans/Puzzle.rakumod
blob: 8e184f81562f4163df6a6f8a55a1d1e5f0ff8d33 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class Puzzle is export {
    has @.grids;
    has @!gray-squares;

    submethod TWEAK() {
        for 0 .. @!grids.end -> $y {
            for 0 .. @!grids[$y].end -> $x {
                # Remove the markers from the puzzle & push the
                # positions to @!gray-squares.
                if @!grids[$y][$x].match("*") -> $match {
                    @!grids[$y][$x] = $match.replace-with("");
                    push @!gray-squares, ($y, $x);
                }
            }
        }
    }

    # 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 square is a gray square.
    method is-gray-square(Int $y, Int $x) {
        return so @!gray-squares.grep(($y, $x));
    }
}