Question
Hey I need help with my code, the code I need help with making is the display solutions, but before doing that you will have
Hey I need help with my code, the code I need help with making is the display solutions, but before doing that you will have to make the jumble board(making jumble board function before the display function makes it easier to make the display function so pls try and make the jumble board function) the instructions to make the code are in the picture below, and use try_move function to make the jumble board function,
here are instructions for display_solutions:class Scrambler needs a member function display_solution, which accepts no arguments and re- turns a string showing the solution to the game. This is the solution from the start, not from the current state of the board, by basically reversing theJumble-Board algorithm. Here is my code which is correct and works:#include
using namespace std;
class Scrambler{ public: Scrambler(const string& path, const int size); string str() const; void scramblerinit(); void try_move(const string& cmd); bool is_over() const; string display_solution() const; vector
private: vector
Scrambler :: Scrambler(const string& path, const int size){ this->size = size; this->path = path; ifstream file; file.open(path); for(string lines; getline(file,lines);){ words.push_back(lines); } for(int j = 0; j < size; j++){ vector
void Scrambler:: scramblerinit(){ for(int j = 0; j < size; j++){ int spaceRemain = board.at(j).size(); int space; int i = 0; while(spaceRemain > 2){ int randNum = rand() % words.size(); string wordRand = words[randNum]; space = spaceRemain - wordRand.size(); if(wordRand.size() <= spaceRemain && space != 3){ for(char character: wordRand){ board.at(j).at(i) = character; i++; spaceRemain--; } i++; spaceRemain--; } } } }
string Scrambler:: str()const{ string rboard; string seperate; int count; count = 1;
for(int j = 0; j <= size; j++){ if(j == 1){ rboard = " "; } rboard += " " + to_string(j); } rboard += " "; for(int i = 0; i<4 * size; i++){ seperate += "-"; } for(vector
void Scrambler::try_move(const string& cmd) { if(cmd[0]=='r'){ int r = cmd[1]-'0'-1; int dir = cmd[2]=='l'?1:-1; if(dir==1){ int temp = board[r][0]; for(int c=0; c
} vector
bool Scrambler::is_over() const { return false; }
string Scrambler::display_solution() const { return "1+1"; }
int main() { Scrambler scrambler("dictionary(1).txt", 7); cout << "Initial board: " << scrambler.str() << endl;
scrambler.try_move("c2d"); cout << "Board after c2d move: " << scrambler.str() << endl;
return 0; }