CSSE 230
Scrabble Project

Background - the game and the project

This is a team assignment, to be done by teams of four students (a couple of teams may have fewer students). 

The Scrabble crossword game has been sold in its current form since 1948.  According to http://en.wikipedia.org/wiki/Scrabble , one-third of American households own a Scrabble set. If you are not familiar with the game, skim the the above article. 
Even if you are familiar with the game, you should refresh your memory by reading the official rules at http://www.hasbro.com/scrabble/en_US/rulesSetup.cfm .  You also will want to click the Game Play and Scoring links to see the details.  

Once you understand the basics of Scrabble scoring, see this example that scores 1830 points on one play: http://www.fun-with-words.com/scrabble.html .  The description of how this works and the suggestions on that page of how to try to get a higher score will probably increase your understanding of Scrabble scoring. Your team may want to get together to play a few games of scrabble as a fun way to get up to speed on scoring.

A human Scrabble player may settle for a lower score for a given turn in hopes of saving "good" tiles and drawing new tiles that enable a "big play" on a subsequent term.  But your computer player can take a simpler "greedy" approach, getting the largest score that it can find for each turn, regardless of future potential.

Your game should have three different modes: For testing purposes, we are much more interested in the computer player; the human player is there mainly to make it easier to test and debug your scoring algorithm and legal move verification, and to provide a WYSIWYG way for you to create and save specific games that can demonstrate your computer player's ability to find good plays.

The major things that your code must do

Time requirements:  Your program should be able to load the dictionary into your data structure in about a minute, and your computer player should decide what to play for a single turn in less than 10 seconds.

Milestones

1 (30) Wednesday, 8th week 8:00 AM 3-4 page document describing the data structures and algorithms you plan to use for finding the best word to play. Probably will focus on the Scrabble and Scrabble dictionary classes, and other classes used by them.  Include UML class diagram. Should also include a description of your GUI enhancements:  For example, how will human player indicate what letters to play where?
Submit to a drop box on ANGEL.
2 (50) Friday, 9th week 8:00 AM Rubric Working, well-documented code for a human player, ability to load and save games. Commit to your repository.
3 (150) Wednesday, 10th week 8:00 AM Rubric Final, well-documented code for both human and computer players. Commit to your repository.
4 (30) Thursday, 10th week in-class Rubric ≤ 7-minute presentation about your algorithms and data structures. May include a demo, if your program has unique features.
5 (30) Thursday, 10th week Noon Performance evaluation of team members, including yourself.

A sticky (a.k.a. GUI) situation

Writing a GUI for Scrabble from scratch would be an interesting and enlightening thing to do, but we want you to focus on the course's title, Data Structures and Algorithms. While you are welcome to be creative and produce your own user interface, this is not required. We have provided a basic user interface which you can extend in various ways.  But of course you can write your own if you prefer.

The starting code that we providing for you (ScrabbleFrame.java and other classes that it uses) already allows you to display a board and load a game file. It calls the ScrabbleDictionary constructor to build a dictionary object for the game to use.  At this point that constructor does not actually build a dictionary.  That is one of your main tasks.

THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN  THE SOFTWARE.  But even if it has a bug or two, hopefully you will find it a lot easier than writing your own from scratch!

There are a few new GUI features (widgets) that you should add (as buttons, menu items, or something).  The names I give here do not have to be the words that the user sees; they are meant to convey the idea of the functionality needed.  Not all of these will be relevant to all of the modes; ideally thay should only appear in relevant modes.

  1. New game.  Loads the default scrabble board with the default set of tiles, shuffles the tiles and puts seven of them in the player's hand. Displays those tiles.  Sets score to zero. You should be able to start a new game at any point in time without restarting the GUI.
  2. Save game.  Prompts the user for a filename and saves the current game info in the .scrabble format (see below).
  3. Load Game.  Loads a previously saved game, in .scrabble form.  This code already exists, but only works for H mode.  You need to make it work for the other nodes also.
  4. Help screen(s).  Describe how the user can do things (anything that is not obvious from the GUI).
  5. Exchange.  The user selects one or more tiles to exchange, and the program draws the same number of tiles from the tile bag (if available) to replace them. Shuffles tile bag after returning tiles from user hand.
  6. Shuffle.  tileBag must not be automatically reshuffled except at the beginning of a new game or after a tile exchange.  This widget causes it to be shuffled.
  7. Human Play. Allows the user to easily choose the tiles to play and where to play them.  Could be done with a dialog box in which the user types the letters, coordinate of first letter, and direction (horizontal or vertical). Game will be more fun to use if the mouse can be used to provide this information by clicking and dragging on tiles and board squares.
  8. Computer Play.  Computer player makes its next play; tries to exchange tiles if nothing can be played.
  9. Computer Play All.  (in computer-only mode) Computer player makes all of the rest of the plays it can make, and displays final board and score.  It is possible that tile exchanges may be needed along the way (be careful to avoid infinite loops here).
  10. Show History.  Display the sequence of plays made so far.  For each word played, display the main word played, any additional words that are formed by the play, the total score for that play, and that player's total score in the game so far. 
  11. Make the letters more visible (than in the provided GUI) when played on the "triple letter" background.  Perhaps change the color, change the font size, or change the background of the letters to look more like tiles.

Important note: The Scrabble, TestCasesGameState, and ScrabbleDictionary classes know nothing about the GUI.  This separation of functionality is A Good Thing, and we insist that you maintain it. For example,  it is possible to write tests of these classes that are independent of any GUI. 

Other provided code and data

The Scrabble class is the brains of the operation.  It (and any classes that you write to assist it in its work) maintains the state of the came, checks for legal plays, calculates scores, and chooses a play for the computer player.

A ScrabbleDictionary object contains your efficient data structure for accessing the dictionary in ways that your Scrabble class needs to access it.  It is constructed from a .sd file, a text file which contains one word per line.

A GameState object contains the dynamic information about the result of a play.  Basically it is what a GUI needs to know in order to properly update itself.  Must be modified to accommodate 2-player game.

One of the Scrabble constructors reads a .scrabble file and creates a Scrabble object that represents a saved game.

The provided dictionary data file, dictionary01.sd, is one that we found online. It is a combination of the 95% SCOWL list that we used in Doublets and the 2- and 3-letter words from the official Scrabble dictionary, as reported here.

Some sample saved games are provided in the ScrabbleFiles folder.

Javadoc documentation for the prvided classes is provided in your repository, and also here.  May be slightly out-of-date.

Important note:  Your team is not required to use any of the provided code, or even the same class names.  You may modify or replace any of the code, or throw it all away and start "from scratch" if you wish.

Contents of a .scrabble file

This file format was designed to allow for different odd board sizes, but to make your life easier (so you don't have to mess with the GUI much), your code only has to handle 15 x 15 boards. It is possible that a board may have a non-standard configuration in terms of where the premium squares are, that the hand-size may be different than 7, or that there may be a non-standard collection of tiles in the tile bag.

The first line in the file must contain 3 items, separated by spaces. These are the maximum hand size (7 in the example), the board dimension (you can always assume 15, due to how we wrote the provided GUI), and the player mode (2, H, or C, representing 2-player, human-only, computer-only, respectively).

The contents of the second line vary according to the mode from the first line

After the first two lines, the next N lines will be the board configuration, i.e. the layout of special point modifier squares, where N is the previously defined dimension of the board. T, t, D, d, and * mark the special squares:

T – triple word score

t – triple letter score

D – double word score

d – double letter score

* - center space that must be used on first move (this is also a double word score space)

Immediately after the board configuration, the next N lines (once again N is the board dimension) will be the current status of the board in regard to what letters are already on the board and where.  The spaces in the picture are simply squares with no tiles, so the first line in the example is 15 spaces, as is the second line and so forth until there is BOO in the middle of a line.  When a blank tile is played, it is necessary to declare what letter it represents; e.g., when a blank has been played as a P, its position on the board in a .scrabble file is represented by a lower-case p.

The last required line of the file represents the tile bag. These are the characters yet to be drawn; they are provided in the opposite of the order they will be drawn from the bag. This will make the ArrayList manipulation more efficient.

Do not insert any extra lines between the sections.

After the line that contains the tile bag, files may optionally contain any number of additional lines.  These lines may include English comments concerning expected next plays, additional data related to some enhancement that your group adds to the program, or anything else you want to add.

Knowing this format should allow you to create your own test files, using a text editor or using your program.

Examples of play and scoring

The example shown as a file above and as a board below can be found in test03.scrabble. For this example, assume that the letters C, R and W were the last to be played. On that turn, the player earned points for each letter in CROW and in TOW (W will be counted twice). However, special squares only count if they are underneath the C, R or W.  

Now suppose the board layout is the same as above, but a different set of letters is in the player's hand: POSEDIE. On the next play, the player might play S to the right of ROT, O to the right of LO, and D to the right of CROW; this would earn points for playing the main word SOD(8 points), and for the additional words ROTS(4 points), LOO(3 points), and CROWD(15 points).  Once again, double or triple scores only count if they are associated with the squares where S, O, and D are played. 
An even better play:  play EPISODE vertically, with the P immediately to the right of BO.  Now five different words are created: EPISODE (20 points), BOP(13 points), ROTS(4 points), LOO(3 points), and CROWD(15 points). In addition the player gets 50 bonus points for playing all seven tiles, so the total score for this play is 105 points (check me on the individual word scores and the total!).

 

Scrabble discussion forum on ANGEL

It is there. You may want to subscribe to it.   This forum will be the main place for asking/answering questions about this project.