Assign4: Boggle Score


The Game of Boggle

The word game Boggle™ is a beloved part of the CS106B canon for its fun and engaging use of recursive search. While previous versions of CS106B have asked students to implement many parts of the game, we are scaling things down this quarter to focus on the interesting recursive problem at the core of the game – how do you find all the possible words on the board to achieve the highest possible score?

The Boggle game board is a square grid onto which you randomly distribute a set of letter cubes. You find a word on the board by tracing by a path through adjoining letter cubes, using each cube at most once in word.

The diagram below shows a sample board. Follow the arrows to trace the path for the word peace.

img of boggle board

In this part of the assignment, we will use a Grid<char> to represent the game board. Each location in the grid represents a cube, where the character at that grid location represents the letter on the face of the cube.

A word is valid for a given board if it meets all of the following conditions:

Points are scored for a word according to its length. A word with 3 or fewer characters is invalid by the abover criteria and is thus worth zero points. A 4-letter word earns 1 point, a 5-letter word is 2 points; 6-letter words earn 3 points; and so on.

Your task

You are to write a function that computes the total score for all the words found on a given Boggle board. The function prototype is

int scoreBoard(Grid<char>& board, Lexicon& lex)

The function operates by recursively exploring the board to find all words and tallying up the points. When designing your recurisve approach to this problem, consider the following two important ideas:

Notes

We highly recommend reading through the entirety of these notes before getting started on the problem.

Hooray for you! With your success on this task, you are now well on your way to become a master in the practice of recursion! And you also have a tool that lets you win any Boggle game against your friends and family as well…

Extensions