vivekkdagar / Boggle-Word-Solver

A Python Boggle game solver that finds valid words on a 4x4 grid using a custom word database.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

GitHub

Boggle-Word-Solver

A Python Boggle game solver that finds valid words on a 4x4 grid using a custom word database.

made-with-python

Table of Contents

  1. Introduction
  2. Project Structure
  3. Components
  4. How the Game Works
  5. Usage Guide
  6. Conclusion

1. Introduction

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.

Example

2. Project Structure

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.

3. Components

Main Program (main.py)

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.

Word Tree (WordTree.py)

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.

Boggle Game (BoggleGame.py)

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.

4. How the Game Works

Boggle Board

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.

Word Validation

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.

Algorithm Overview

  1. The Boggle board is represented as a 4x4 grid of letters.
  2. The program uses a recursive depth-first search (DFS) algorithm to explore all possible paths on the board.
  3. During the DFS traversal, it checks if the current path forms a valid word by consulting the WordTree, which stores the valid words.
  4. Valid words are added to the list of validated words.
  5. The program returns a sorted list of validated words to be displayed to the user.

5. Usage Guide

Installation

Before running the Boggle game, ensure you have the required dependencies installed. You can use pip or conda for installation.

Using Pip

pip install prettytable

Using Conda

conda install prettytable

Running the Game

To run the Boggle game, execute the main.py script:

python3 main.py

Entering the Boggle Board

  1. When prompted, enter the Boggle board as a 4x4 grid of letters. Each row should be entered on a separate line.
  2. Ensure that each row contains exactly four letters.
  3. The board will be displayed to you.

Viewing Valid Words

After entering the Boggle board, the program will display the valid words found on the board.

Adding a Word to the Database

To add a word

to the word database (word_database.txt), follow these steps:

  1. Open the word_database.txt file in a text editor.
  2. Add the new word to the file, ensuring it is in uppercase and follows the format of one word per line.
  3. Save the file.

About

A Python Boggle game solver that finds valid words on a 4x4 grid using a custom word database.

License:GNU General Public License v3.0


Languages

Language:Python 100.0%