diff options
Diffstat (limited to 'lib/GridFiller.pm')
-rw-r--r-- | lib/GridFiller.pm | 59 |
1 files changed, 40 insertions, 19 deletions
diff --git a/lib/GridFiller.pm b/lib/GridFiller.pm index ebeb933..4ab25ac 100644 --- a/lib/GridFiller.pm +++ b/lib/GridFiller.pm @@ -90,18 +90,6 @@ has result => ( clearer => '_reset_result', ); -sub _build_result { - return [ - map { - [ - map { - [ ( $_ eq '*' ? 3 : 1 ), ' ' ], - } @$_ - ] - } @{shift->grid} - ]; -} - sub _reset { my ($self) = @_; @@ -190,16 +178,49 @@ sub _put_letter_at { return; } +{ +my %colourmap = ( + '*' => { + $HORIZONTAL => { + 0 => 1, + 1 => 2, + }, + $VERTICAL => { + 0 => 3, + 1 => 4, + }, + }, + ' ' => { + $HORIZONTAL => { + 0 => 5, + 1 => 6, + }, + $VERTICAL => { + 0 => 7, + 1 => 8, + }, + }, +); + +sub _build_result { + return [ + map { + [ + map { + [ $colourmap{$_}->{$HORIZONTAL}->{0}, ' ' ], + } @$_ + ] + } @{shift->grid} + ]; +} + sub _find_colour_for { my ($self,$x,$y,$dir) = @_; - # let's be easy - if ($dir == $HORIZONTAL) { - return $self->grid->[$y][$x] eq '*' ? 3 : 1; - } - else { - return $self->grid->[$y][$x] eq '*' ? 4 : 2; - } + return $colourmap{$self->grid->[$y][$x]}->{$dir}->{ + ($dir == $HORIZONTAL) ? ($y % 2) : ($x % 2) + }; +} } sub _find_place_for { |