Subject: | Patch + Tests against Games::Trackword |
Using a given Boggle::Board and it's known list of solutions
I could not get Games::Trackword to find all of the words.
I noticed that not all valid search paths were being searched.
Patch + test attached.
Subject: | Trackword.patch |
--- Trackword.pm.orig 2006-05-23 23:10:17.000000000 -0400
+++ Trackword.pm 2006-05-23 23:09:09.000000000 -0400
@@ -31,7 +31,7 @@
=cut
-my @directions = ([-1,0],[0,-1],[1,0],[0,1]);
+my @directions = ([-1,0],[0,-1],[1,0],[0,1],[1,1],[-1,1],[1,-1],[-1,-1]);
sub new {
my ($class, $string) = @_;
@@ -86,6 +86,9 @@
sub _can_play {
my ($board, $word, $posy, $posx) = @_;
+ if ($posy < 0 or $posx < 0){
+ return 0;
+ }
if (length $word > 1) {
my $last = chop $word;
if($board->[$posy][$posx] eq $last) {
Subject: | 03thorough.t |
#!/opt/perl/bin/perl
use Test::More tests => 68;
use lib 'lib';
use Games::Trackword;
# Test case from http://www.circlemud.org/~jelson/software/boggle.html
my $board = q/OAAN ETRI IHKR IFLV/;
my @solution = <DATA>;
chomp @solution;
my $board = Games::Trackword->new($board);
my @results;
for my $word ( @solution ){
my $has_word = $board->has_word($word);
push @results, $word if $has_word;
ok( $has_word, "$word is on the board");
}
is_deeply( \@solution, \@results, 'All words found');
__DATA__
oat
oath
oar
ate
atria
art
aria
ark
ani
ain
air
airn
airt
airth
nark
naira
eat
eath
ear
earn
earth
eta
eth
toe
toea
tao
tae
tar
tarn
tan
tain
tea
tear
train
traik
tie
the
rat
rato
ratan
rate
rath
rathe
ran
rani
rain
ria
riata
rin
rhea
irate
irk
heat
hear
heart
het
hetaira
hie
hit
kin
kina
kir
kirn
khet
khi
fie
fit