in reply to using perl to find words for scrabble

I have been playing a variety of games like Scrabble and wanted to work up a perl utility to tilt the game in my favor.

Always a fun challenge.

are you aware of any existing solutions to this

Games::Literati, originally by Chicheng Zhang (and now maintained by me), implements the rules for Scrabble (or Super Scrabble), Literati (the early-2000's yahoo-games clone), and Words With Friends. You can also implement custom boards, though my TODO on documenting that one has never been finished -- but if you study how the individual games are done, you should be able to figure out how to define your own gameboard function. For playing, you just have to supply a valid text dictionary file (one word per line), in whatever language you want. It originally started with Scrabble and Literati; when I took it over, I added Super Scrabble and Words With Friends (and fixed a couple scoring bugs). If you come up with a better algorithm for implementing the search than Chicheng Zhang did, and wanted to make a pull request, feel free (likely to be merged, as long as it passes all the coverage tests and doesn't change the user-interface, thus messing up my WWF-games-in-progress).

update: link fixed. Thanks Discipulus and Corion

  • Comment on Re: using perl to find words for scrabble

Replies are listed 'Best First'.
Re^2: using perl to find words for scrabble
by Aldebaran (Curate) on Sep 07, 2019 at 17:46 UTC

    I'd like to replicate what has gone before and ride that horse as far as I can. The module installs fine, and I got the dictionary downloaded. Who would have guessed that it takes 1.83 megs to capture the english language in this way? Let me post a link to the very useful page that the dictionary came from: google code archive. the entry you're looking for is enable1.txt .

    Then I try to follow the development on Games::Literati but don't seem to get anywhere on the invocation, and why would I, as right now, the command line has no connection to the dictionary?

    C:\Users\tblaz\Documents\evelyn>perl -MGames::Literati=scrabble -e'scr +abble()' < t.txt C:\Users\tblaz\Documents\evelyn>type t.txt ............... ............... ............... .......c....... ......ai....... .......s.header .......t....r.. ...jurors..soup .......o....p.h .upsilon.f..pea .......speering .........s..n.e .........t..g.. .........e..... ........broils. yes 7,8 10,14 7,14 eurmsss C:\Users\tblaz\Documents\evelyn>

    Meanwhile, I have an ordinary script as I know how to create them with the location of the dictionary as a script that does not receive reference:

    C:\Users\tblaz\Documents\evelyn>type 1.game.pl #!/usr/bin/perl -w use 5.016; use Data::Dump; my $WordFile = 'C:\Users\tblaz\Documents\html_template_data\dict\enabl +e1.txt'; C:\Users\tblaz\Documents\evelyn>

    How do I brook this gap?

    Thanks all for comments,

      My invocation is perl -e "use Games::Literati qw(wordswithfriends); $Games::Literati::WordFile = qq(/usr/dict/wordswithfriends.dict) ; wordswithfriends()" < t.txt

      Looking at your invocation: you're obviously on windows; the -e one-liner on Windows requires double-quotes, not linux single quotes; if I try with linux single quotes, I get nothing. If I convert your oneliner to double-quotes instead of single-quotes, it gives the error:

      Hashing words... Cannot open words file "./wordlist" No such file or directory at -e line 1.

      For your setup, I believe you should use perl -MGames::Literati=scrabble -e"$Games::Literati::WordFile = 'c:\users\tblaz\documents\html_template_data\dict\enable1.txt'; scrabble()" < t.txt. In your script version, $WordFile should not be a my variable; it's part of the Games::Literati module, so, as the documentation says, "These variables are exportable, so can be fully qualified as %Games::Literati::valid, or if included in the export list when you use the module, you can reference them directly", and then gives a multiline example. In your case you'll either need to use Games::Literati qw(scrabble $WordFile); $WordFile = '...';, or use the variable fully qualified variable name, as in use Games::Literati qw/scrabble/; $Games::Literati::WordFile = '...';

        I have output now, and I must say, it is impressive. Quick, too. There's probably much more time in keeping an accurate representation of the board than thinking time for a best next move:

        C:\Users\tblaz\Documents\evelyn>perl -MGames::Literati=scrabble -e"$Ga +mes::Literati::WordFile = 'c:\users\tblaz\documents\html_template_dat +a\dict\enable1.txt'; scrabble()" < t.txt Hashing words... ... ---------Scrabble---------- Board: ............... ............... ............... .......c....... ......ai....... .......s.header .......t....r.. ...jurors..soup .......o....p.h .upsilon.f..pea .......speering .........s..n.e .........t..g.. .........e..... ........broils. Is the above correct? wild tiles are at:[Row1,Col1 Row2,Col2 ...] Enter tiles: Looking for solutions for eurmsss(in X axis)... Board: ............... ............... ............... .......c....... ......ai....... .......s.header .......t....r.. ...jurors..soup .......o....p.h .upsilon.f..pea .......speering .........s..n.e .........t..g.. .........e..... ........broils. using 6 tiles: (18) row 3 become: 'cussers' starting at column 8 (9) row 12 become: 'russets' starting at column 4 using 5 tiles: (16) row 3 become: 'cruses' starting at column 8 (16) row 3 become: 'curses' starting at column 8 ... (2) column 14 become: 'er' starting at row 4 (7) column 14 become: 'phages' starting at row 12 Possible Top Ten Solution 1: row 14 become: 'embroils' starting at col +umn 6 using 2 tile(s), score 36 Possible Top Ten Solution 2: row 4 become: 'aimer' starting at column +8 using 3 tile(s), score 23 Possible Top Ten Solution 3: row 6 become: 'stems' starting at column +6 using 4 tile(s), score 23 Possible Top Ten Solution 4: row 6 become: 'stums' starting at column +6 using 4 tile(s), score 23 Possible Top Ten Solution 5: column 2 become: 'sperms' starting at row + 8 using 5 tile(s), score 22 Possible Top Ten Solution 6: column 2 become: 'spumes' starting at row + 8 using 5 tile(s), score 22 Possible Top Ten Solution 7: row 4 become: 'em' starting at column 9 +using 2 tile(s), score 21 Possible Top Ten Solution 8: row 4 become: 'um' starting at column 9 +using 2 tile(s), score 21 Possible Top Ten Solution 9: column 2 become: 'sperm' starting at row +8 using 4 tile(s), score 20 Possible Top Ten Solution 10: column 2 become: 'spume' starting at row + 8 using 4 tile(s), score 20 C:\Users\tblaz\Documents\evelyn>

        If I were to go farther with this, I'd have to get off the command line. Also, I haven't cobbled together how a person completes a "turn."

        So how can we do this without an indirection operator on the command line?