Giter Site home page Giter Site logo

boggle-puzzle-solver's Introduction

Boggle-Puzzle-Solver

Java Project to solve Boggle puzzles.

The objective of this problem is to accept a set of words along with a puzzle grid and display the words that appear in the puzzle, along with the path traversed to encounter the word, to an user [1]. The general solution is as follows: Start at one point in the puzzle grid and traverse through the grid in any one of 8 directions. Whenever a word in the set of words is encountered through a (non-repetitive) path, the word is considered as “Present”. The program functions as follows. Users can input a set of words and a puzzle grid. The set contains words that might appear in the grid. The program traverses through the puzzle and generates a sorted list of words which can be located in the grid along with the path traversed to obtain the word.

Classes:

Boggle.java This class represents instances of a Boggle Puzzle: Each object of type Boggle is associated with the following attributes: Methods: • boolean getDictionary(BufferedReader stream): ✓ Return Type: boolean • boolean getPuzzle(BufferedReader stream) ✓ Return Type: boolean • List solve() ✓ Return Type: List of Strings • String print( ) ✓ Return Type: String

The initial approach that I implemented was a Brute-Force approach where the code starts from each cell in the puzzle grid and recursively travels in all 8 directions (if possible). Stopping Conditions (Grid’s Boundary):

  1. When the next cell’s X-coordinate is lesser than zero.
  2. When the next cell’s Y-coordinate is lesser than zero.
  3. When the next cell is outside the last row (index is greater than the number of columns).
  4. When the next cell is outside the last column (index is greater than the number of rows). Subsequently, in order to improve the efficiency of the code the following objective was achieved: “Traverse only cells that are relevant to words in the dictionary” In order to achieve this objective, the following conditions were included in the code:
  5. Instead of traversing all the cells in the puzzle grid, for each word in the dictionary, start traversal from a cell only if the character in the cell matches the starting letter of the word.
  6. During traversal of each cell, and comparison of the new word with the expected word, move on to the next traversal only when the recently appended word matches the substring of the expected word. Ex: Word to be found is book. Current traversal has formed a word – “bo”. Since “bo” is a valid substring of “book” we can continue traversal. If the current traversal had formed a word “bi” no further traversals can be made since the current word is not a valid substring of the expected word – “book”.
  7. During traversal of each cell the length of the current word and expected words are compared. If the length of the current word is GREATER than that of the expected word, no further traversals will be made. (It would not yield any result).

boggle-puzzle-solver's People

Contributors

danny-at-dalhousie avatar bennydanielt avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.