Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re^4: Problem with regex wildcard operator (.)...?

by Marshall (Canon)
on Sep 06, 2021 at 04:55 UTC ( #11136493=note: print w/replies, xml ) Need Help??

in reply to Re^3: Problem with regex wildcard operator (.)...?
in thread Problem with regex wildcard operator (.)...?

I am still not "getting it" in terms of your input syntax and how it should match against the dictionary.

I recently wrote a "cheater program" for a less sophisticated game, but perhaps with some similar matching requirements?

In my game, I have a set of "tiles", letters than I can use to form words. I cannot use any letter other than one of these letters to form words. There are not any 2 letter words in my dictionary. Your dictionary has a lot of weird words, but I guess that is how scrabble is!

Your example is a bit hard for me to figure out since, es,os,sh,si are not "normal English words" although as,is,so are. Likewise "aa" is not a normal English word, although "as" is. There are words in the scrabble dictionary that I've never read, heard or used.

What I'd like to see is a user session that shows how your scrabble cheat game works. I will attach a user example from my cheat program for another game. Once we understand what the code is supposed to do, then at least I would be interested in helping you create a "blackbelt" level cheat program - just for the fun of it!

Here is an example of the kind of example that I want from you:

Example 1: leading ";" means this is a list of letters instead of a pattern list of letters or pattern: ;lolewf list of letters or pattern: --- The --- says: show me all 3 letter words that can be formed from my letter "universe". elf ell few foe fol low owe owl woe # Example 2: # Show me all 4 letter words which can be formed from # the "list of letters" that have "l" as the 3rd letter list of letters or pattern: ;odlswe # List of Letters list of letters or pattern: --l- # A search pattern dole owls sold sole weld wold
I don't know really anything about Scrabble. But I think you will have to develop a syntax to input words that are on the board already. I think if some guy plays "pagan", you can play "ize" to turn this into "paganize" and score big points. In addition, each letter has some kind of "value", playing a "z" is worth more than playing an "a". I suspect that you are going to want a word sort order that instead of being alphabetical, is based upon the point value of the word?

I think your tr statement could be better:
tr is a very stupid thing and it does not use character sets. I am not sure why your code seems to work.

use strict; use warnings; my $string = '\abCD'; $string =~ tr/\[A-Z]/[a-z]/; #should be tr/A-Z/a-z/? print "$string\n";

Replies are listed 'Best First'.
Re^5: Problem with regex wildcard operator (.)...?
by AnomalousMonk (Bishop) on Sep 06, 2021 at 07:19 UTC
    I am not sure why your code seems to work.

    It works because \[ is just an escaped [, so tr/\[A-Z]/[a-z]/ is translating [ to [, ] to ], and uppercase to lowercase. Any other character, e.g., \, is unaffected.

    Give a man a fish:  <%-{-{-{-<

      Thanks for the explanation! I did not think that an escape '\' would work within TR. Even though that does indeed work, I prefer my tr/A-Z/a-z/ because it is easy for me to understand it at a glance. Of course, mileage varies.
        I prefer ... tr/A-Z/a-z/ ...

        So do I - or better yet lc in this case. :)

        Give a man a fish:  <%-{-{-{-<

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2022-10-07 15:29 GMT
Find Nodes?
    Voting Booth?
    My preferred way to holiday/vacation is:

    Results (30 votes). Check out past polls.