Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
my $newmask = ( $old ^ $word ) =~ tr/\0/\xff/cr; $flip and ( $board, $heights ) = flip $board, $heights; substr $board, $pos, length $word, $word; #say "new mask is $newmask"; substr $heights, $pos, length $highs, ( $highs & $newmask ) =~ tr/0-4/1-5/r | ( $highs & ~$newmask ); $flip and ( $board, $heights ) = flip $board, $heights; my $tiles = join '', @tiles; say "word is $word"; $tiles =~ s/$_// for split //, $word & $newmask;

let me try...

my $newmask = ( $old ^ $word ) =~ tr/\0/\xff/cr;

$newmask is "\xff" where the old and new words differ, that is a new tile must be used. It is "\0" where no tile is to be placed (using existing board state).

$flip and ( $board, $heights ) = flip $board, $heights; substr $board, $pos, length $word, $word; #say "new mask is $newmask"; # $newmask has unprintable characters +, use something like Data::Dump that will show them. substr $heights, $pos, length $highs, ( $highs & $newmask ) =~ tr/0-4/1-5/r | ( $highs & ~$newmask );

hehehe! GOAL => increment the stack sizes for only the new tiles.

$highs & $newmask produces a string that only has non-null characters where new tiles are to be played. In other words, it isolates the stacks for the new tiles, everywhere else is "\0".
=~ tr/0-4/1-5/r increments the height for each place a new tile is played.
~$newmask inverts $newmask to be "\xff" only where old tiles remain visible.
$highs & ~$newmask produces a string with only the unchanged stack values (and "\0" where the new values are).
Finally, the | puts the old and new stack counts together so they can be replaced in the heights string.

$flip and ( $board, $heights ) = flip $board, $heights; my $tiles = join '', @tiles; say "word is $word"; $tiles =~ s/$_// for split //, $word & $newmask;

This removes the tiles that are used for this word from the string of all tiles, soon to be replaced in @tiles.

Hope this helps...


In reply to Re^5: implementing a scrabble-esque game on Termux III by tybalt89
in thread implementing a scrabble-esque game on Termux III 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 having an uproarious good time at the Monastery: (5)
As of 2024-04-25 14:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found