Question: IN C++ USING SEARCHING AND SORTING ALGORITHMS Do you remember the 15 puzzle? Now, it is time to implement this game. Think about what we

IN C++ USING SEARCHING AND SORTING ALGORITHMS

Do you remember the 15 puzzle? Now, it is time to implement this game.

Think about what we need to implement and play this game! We need a board with the numbers 1- 15 randomly distributed across it. To do that, create your board with these integers then use a function to shuffle them across the game board. In this way, you guarantee that your integers are randomly unique.

As the player chooses one of these numbers to move, your code should search the game board for that number and move it, if that number is adjacent to the blank tile, to the top-, bottom-, left- or right- side. Since the blank tile is used with every move, it is recommended that you keep track of its position rather than searching for it every time. Whenever a player makes a move he/she should be able to see the updated board. Otherwise, they should be informed that their attempt to move the number is not allowed. When the number on the board are all sorted from left to right and top to bottom, the player wins the game and optionally, he/she can play another game. Make sure that whenever a player starts a game, a new game board is generated with a different random distribution of the tiles. Do not allow the player to input values other than the numbers 1 to 15.

Here is what I have so far please add to it.

#include #include #include using namespace std;

const int SIZE = 4; const int BLANK_TILE = '*'; const int BOARD_SIZE = 16;

void displayBoard(int board[][SIZE]); void shuffle(int originalBoard[][SIZE], int &blanki, int &blankj); bool moveTile(int gameBoard[][SIZE], int nextMove, int &blanki, int &blankj); bool won(int gameBoard[][SIZE]);

int main() { // TODO: create the game board // TODO: shuffle tiles on board // TODO: prompt the user to input a tile to be moved // TODO: play the game until the user wins! return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!