diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2020-11-29 01:44:00 +0100 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2020-11-29 01:44:00 +0100 |
| commit | 5216d920fb26638ceda9f6391c5449c5e7bc8409 (patch) | |
| tree | 8c117086cbb7968f010cae3aca0d16a51e8a2470 /labb5/src/boggleplay.cpp | |
| parent | fb80ac50825c7ca1fa063d3493175b7b27adbdb1 (diff) | |
| download | tddd86-5216d920fb26638ceda9f6391c5449c5e7bc8409.tar.gz | |
initial work labb5
Apparently I need to implement a second search function here.
I don't agree with the reasoning in the lab description.
> NOTERA: Programmet innehåller två rekursiva sökningar: en för att
> hitta ett specifikt ord inmatat av den mänskliga spelaren och en
> annan för att söka ̈över hela brädet under datorspelarens tur. Du
> tänker kanske att dessa borde gå att kombinera till en integrerad
> funktion, genom att göra all ordsökning i början av spelet, precis
> efter att brädet initierats. För att bli godkänd på labben måste
> du dock implementera människan och datorn som två separata
> sökfunktioner. Det finns tillräckliga skillnader mellan de två för
> att de inte ska gå att kombinera rent och snyggt.
Diffstat (limited to 'labb5/src/boggleplay.cpp')
| -rwxr-xr-x | labb5/src/boggleplay.cpp | 52 |
1 files changed, 49 insertions, 3 deletions
diff --git a/labb5/src/boggleplay.cpp b/labb5/src/boggleplay.cpp index 76bdcde..914443b 100755 --- a/labb5/src/boggleplay.cpp +++ b/labb5/src/boggleplay.cpp @@ -1,6 +1,6 @@ // You will edit and turn in this CPP file. // Also remove these comments here and add your own. -// TODO: remove this comment header and replace with your own +// TODO remove this comment header and replace with your own #include <cstdlib> #include <iostream> @@ -9,13 +9,59 @@ #include "Boggle.h" #include "bogglemain.h" #include "strlib.h" -// TODO: include any other header files you need + +#include <string> /* * Plays one game of Boggle using the given boggle game state object. */ void playOneGame(Boggle& boggle) { - // TODO: implement this function (and add any other functions you like to help you) + boggle.clear(); + bool input_custom_board = yesOrNo("Input custom board? "); + if (input_custom_board) { + string input_board; + while (true) { + cout << "Input your board (16 characters): "; + getline(cin, input_board); + if (input_board.length() == 16) { + if (boggle.letters_from_string(input_board)) { + break; + } else { + cout << "Please input a valid string" << endl; + } + } else { + cout << "Please input 16 characters only" << endl; + } + } + } else { + boggle.shuffle(); + } + boggle.find_all_words(); + cout << boggle.debug_words() << endl; + + std::cout << "It's your turn!" << std::endl; + cout << boggle.board_to_string() << endl; + string user_input; + while (true) { + cout << "Your words (" << boggle.get_user_words_size() << "):" << endl; + cout << boggle.user_words_to_string() << endl; + cout << "Your score: " << boggle.get_user_score() << endl; + cout << "Type a word (or press Enter to end your turn) "; + getline(cin, user_input); + if (user_input == "") { + break; + } + if (!boggle.word_is_valid(user_input)) { + cout << "Your word is invalid" << endl; + } else if (!boggle.word_is_unplayed(user_input)) { + cout << "Your word has already been played!" << endl; + } else if (user_input.length() < 4) { + cout << "Your word is too short!" << endl; + } else { + cout << "You found a new word!" << endl; + boggle.add_user_word(user_input); + } + } } |
