Scrabble Search

[Home]   [Puzzles & Projects]    [Delphi Techniques]   [Math topics]   [Library]   [Utilities]

 

Search

Search WWW

Search DelphiForFun.org

As of October, 2016, Embarcadero is offering a free release of Delphi (Delphi 10.1 Berlin Starter Edition ).     There are a few restrictions, but it is a welcome step toward making more programmers aware of the joys of Delphi.  They do say "Offer may be withdrawn at any time", so don't delay if you want to check it out.  Please use the feedback link to let me know if the link stops working.

 

Support DFF - Shop

 If you shop at Amazon anyway,  consider using this link. We receive a few cents from each purchase.   Thanks.


Support DFF - Donate

 If you benefit from the website,  in terms of knowledge, entertainment value, or something otherwise useful, consider making a donation via PayPal  to help defray the costs.  (No PayPal account necessary to donate via credit card.)  Transaction is secure.

Contact

Feedback:  Send an e-mail with your comments about this program (or anything else).

Search DelphiForFun.org only

 

 

Problem Description

Here's a Scrabble "Helper" program which finds eligible words from the Official Scrabble Word List (TWL06 = 2006 Tournament Word List) given given available tile letters and information about potential connecting letters on the board.     

Background & Techniques

We had time over the year-end  holidays this year (2013) to play some games with the extended family.  Boys have a distinct disadvantage in  language-oriented games like Scrabble.  I came in third in a 4 player Scrabble game, beaten by my wife and a granddaughter.  (I did beat my son though!)  Their Scrabble set included a large book of valid Scrabble words and a 3-minute timer to limit the time spent checking for high scoring words.   Today's program is an equalizer because it can perform searches thousands of times faster than we poor humans.  Now if I can only convince the girls to let me use it J.

Use with a physical board and tiles:

Players can draw tiles and enter or update their tile letters in the text area.  The program will never allow more than 7 letters in the set so deletions must be made before additions.

By examining the current board state, they then enter  or update the best letters to  connect to.  Likely candidates are those letters which could lead to multiple word and/or letter scores  or have many eligible empty letter spaces before or after the connecting letter.  Each candidate letter is entered as a 3 symbol key with format (# of eligible empty cells before the letter, the letter, # of eligible cells following the  letter).  

After intersection keys are entered, clicking the "Search for Words" button will produce a ranked list of candidates for each connecting letter entry.  "Raw" word scores are listed with each candidate, obviously not knowing what effect the word or letter multipliers might have on the true score.   Optionally, after electing the word to enter, clicking it will automatically delete the used letters from to tile set.  This can also be accomplished by manually editing the text letters.     

 Using program tile management:

This is an experimental feature which provides a 10x10 tile grid containing a shuffled version of the 100 tiles lying face down.  After letters are removed from the player's letter set, either manually or by clicking on the word played. The player may then click individual face-down tiles in the tile grid to add them to his letter set.  Players may also double click on the letter display area to randomly draw enough tiles to restore the player's supply back to 7.   The feature to allow players to exchange tiles  selected from the tile grid as a move is not currently implemented.  Another disadvantage of this feature is that all players must use the same tile board which currently means sharing a single Windows laptop or tablet.

 Helper or Cheater?

While  searching for Scrabble rules I ran across a "Scrabble Cheats" web page which reports that many aficionados consider using a dictionary to be "cheating" and I suppose in tournament play it would be.  For friendly play, it seems  to be a good way to increase vocabulary.   By not considering word and letter multipliers in ranking possible words, there is still plenty of room for mental exercise which candidate words to place in which locations. 

 Non-programmers are welcome to read on, but may want to jump to bottom of this page to download the executable program now.

Programmer's Notes:

Interesting problems addressed in coding this program include:

bulletControlling entries representing each player's tiles.  Only up to 7 letters "A" though "Z" and the blank tile can be accepted.  The grid version of the text of the tiles was added primarily to make the presence to blank tiles clear to players. I used the "Key Up" event exit to validate the key pressed but by that time the letter has already been added which complicates the process.  Eliminating the text input and using only the string grid tile images might be a better solution. 
bulletRepresenting available areas for connecting new words.  The 3 character key with  digit-letter-digit format lets player's specify how many spaces are available before and after the subject letter.
bulletBuilding letter strings to test against the word list file.
bulletSearch for word lengths, N,  between 2 and the smaller of
bullet8 (7 user tiles plus the connecting letter) and
bulletthe sum of possible letter before and after the connecting letter plus1.
bullet Permute players letters taking all arrangements of N of the 7 user letters for each N value.
bulletFor each permuted subset of letters, insert the connecting letter in all positions which do not violate the letters before and after constraint.
bulletIf one or both "blank" tiles are in the user set, substitute each letter "A" though "Z" in place of each blank.
bulletValidate each potential word against a list of words already found (to avoid duplicates) and against the master word list to find valid words.  Both lists are maintained as sorted TStringList types which makes for fast lookups.
bulletDrawing face-up tiles.  An "OnDrawCell" exit allows us to check each passed letter from the player's tile set and display it size 12 toward the lower left corner of the tile.  The value is obtained from a Values integer array index by characters "@" through "Z".  ("@" is the predecessor of "A" and is used to hold the value of the blank tiles (0).   
bulletImplementing a 3 minute countdown timer.  I was surprised that I hadn't done one of these, but it is quite straight forward.  A TTimer control fires at 1000ms (1 second) intervals when it is enabled.  To start the timer, we set  StopTime variable as current Time+ 180 seconds, make the time display label visible, and enable the timer.   In the timer exit, we calulate StopTime - Current Time and display it with a call to FormatDateTime using format string 'n:ss'.  ("n" is the minutes format character since "m" was already taken for displaying "months".) 
bulletHandling the 100 tile set.
bulletBuilding a face-down shuffled array of all 100 tiles.  I initially defined prefilled Counts and Values arrays each with 27 entries indexed by characters "@' to "Z" with "@" entries holding the count (2) and value (0) for the blank tiles.    The 100 entry TilesArray is then filled with Counts[x] occurrences of characters x from "@" to "Z".   The 10x10 TileGrid is filled from the LoadBoardGrid procedure by generating and shuffling a Deck array with digits 0 through 99.   The Deck array is then processed sequentially placing TilesArray[Deck[N]] at location TiledGrid[N div 10, N mod 10].          
bulletTracking which ones have been drawn.  As tiles are "drawn" from TileGrid, that Cell is set to "0" indicating that the cell is empty, and an AvailTileCount variable which started at 100 is decremented by one.  
bulletGenerating a random sample from those tiles not yet drawn.     When a random tile is to be drawn, we generate a number. K,  using Random(AvailTileCount)+1 and scan TileGrid by column and row until the Kth unused tile is found.

Running/Exploring the Program 

bulletDownload  executable
bulletDownload source  (Note: Several units used by this program reside in our library zip file of commonly used units.  Library file DFFVLIB13 or later is required to recompile this program )
bulletDownload current library file (DFFLibV15).

 

Suggestions for Further Explorations

.Text entry of user tiles should be replaced by clicking and keying on the MyTileGrid tile images.
.With full knowledge of the board, the program could do a much better job of evaluating and ranking word values by knowing availability of double and triple word and letter scores in relation to possible connecting letters.  In fact, the program could become an almost unbeatable opponent unless it was "dumbed down".
 
   
   

 

Original:  January 5, 2014

Modified:  February 18, 2016

 
  [Feedback]   [Newsletters (subscribe/view)] [About me]
Copyright 2000-2017, Gary Darby    All rights reserved.