A JavaFX-based implementation of the classic Scrabble board game where two to four players earn points by arranging tiles, each marked with a single letter, on a 15x15 grid board. The tiles need to create words that read horizontally from left to right or vertically downward, intersecting like a crossword, and must be valid according to a standard dictionary. For this assignment, you’ll develop a two-player version pitting a human player against a computer opponent. The game will use a dictionary sourced from a file containing a list of permissible words, and your program must be adaptable to work with any dictionary file provided.
This Scrabble game implementation leverages well-known data structures and algorithms to optimize gameplay performance. A Trie (prefix tree) is used for efficient dictionary lookups, allowing quick validation of words and prefixes. HashMaps provide fast retrieval of letter values and tile frequencies, ensuring efficient scoring calculations. The computer opponent utilizes a priority-based search algorithm to determine the best possible word placement by evaluating potential moves and maximizing the score based on board conditions. These optimizations enhance the game's speed, accuracy, and responsiveness, ensuring a smooth and competitive playing experience.
- The rules of the game is adapted from https://www.hasbro.com/common/instruct/Scrabble_%282003%29.pdf
- The game begins with an empty 15x15 board.
- Each player (human and computer) draws 7 tiles from the Tile Bag to form their initial tray.
- The human player goes first, followed by the computer opponent.
- Turn Structure:
- On a player’s turn, they may:
-
- Play a Word: Place one or more tiles from their tray onto the board to form a valid word.
-
- Swap Tiles: Return one or more tiles to the Tile Bag and draw an equal number of new tiles (if tiles remain in the bag), forfeiting their turn.
-
- Skip Turn: Pass without playing or swapping, allowing the opponent to play.
- After a play, the player draws tiles from the Tile Bag to replenish their tray back to 7 (if tiles are available), then the turn passes to the opponent.
- Word Placement Rules:
- Formation: Tiles must form a single continuous word, reading left to right (horizontal) or top to bottom (vertical), like a crossword. All new tiles in a turn must be placed in a single row or column.
- Connection: After the first move, each new word must connect to at least one existing tile on the board (adjacent horizontally or vertically).
- First Move: The first word must:
-
- Be at least two letters long
-
- Cover the center square (7,7), which is a Double Word Score square.
- Validity: All words formed (the main word and any intersecting words) must be present in the provided dictionary file. Words are case-insensitive (e.g., "CAT" and "cat" are equivalent).
- Blanks: Blank tiles ('*') can substitute for any uppercase letter but score 0 points.
- Scoring:
- Tile Points: Each letter tile has a point value (see above). Blank tiles score 0
- Premium Squares:
-
- If a tile is placed on a premium square, its effect applies only to that turn:
-
-
- Double/Triple Letter Score multiplies the tile’s value (e.g., 'B' on .2 scores 6).
-
-
-
- Double/Triple Word Score multiplies the entire word’s total score after letter calculations.
-
-
- Premiums are used only once; subsequent plays treat these squares as normal (no multiplier).
- Multiple Words: If a play forms additional words by intersecting with existing tiles, the scores of all new words are added to the turn’s total.
- Seven-Tile Bonus: If a player uses all 7 tiles from their tray in one turn, they receive an additional 50 points.
- Computer Opponent:
- The computer uses a solver algorithm to determine its move, maximizing its score based on the current board, its tray, and the dictionary.
- For the first move (if the human skips), the computer must also cover the center square (7,7).
- The game ends when:
-
- The Tile Bag is empty, and one player uses all their tiles; or
-
- Both players skip their turns consecutively (indicating no further moves are possible).
- Final Scoring:
-
- Each player’s remaining tiles are totaled (using their point values), and this sum is subtracted from their score.
-
- The opponent of the player who used all their tiles (if applicable) adds the value of those remaining tiles to their score.
-
- The player with the highest final score wins. If scores are tied, the game is a draw.
- Resignation: The human player can resign at any time, ending the game immediately with the computer declared the winner.
- Dictionary Flexibility: The program must handle any dictionary file provided, ensuring all word validations use the file’s contents without assuming a specific word list.
- Slow Processing in Computer Turn with Blank Tiles: The computer’s turn experiences significant delays when processing moves that involve a blank tile ('*') in the tray. This is likely due to the solver exploring all 26 possible letter substitutions for each blank tile, which increases computational complexity exponentially.
- Score Not Updating in Alert Box: Occasionally, the actual score of the player (human or computer) is not correctly reflected in the alert box displayed after a move. This bug may stem from a mismatch between the internal score tracking and the UI update logic, causing the displayed score to lag behind the true value.
- Adding Sound to the Game: Introduce audio effects to enhance the player experience, such as sounds for tile placement, valid word submission, invalid move attempts, and game end conditions.
The Scrabble game implementation includes three separate JAR files, each serving a distinct purpose. Below are the instructions for running each:
- scorechecker.jar: A console-based utility for checking scores, intended for graders.
- Command:
java -jar scorechecker.jar <dictionaryfilename> - Replace with the path to the dictionary text file containing valid words.
- solver.jar: A console-based tool for graders to verify the solver’s ability to generate valid words on the board.
- Command:
java -jar solver.jar <dictionaryfilename> - Replace with the path to the dictionary text file.
- maingame.jar: The main GUI version of the Scrabble game.
- Command:
java -jar scrabble.jar - If the JAR does not run via the command line (e.g., due to JavaFX dependencies or misconfiguration), run it via the main method in the ScrabbleGUI class:
-
- Open the project in an IDE, locate the ScrabbleGUI class, and execute its main method directly.