summaryrefslogtreecommitdiff
path: root/lib/GridFiller/Status.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/GridFiller/Status.pm')
-rw-r--r--lib/GridFiller/Status.pm80
1 files changed, 2 insertions, 78 deletions
diff --git a/lib/GridFiller/Status.pm b/lib/GridFiller/Status.pm
index 873d252..4f55c6f 100644
--- a/lib/GridFiller/Status.pm
+++ b/lib/GridFiller/Status.pm
@@ -17,11 +17,13 @@ has words_to_use => (
get_next_word => 'shift',
},
is => 'rw',
+ required => 1,
);
has grid_status => (
isa => GridStatusT,
is => 'rw',
+ required => 1,
);
around BUILDARGS => sub {
@@ -92,53 +94,6 @@ sub unfilled {
return 0;
}
-sub find_place_for {
- my ($self,$word) = @_;
-
- my $dir = int(rand(2)) ? $HORIZONTAL : $VERTICAL;
-
- my $length = length $word;
-
- my @ret;
-
- if ($dir == $HORIZONTAL) {
- @ret = $self->_find_place_horiz($length);
- @ret = $self->_find_place_vert($length) unless @ret;
- }
- else {
- @ret = $self->_find_place_vert($length);
- @ret = $self->_find_place_horiz($length) unless @ret;
- }
-
- return @ret;
-}
-
-sub _find_place_horiz {
- my ($self,$length) = @_;
-
- my $rows = scalar @{$self->grid_status};
- my $col;
-
- for my $row (0..$rows-1) {
- $col = $self->_find_in_row($row,$length);
- return ($col,$row,$HORIZONTAL) if defined $col;
- }
- return;
-}
-
-sub _find_place_vert {
- my ($self,$length) = @_;
-
- my $cols = scalar @{$self->grid_status->[0]};
- my $row;
-
- for my $col (0..$cols-1) {
- $row = $self->_find_in_col($col,$length);
- return ($col,$row,$VERTICAL) if defined $row;
- }
- return;
-}
-
{
my %symbols=(
$NOTHING => ' ',
@@ -146,37 +101,6 @@ my %symbols=(
$WHITE => 'O',
);
-sub _do_find {
- my ($self,$str,$length) = @_;
-
- my ($skip) = ($str =~ m{^ (.*?) (?: X{$length} | O{$length} ) }x);
-
- $self->log->debug(defined $skip ? " skip <$skip>" : " nope");
-
- return length($skip) if defined $skip;
- return;
-}
-
-sub _find_in_row {
- my ($self,$row,$length) = @_;
-
- my $str = join '',map { $symbols{$_} } @{$self->grid_status->[$row]};
-
- $self->log->debug("row $row = $str");
-
- return $self->_do_find($str,$length);
-}
-
-sub _find_in_col {
- my ($self,$col,$length) = @_;
-
- my $str = join '',map { $symbols{$_->[$col]} } @{$self->grid_status};
-
- $self->log->debug("col $col = $str");
-
- return $self->_do_find($str,$length);
-}
-
sub to_string {
my ($self) = @_;