Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Word Search Builder

by Fendaria (Beadle)
on Feb 21, 2005 at 23:11 UTC ( [id://433187]=note: print w/replies, xml ) Need Help??


in reply to Word Search Builder

Wonderful little program.

I couldn't help myself from noticing though you can combine your two loops in addWord if you randomize the order you brute force search. As long as your brute force search hits all possibilities, you can search in whatever order you want.

sub randomizeArray(@) { my @array = @_; for my $i ( 1 .. $#array ) { my $j = int rand( $i + 1 ); ( $array[$i], $array[$j] ) = ( $array[$j], $array[$i] ); } return @array; } ## end sub randomizeArray(@) sub addWord { my ( $grid, $word ) = @_; for my $dir ( randomizeArray( 0 .. 7 ) ) { for my $y ( randomizeArray( 0 .. $height - 1 ) ) { for my $x ( randomizeArray( 0 .. $width - 1 ) ) { if ( wordFits( $grid, $word, $x, $y, $dir ) ) { insertWord( $grid, $word, $x, $y, $dir ); return 1; } } } ## end for my $y ( randomizeArray... } ## end for my $dir ( randomizeArray... return 0; } ## end sub addWord

It would also be neat if you allowed for 'turns' when adding a word. ex. in a 2,2 grid allow the word 'perl' as

pe
rl

I think the game 'boggle' allows for word grids in this style.

Fendaria

Replies are listed 'Best First'.
Re^2: Word Search Builder
by aufflick (Deacon) on Feb 22, 2005 at 00:43 UTC
    You're insane! Just as nuts as my girlfriend's flatmate who loves borderless jigsaws that come with extra pieces!
Re^2: Word Search Builder
by pbeckingham (Parson) on Mar 08, 2005 at 16:03 UTC

    Thanks! You're right about the ordering. As for the Boggle thing, I don't know how I might go about that.



    pbeckingham - typist, perishable vertebrate.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://433187]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-19 01:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found