package GridFiller;
use Moose;
use namespace::autoclean;
use GridFiller::Types qw(GridT WordListT );
use Carp;
with 'MooseX::Log::Log4perl';
has status => (
isa => 'GridFiller::Status',
is => 'ro',
required => 1,
);
has chooser => (
isa => 'GridFiller::Chooser',
is => 'ro',
required => 1,
);
has result => (
isa => 'GridFiller::Result',
is => 'ro',
required => 1,
);
sub fill {
my ($self) = @_;
my $status=$self->status;
my $result=$self->result;
my $chooser=$self->chooser;
while ($status->unfilled() && $status->has_next_word()) {
my $word = $status->get_next_word();
$self->log->debug("Placing $word");
my ($space,$x,$y,$dir) = $chooser->find_place_for($word);
if (! defined $x) {
$self->log->debug("No place for $word");
$result->mark_leftover($word);
next;
};
$result->place_word_at($word,$space,$x,$y,$dir);
$status->place_word_at($word,$space,$x,$y,$dir);
if ($self->log->is_debug) {
$self->log->debug($status->to_string);
$self->log->debug($result->to_string);
}
}
return;
}
1;