Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
How about you have the phone take a picture of the board, reconstruct the board in memory, find best move for you? And optionally looking ahead and minimising the score of your opponent's next move.

I would love to be able to use phone technology in such a manner. These might be my first tepid steps to coding for this device. I'm always glad to entertain asides and "what are we on the cusp of" discussions, provided that we're also addressing the main topic of the thread.

but I could not see a function which searches for words in dictionary when some of its letters are clamped on specific values. I.e. for those letters already set on the board squares where you plan to place your new word.

I have some ideas on how to deal with that clamping. Our algorithm would move bottom to top for possible placing of vertical vectors, and right to left if they are horizontal. I would think that that would create analogous logic for the two cases. You either have to place your tiles vertically, or horizontally, but never both.

So, can you start with a filter for the results of tybalt89's my $pattern = join '', map "$_?", sort @tiles; to make sure your candidate words have specific letters at specific positions?

The resulting string is simply the tiles with a question mark as padding. I didn't find that useful for this version.

Then have another function which calculates the score of each candidate word taking into consideration what's already on board (i think appending to existing words gives you extra credit?). Would that be easier by having that function taking the board state as input, adds your candidate word in it and re-calculates the total board score? Subtracting this from initial score will be your word's score - more or less, right?

I've started with a calculation function and "gotten on the proverbial board." Let me trot out some output then source next:

C:\Users\tblaz\Documents\evelyn>perl 1.board.pl [ [ { height => 0, letter => "." }, { height => 0, letter => "." }, { height => 0, letter => "." }, { height => 0, letter => "." }, { height => 0, letter => "." }, ... { height => 0, letter => "." }, { height => 0, letter => "." }, { height => 0, letter => "." }, { height => 0, letter => "." }, ], ] input is acehioo Found 7,012 1-7 letter strings in acehioo. Found 33 words in acehioo. chiao : 5 achoo : 5 ciao : 4 chao : 4 echo : 4 ohia : 4 chia : 4 coho : 4 each : 4 ache : 4 ich : 3 oca : 3 chi : 3 ice : 3 hic : 3 hae : 3 ace : 3 hao : 3 hie : 3 ooh : 3 oho : 3 hoe : 3 coo : 3 ho : 2 oh : 2 ha : 2 ai : 2 hi : 2 ah : 2 eh : 2 ae : 2 he : 2 oe : 2 { ace => 3, ache => 4, achoo => 5, ae => 2, ah => 2, ai => 2, chao => 4, chi => 3, chia => 4, chiao => 5, ciao => 4, coho => 4, coo => 3, each => 4, echo => 4, eh => 2, ha => 2, hae => 3, hao => 3, he => 2, hi => 2, hic => 3, hie => 3, ho => 2, hoe => 3, ice => 3, ich => 3, oca => 3, oe => 2, oh => 2, ohia => 4, oho => 3, ooh => 3, } C:\Users\tblaz\Documents\evelyn>perl 1.board.pl [ [ { height => 0, letter => "." }, { height => 0, letter => "." }, { height => 0, letter => "." }, { height => 0, letter => "." }, { height => 0, letter => "." }, ...=> "." }, { height => 0, letter => "." }, { height => 0, letter => "." }, { height => 0, letter => "." }, { height => 0, letter => "." }, ], ] input is aachhil Found 3,591 1-7 letter strings in aachhil. Found 26 words in aachhil. chalah : 6 laich : 5 chia : 4 hila : 4 hail : 4 haha : 4 laic : 4 lich : 4 aha : 3 hah : 3 ich : 3 aal : 3 hic : 3 chi : 3 ail : 3 aah : 3 lac : 3 ala : 3 ai : 2 ah : 2 la : 2 ha : 2 aa : 2 al : 2 li : 2 hi : 2 { aa => 2, aah => 3, aal => 3, ah => 2, aha => 3, ai => 2, ail => 3, al => 2, ala => 3, chalah => 6, chi => 3, chia => 4, ha => 2, hah => 3, haha => 4, hail => 4, hi => 2, hic => 3, hila => 4, ich => 3, la => 2, lac => 3, laic => 4, laich => 5, li => 2, lich => 4, } C:\Users\tblaz\Documents\evelyn><\c> <p>Source:</p> <c>#!/usr/bin/perl use 5.011; use warnings; use Path::Tiny; use Algorithm::Permute; use Number::Format 'format_number'; use List::Util 'uniq', 'shuffle'; use Data::Dump; # the board my @board; foreach my $row ( 0 .. 9 ) { foreach my $col ( 0 .. 9 ) { $board[$row][$col] = { letter => '.', height => 0 }; } } my $refBoard = \@board; dd $refBoard; ## quick and dirty... my @letters = split //, 'aaaaaaaaabbccddddeeeeeeeeeeeeffgggghhiiiiiiiiijkllllmmnnnnnnoooooooop +pqrrrrrrssssttttttuuuuvvwwxyyz'; my @my_orig_chars = ( shuffle @letters )[ 0 .. 6 ]; my $input = join '', map "$_", sort @my_orig_chars; say "input is $input"; my $length = length $input; my @input_chars = split '', $input; my $words_file = 'c:\users\tblaz\documents\html_template_data\dict\ena +ble1.txt'; my %words = map { $_ => 1 } path($words_file)->lines( { chomp => +1 } ); my @partials; for ( 1 .. $length ) { my $P = Algorithm::Permute->new( \@input_chars, $_ ); while ( my @res = $P->next ) { push @partials, join '', @res; } } @partials = uniq @partials; #say "partials are @partials"; say sprintf 'Found %s 1-%s letter strings in %s.', format_number( scalar @partials ), $length, $input; my %found = map { $_ => calc_score($_) } grep { $words{$_} } @part +ials; my $ref_found = \%found; say sprintf 'Found %s words in %s.', format_number( scalar keys %found + ), $input; #my $debug =0; for ( sort { $found{$b} <=> $found{$a} } keys %found ) { say "$_ : $found{$_}"; } dd $ref_found; ############### sub calc_score { my $word = shift; my $val; $val = length $word; return $val; } __END__

Questions:

Q1) How do I print the board by showing the letter value in the hash stored at each array location?

As I'm looking at what I have, I realize what I want for the board. It's to have the column numbers displayed in the first row and the row letters displayed in the first column. We could put a character in the corner like a black square. Thus, the array of hashes will be 11x11, but the values will no longer be zero indexed in a way that needs to be accounted for.

Q2) How do I best create these arrays?

Q3 How am I getting greater than 7! = 5040 values from the uniq call on 7 tiles?

Q4) How to I take the best word that %found has and insert it into the array of hashes at, say, the sixth row beginning at the third column and going right? We are guaranteed to have enough room for the first word. It is the only one that can be played without touching the previous graph at some point. (no floaters after the first one).

Thanks for your comments


In reply to Re^2: Inputing vectors into a scrabble-esque game by Aldebaran
in thread Inputing vectors into a scrabble-esque game by Aldebaran

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-03-29 00:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found