Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Language: C++ I need to write a recursive backtracking function for the Scrabble game, finds all legal words that can be made out of some

Language: C++

I need to write a recursive backtracking function for the Scrabble game, finds all legal words that can be made out of some subset of the letters in the players hand, with the board letter either at the beginning or end of the word (depending on what the user entered). Each tile will be used at most once, but its possible for two different tiles to have the same letter.

I already wrote the function, but it doesn't works well. Hope you can help me to fix it.

void find_word_firstpos(vector wordlist,string current_word, string current_letter_in_hand) { //base: we stop the function when we only have one letter in hand if (current_letter_in_hand.length() == 1) { string tmp = current_word + current_letter_in_hand[0]; if (check_legal_word(wordlist,tmp) == true) { cout

} else { find_word_firstpos(wordlist, tmp, current_letter_in_hand.substr(i, 1)); }

} }

}

My output

image text in transcribed

The required output: image text in transcribed

C:\Users\maing\Desktop\HW HW3\Debug\HW3.exe What are your current letters? ABCDEF What letter is on the board? H Is this letter of begining of the word? (y) y HA 5 HE 5 Go again? (y) Sample Run( Entries in bold are user input) Enter the name of the wordlist file: TWL06.txt What are your current letters? ABCDEFG What letter is on the board? H Is this letter the beginning of the word? y HA 5 HAD 7 HADE 8 HAE 6 HAED 8 HAG 7 HE 5 HEAD 8 Go again? (y) y what are your current letters? ABCDEFG what letter is on the board? H Is this letter the beginning of the word? n AH 5 BAH 8 BACH 11 BEACH 12 DAH 7 EH 5 EACH 9 EDH 7 FEH 9 C:\Users\maing\Desktop\HW HW3\Debug\HW3.exe What are your current letters? ABCDEF What letter is on the board? H Is this letter of begining of the word? (y) y HA 5 HE 5 Go again? (y) Sample Run( Entries in bold are user input) Enter the name of the wordlist file: TWL06.txt What are your current letters? ABCDEFG What letter is on the board? H Is this letter the beginning of the word? y HA 5 HAD 7 HADE 8 HAE 6 HAED 8 HAG 7 HE 5 HEAD 8 Go again? (y) y what are your current letters? ABCDEFG what letter is on the board? H Is this letter the beginning of the word? n AH 5 BAH 8 BACH 11 BEACH 12 DAH 7 EH 5 EACH 9 EDH 7 FEH 9

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design For Mere Mortals

Authors: Michael J Hernandez

4th Edition

978-0136788041

More Books

Students also viewed these Databases questions

Question

What is meant by the term telecommunications?

Answered: 1 week ago

Question

What is Change Control and how does it operate?

Answered: 1 week ago

Question

How do Data Requirements relate to Functional Requirements?

Answered: 1 week ago