Question
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
The required output:
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 9Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started