1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Flura [38]
3 years ago
15

I need help writing a recursion function to solve a boggle game for c++.

Computers and Technology
1 answer:
Mandarinka [93]3 years ago
7 0

Answer:

#include <cstring>

#include <iostream>

using namespace std;

 

#define A 3

#define B 3

 

// LET US CREATE A DICTIONARY

string dict[] = { "KILLS", "GOT", "QUIZ", "GO" };

int n = sizeof(dict) / sizeof(dict[0]);

 

// Let us make a function to find whether a given word is present in dictionary.

bool isPresent(string& str)

{

   // linear search of words

   for (int i = 0; i < n; i++)

       if (str.compare(dict[i]) == 0)

           return true;

   return false;

}

 

// A function for printing all words present on Boggle

void findWordin(char bogle[A][B], bool hasbeenvisited[A][B], int i,

                  int j, string& str)

{

   hasbeenvisited[i][j] = true;

   str = str + bogle[i][j];

 

   // If str is in the dictionary, then you need to print it

   if (isPresent(str))

       cout << str << endl;

 

   // Travering adjacent 8 cells of the boggle

   for (int r = i - 1; r <= i + 1 && r < A; r++)

       for (int c= j - 1; c <= j + 1 && c < B; c++)

           if (r >= 0 && c >= 0 && !hasbeenvisited[r][c])

               findWordin(bogle, hasbeenvisited, r, c, str);

 

   // for erasing current characters on the string, and mark them visited

   // of the current cells to false  

   str.erase(str.length() - 1);

   hasbeenvisited[i][j] = false;

}

 

// Prints all words which are in dictionary.

void findWords(char boggle[A][B])

{

   // for marking all the characters as not being visited

   bool hasbeenvisited[A][B] = { { false } };

 

   // Initializing the present string

   string str = "";

 

   // Reading all the characters for finding all the words that begins with the above character

   for (int i = 0; i < A; i++)

       for (int j = 0; j < B; j++)

           findWordin(boggle, hasbeenvisited, i, j, str);

}

 

// the code for testing of the function

int main()

{

   char bogle[A][B] = { { 'k', 'I', 'L' },

                         { 'L', 'S', 'M' },

                         { 'G', 'O', 'T' } };

 

   cout << "Below list of words are present in the dictionary\n";

   findWords(bogle);

   return 0;

}

Explanation:

The program is properly commented, and that explains each step of it.  However, I have kept dictionary as constant for similifying the code. And it can be set to variable easily, if required.

You might be interested in
What game is the best for racing and modifying cars
sleet_krkn [62]

Answer:  it is Forza Horizon 4. ...

Best Car Games

1.Forza Horizon 4

2. Grand Theft Auto V

3. Need For Speed Payback

4. Car Mechanic Simulator

5. Forza Horizon 4

6. Rocket League

Explanation:

6 0
3 years ago
Global knowledge is the same as common knowledge.
slava [35]

Answer:

OT

Explanation:

8 0
4 years ago
Read 2 more answers
Which vulnerability can occur if a programmer does not properly validate user input and allows an attacker to include unintended
sergiy2304 [10]

Answer:

SQL injection

Explanation:

SQL injection is a vulnerability in databases that occurs when user input is not properly validated. Hackers are able to input SQL query statements to bypass the use of the actual user name and password to gain access to the account.

Using placeholders in programmed SQL statements mitigates the effects of SQL injection.

6 0
3 years ago
A[n] _______________ is a hacker whose intention is the exploitation of a target computer or network to create a serious impact,
Margarita [4]
Cyberterrorist. They use the internet to hack into the government and private computer system which cripples the military.

8 0
3 years ago
Can you help me with game development? In coding, what exists as height and width only.
Masja [62]

Answer:

yes ofc

Explanation:

acctually it depends on what software you use/ apps/installation. because on your software it has your pointer arrows and directions you acctually want to click that it will give you instructions on anything you request!

6 0
3 years ago
Read 2 more answers
Other questions:
  • A virus has attacked your hard drive and now when you start up Windows, instead of seeing a Windows desktop, the system freezes
    9·2 answers
  • True or false: a cover letter accompanies a resume to showcase a job-seeker’s personal life
    6·2 answers
  • The ____________________ packet-filtering firewall allows only a particular packet with a particular source, destination, and po
    10·1 answer
  • 5. Tricks of the language commercials use are called Rhetorical Devices?
    9·1 answer
  • The ____ developed numerical methods for generating square roots, multiplication tables, and trigonometric tables used by early
    12·1 answer
  • Write a program that first reads in the name of an input file, followed by two strings representing the lower and upper bounds o
    8·1 answer
  • What is the point of brainy when other people have to answer your questions but not the cumputer
    9·1 answer
  • What is the alogarithm for solving the perimeter of a triangle
    11·1 answer
  • Logan has developed an excellent presentation with interesting content. He received great feedback on the evaluation
    10·1 answer
  • Your principal has hired you to design a drone that can monitor students in the hallways. Before you brainstorm design ideas, yo
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!