A Python Boggle game solver that finds valid words on a 4x4 grid using a custom word database.
Boggle is a word game where players search for words on a 4x4 grid of letters. This project implements a Boggle Game solver that takes a Boggle board as input and finds all valid words that can be formed on that board based on a provided word database.
The project is organized into three main components:
main.py
: The main program responsible for user interaction and running the Boggle game.WordTree.py
: The WordTree class, which is used to store a dictionary of valid words and find words on the Boggle board.BoggleGame.py
: The BoggleGame class, which handles the game logic, including loading the word database and solving the Boggle board.
The main.py
file serves as the entry point of the program. It allows users to input a Boggle board, loads a word database, and then finds and displays valid words on the board.
The WordTree
class in WordTree.py
is responsible for storing a dictionary of valid words and finding words on the Boggle board. It uses a tree-like data structure to efficiently search for words.
The BoggleGame
class in BoggleGame.py
manages the core logic of the Boggle game. It loads the word database, solves the Boggle board, and prints the board and valid words.
The Boggle board is a 4x4 grid of letters. Users input this grid as a list of lists, where each inner list represents a row of letters. The game board is displayed to the user.
The program validates words against a word database. If a sequence of letters on the Boggle board forms a valid word in the dictionary, it is considered a valid word.
- The Boggle board is represented as a 4x4 grid of letters.
- The program uses a recursive depth-first search (DFS) algorithm to explore all possible paths on the board.
- During the DFS traversal, it checks if the current path forms a valid word by consulting the WordTree, which stores the valid words.
- Valid words are added to the list of validated words.
- The program returns a sorted list of validated words to be displayed to the user.
Before running the Boggle game, ensure you have the required dependencies installed. You can use pip
or conda
for installation.
pip install prettytable
conda install prettytable
To run the Boggle game, execute the main.py
script:
python3 main.py
- When prompted, enter the Boggle board as a 4x4 grid of letters. Each row should be entered on a separate line.
- Ensure that each row contains exactly four letters.
- The board will be displayed to you.
After entering the Boggle board, the program will display the valid words found on the board.
To add a word
to the word database (word_database.txt
), follow these steps:
- Open the
word_database.txt
file in a text editor. - Add the new word to the file, ensuring it is in uppercase and follows the format of one word per line.
- Save the file.