in reply to Re^2: implementing a scrabble-esque game on Termux III
in thread implementing a scrabble-esque game on Termux III
$board =~ /(?<!\w).{2,}(?!\w)(?{ push @pat, [ $-[0], $& ] })(*FAIL)/ +;
This is the heart of finding a place to move. For a word to be a legal move, it must match one of the patterns in @pat.
The (?<!\w) prevents putting the new word next to a preceding word, and the (?!\w) prevent putting the new word abutting a following word.
The(*FAIL) forces the regex engine to try every possible place to find a match.
Try
perl -le ' "abcd" =~ /.{2,}(?{print $&})(*FAIL)/ '
and notice it prints out every substring with two or more characters.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: implementing a scrabble-esque game on Termux III and Path::Tiny output
by Aldebaran (Curate) on Dec 03, 2019 at 06:53 UTC | |
by tybalt89 (Monsignor) on Dec 03, 2019 at 16:42 UTC | |
by tybalt89 (Monsignor) on Dec 03, 2019 at 08:43 UTC | |
by Aldebaran (Curate) on Dec 10, 2019 at 05:19 UTC |
In Section
Seekers of Perl Wisdom