Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need this to be done in Visual Studio and also need entire working code for th

ID: 3747934 • Letter: I

Question

I need this to be done in Visual Studio and also need entire working code for this

A02 - Imperative Sliding Tile Puzzle.docx
1 / 5 CIS 221 – Programming II: C++ - Programming Assignment Imperative Sliding Tile Puzzle
Overview In this assignment, the student will write a C++ program that simulates a traditional sliding tile puzzle. The student will write this simulation strictly using the imperative programming paradigm (function-based programming)
When completing this assignment, the student should demonstrate mastery of the following concepts:
* Imperative Programming Paradigm Usage * Simulation Design * Pseudo-Random Program Behavior * Windows API Calls * Advanced UI Design – Console Color Modification * Advanced UI Design – Simple Refreshing Display/Keystroke Processing
Assignment In this assignment, you will be strictly adhering to the imperative programming paradigm. This means that objects/classes are not to be created as core operational elements in this solution. Instead, functions performing different tasks along with piece of driver code in main would be appropriate.   
You will be creating a simulation for a traditional “sliding tile puzzle”. If you are unfamiliar with sliding tile puzzles, see the following:
* https://en.wikipedia.org/wiki/Sliding_puzzle
When writing a program using the imperative programming paradigm, you should be break the problem down into a series of functions that represent the logical interactions with the puzzle. You should be sending information to and from your functions with arguments and return values in a meaningful, thoughtful way. To know if you are operating within the spirit of the imperative paradigm, you should find yourself breaking the problem down into a series of repeatable, independent tasks that represent the individual functions of your solution. You should then have core “driver” logic in the main() function that orchestrates a series of calls to these functions to execute the simulation as you see fit. If you need more information on the imperative programming paradigm, see the following:
* https://en.wikipedia.org/wiki/Imperative_programming
When completing this project, there are several items to take into consideration upfront…
You must carefully consider the manner in which you scramble the board initially. In some naïve approaches, the tiles are simply lifted and placed 2 / 5 into random locations on the board. This may sound good in a pinch, but further mathematical investigation will quickly reveal that this approach will produce a board that cannot be solved 50% of the time. This happens because a solved state as illustrated in the first screen shot below cannot be transformed into a board state in which the 7 and 8 tiles are hypothetically transposed. In essence, there are two distinct sets of board states and a board that is currently set in one state will never move to one of the states in the other family through a series of legal moves (slides). As a result, you must create routine that scrambles the board by making a series of repetitious “legal” moves to the puzzle in a “random” fashion.
You must strategically use color to get full credit for this assignment. You can easily change the fore-color and back-color for the Windows console through the Windows API. It would probably be best to get the puzzle working first and then tackle the color second. However, make sure the colors update as the individual moves are made. You might want to set up a small demo for yourself to explore the manner in which colors are changed through the Windows API to get a handle on this before integrating it into your project’s code.
Example Execution Screen Shot #1
When the game begins, the board should appear in the solved state.
Example Execution Screen Shot #2 3 / 5

Have the user press any key to begin scrambling the tiles. Remember, you must make actual moves on the board. A pure random arrangement of the tiles will result in half of the board states being solvable and the other have of the states being unsolvable.
Example Execution Screen Shot #3

Provide the user with an intuitive interface for moving the tiles. When a move is made, trigger the appropriate functions, clear the screen, and re-draw the board to reflect the new state. Do not show the old board states (force the screen to re-draw in an aesthetically pleasing manner). Make sure your prompts are intuitive with clear instructions that would help any reasonably intelligent user interact with your program.
Example Execution Screen Shot #4 4 / 5

Remember, the asterisk (*) represents the pivot point. Things should be considered from the perspective of a user interacting with a sliding tile puzzle since this is a simulation. The directions represent the direction in which a tile is pushed to occupy the blank space, not the direction in which the blank space moves.
Example Execution Screen Shot #5

Tiles placed in incorrect position should be colored in RED.
Example Execution Screen Shot #6 5 / 5

Tile that get moved into their correct resting position should draw in GREEN.
Example Execution Screen Shot #7

The puzzle is solved when every tile has been moved into the correct position I need this to be done in Visual Studio and also need entire working code for this

A02 - Imperative Sliding Tile Puzzle.docx
1 / 5 CIS 221 – Programming II: C++ - Programming Assignment Imperative Sliding Tile Puzzle
Overview In this assignment, the student will write a C++ program that simulates a traditional sliding tile puzzle. The student will write this simulation strictly using the imperative programming paradigm (function-based programming)
When completing this assignment, the student should demonstrate mastery of the following concepts:
* Imperative Programming Paradigm Usage * Simulation Design * Pseudo-Random Program Behavior * Windows API Calls * Advanced UI Design – Console Color Modification * Advanced UI Design – Simple Refreshing Display/Keystroke Processing
Assignment In this assignment, you will be strictly adhering to the imperative programming paradigm. This means that objects/classes are not to be created as core operational elements in this solution. Instead, functions performing different tasks along with piece of driver code in main would be appropriate.   
You will be creating a simulation for a traditional “sliding tile puzzle”. If you are unfamiliar with sliding tile puzzles, see the following:
* https://en.wikipedia.org/wiki/Sliding_puzzle
When writing a program using the imperative programming paradigm, you should be break the problem down into a series of functions that represent the logical interactions with the puzzle. You should be sending information to and from your functions with arguments and return values in a meaningful, thoughtful way. To know if you are operating within the spirit of the imperative paradigm, you should find yourself breaking the problem down into a series of repeatable, independent tasks that represent the individual functions of your solution. You should then have core “driver” logic in the main() function that orchestrates a series of calls to these functions to execute the simulation as you see fit. If you need more information on the imperative programming paradigm, see the following:
* https://en.wikipedia.org/wiki/Imperative_programming
When completing this project, there are several items to take into consideration upfront…
You must carefully consider the manner in which you scramble the board initially. In some naïve approaches, the tiles are simply lifted and placed 2 / 5 into random locations on the board. This may sound good in a pinch, but further mathematical investigation will quickly reveal that this approach will produce a board that cannot be solved 50% of the time. This happens because a solved state as illustrated in the first screen shot below cannot be transformed into a board state in which the 7 and 8 tiles are hypothetically transposed. In essence, there are two distinct sets of board states and a board that is currently set in one state will never move to one of the states in the other family through a series of legal moves (slides). As a result, you must create routine that scrambles the board by making a series of repetitious “legal” moves to the puzzle in a “random” fashion.
You must strategically use color to get full credit for this assignment. You can easily change the fore-color and back-color for the Windows console through the Windows API. It would probably be best to get the puzzle working first and then tackle the color second. However, make sure the colors update as the individual moves are made. You might want to set up a small demo for yourself to explore the manner in which colors are changed through the Windows API to get a handle on this before integrating it into your project’s code.
Example Execution Screen Shot #1
When the game begins, the board should appear in the solved state.
Example Execution Screen Shot #2 3 / 5

Have the user press any key to begin scrambling the tiles. Remember, you must make actual moves on the board. A pure random arrangement of the tiles will result in half of the board states being solvable and the other have of the states being unsolvable.
Example Execution Screen Shot #3

Provide the user with an intuitive interface for moving the tiles. When a move is made, trigger the appropriate functions, clear the screen, and re-draw the board to reflect the new state. Do not show the old board states (force the screen to re-draw in an aesthetically pleasing manner). Make sure your prompts are intuitive with clear instructions that would help any reasonably intelligent user interact with your program.
Example Execution Screen Shot #4 4 / 5

Remember, the asterisk (*) represents the pivot point. Things should be considered from the perspective of a user interacting with a sliding tile puzzle since this is a simulation. The directions represent the direction in which a tile is pushed to occupy the blank space, not the direction in which the blank space moves.
Example Execution Screen Shot #5

Tiles placed in incorrect position should be colored in RED.
Example Execution Screen Shot #6 5 / 5

Tile that get moved into their correct resting position should draw in GREEN.
Example Execution Screen Shot #7

The puzzle is solved when every tile has been moved into the correct position

A02 - Imperative Sliding Tile Puzzle.docx
1 / 5 CIS 221 – Programming II: C++ - Programming Assignment Imperative Sliding Tile Puzzle
Overview In this assignment, the student will write a C++ program that simulates a traditional sliding tile puzzle. The student will write this simulation strictly using the imperative programming paradigm (function-based programming)
When completing this assignment, the student should demonstrate mastery of the following concepts:
* Imperative Programming Paradigm Usage * Simulation Design * Pseudo-Random Program Behavior * Windows API Calls * Advanced UI Design – Console Color Modification * Advanced UI Design – Simple Refreshing Display/Keystroke Processing
Assignment In this assignment, you will be strictly adhering to the imperative programming paradigm. This means that objects/classes are not to be created as core operational elements in this solution. Instead, functions performing different tasks along with piece of driver code in main would be appropriate.   
You will be creating a simulation for a traditional “sliding tile puzzle”. If you are unfamiliar with sliding tile puzzles, see the following:
* https://en.wikipedia.org/wiki/Sliding_puzzle
When writing a program using the imperative programming paradigm, you should be break the problem down into a series of functions that represent the logical interactions with the puzzle. You should be sending information to and from your functions with arguments and return values in a meaningful, thoughtful way. To know if you are operating within the spirit of the imperative paradigm, you should find yourself breaking the problem down into a series of repeatable, independent tasks that represent the individual functions of your solution. You should then have core “driver” logic in the main() function that orchestrates a series of calls to these functions to execute the simulation as you see fit. If you need more information on the imperative programming paradigm, see the following:
* https://en.wikipedia.org/wiki/Imperative_programming
When completing this project, there are several items to take into consideration upfront…
You must carefully consider the manner in which you scramble the board initially. In some naïve approaches, the tiles are simply lifted and placed 2 / 5 into random locations on the board. This may sound good in a pinch, but further mathematical investigation will quickly reveal that this approach will produce a board that cannot be solved 50% of the time. This happens because a solved state as illustrated in the first screen shot below cannot be transformed into a board state in which the 7 and 8 tiles are hypothetically transposed. In essence, there are two distinct sets of board states and a board that is currently set in one state will never move to one of the states in the other family through a series of legal moves (slides). As a result, you must create routine that scrambles the board by making a series of repetitious “legal” moves to the puzzle in a “random” fashion.
You must strategically use color to get full credit for this assignment. You can easily change the fore-color and back-color for the Windows console through the Windows API. It would probably be best to get the puzzle working first and then tackle the color second. However, make sure the colors update as the individual moves are made. You might want to set up a small demo for yourself to explore the manner in which colors are changed through the Windows API to get a handle on this before integrating it into your project’s code.
Example Execution Screen Shot #1
When the game begins, the board should appear in the solved state.
Example Execution Screen Shot #2 3 / 5

Have the user press any key to begin scrambling the tiles. Remember, you must make actual moves on the board. A pure random arrangement of the tiles will result in half of the board states being solvable and the other have of the states being unsolvable.
Example Execution Screen Shot #3

Provide the user with an intuitive interface for moving the tiles. When a move is made, trigger the appropriate functions, clear the screen, and re-draw the board to reflect the new state. Do not show the old board states (force the screen to re-draw in an aesthetically pleasing manner). Make sure your prompts are intuitive with clear instructions that would help any reasonably intelligent user interact with your program.
Example Execution Screen Shot #4 4 / 5

Remember, the asterisk (*) represents the pivot point. Things should be considered from the perspective of a user interacting with a sliding tile puzzle since this is a simulation. The directions represent the direction in which a tile is pushed to occupy the blank space, not the direction in which the blank space moves.
Example Execution Screen Shot #5

Tiles placed in incorrect position should be colored in RED.
Example Execution Screen Shot #6 5 / 5

Tile that get moved into their correct resting position should draw in GREEN.
Example Execution Screen Shot #7

The puzzle is solved when every tile has been moved into the correct position A02 - Imperative Sliding Tile Puzzle.docx
1 / 5 CIS 221 – Programming II: C++ - Programming Assignment Imperative Sliding Tile Puzzle
Overview In this assignment, the student will write a C++ program that simulates a traditional sliding tile puzzle. The student will write this simulation strictly using the imperative programming paradigm (function-based programming)
When completing this assignment, the student should demonstrate mastery of the following concepts:
* Imperative Programming Paradigm Usage * Simulation Design * Pseudo-Random Program Behavior * Windows API Calls * Advanced UI Design – Console Color Modification * Advanced UI Design – Simple Refreshing Display/Keystroke Processing
Assignment In this assignment, you will be strictly adhering to the imperative programming paradigm. This means that objects/classes are not to be created as core operational elements in this solution. Instead, functions performing different tasks along with piece of driver code in main would be appropriate.   
You will be creating a simulation for a traditional “sliding tile puzzle”. If you are unfamiliar with sliding tile puzzles, see the following:
* https://en.wikipedia.org/wiki/Sliding_puzzle
When writing a program using the imperative programming paradigm, you should be break the problem down into a series of functions that represent the logical interactions with the puzzle. You should be sending information to and from your functions with arguments and return values in a meaningful, thoughtful way. To know if you are operating within the spirit of the imperative paradigm, you should find yourself breaking the problem down into a series of repeatable, independent tasks that represent the individual functions of your solution. You should then have core “driver” logic in the main() function that orchestrates a series of calls to these functions to execute the simulation as you see fit. If you need more information on the imperative programming paradigm, see the following:
* https://en.wikipedia.org/wiki/Imperative_programming
When completing this project, there are several items to take into consideration upfront…
You must carefully consider the manner in which you scramble the board initially. In some naïve approaches, the tiles are simply lifted and placed 2 / 5 into random locations on the board. This may sound good in a pinch, but further mathematical investigation will quickly reveal that this approach will produce a board that cannot be solved 50% of the time. This happens because a solved state as illustrated in the first screen shot below cannot be transformed into a board state in which the 7 and 8 tiles are hypothetically transposed. In essence, there are two distinct sets of board states and a board that is currently set in one state will never move to one of the states in the other family through a series of legal moves (slides). As a result, you must create routine that scrambles the board by making a series of repetitious “legal” moves to the puzzle in a “random” fashion.
You must strategically use color to get full credit for this assignment. You can easily change the fore-color and back-color for the Windows console through the Windows API. It would probably be best to get the puzzle working first and then tackle the color second. However, make sure the colors update as the individual moves are made. You might want to set up a small demo for yourself to explore the manner in which colors are changed through the Windows API to get a handle on this before integrating it into your project’s code.
Example Execution Screen Shot #1
When the game begins, the board should appear in the solved state.
Example Execution Screen Shot #2 3 / 5

Have the user press any key to begin scrambling the tiles. Remember, you must make actual moves on the board. A pure random arrangement of the tiles will result in half of the board states being solvable and the other have of the states being unsolvable.
Example Execution Screen Shot #3

Provide the user with an intuitive interface for moving the tiles. When a move is made, trigger the appropriate functions, clear the screen, and re-draw the board to reflect the new state. Do not show the old board states (force the screen to re-draw in an aesthetically pleasing manner). Make sure your prompts are intuitive with clear instructions that would help any reasonably intelligent user interact with your program.
Example Execution Screen Shot #4 4 / 5

Remember, the asterisk (*) represents the pivot point. Things should be considered from the perspective of a user interacting with a sliding tile puzzle since this is a simulation. The directions represent the direction in which a tile is pushed to occupy the blank space, not the direction in which the blank space moves.
Example Execution Screen Shot #5

Tiles placed in incorrect position should be colored in RED.
Example Execution Screen Shot #6 5 / 5

Tile that get moved into their correct resting position should draw in GREEN.
Example Execution Screen Shot #7

The puzzle is solved when every tile has been moved into the correct position

Explanation / Answer

#include <iostream>

#include <string>

#include <conio.h>

#include <ctime>

#include <Windows.h>

using namespace std;

// To use the arrow keys instead of letters

#define UP 72

#define LEFT 75

#define RIGHT 77

#define DOWN 80

int solvedBoard[10][10];

void printBoard(int board[][10], int);

void initializeBoard(int board[][10], int);

void slideTile(int board[][10],int move,int);

bool isBoardSolved(int board[][10],int);

void scrambleBoard(int board[][10],int);

void WaitKey();

int main()

{

int amount=0;

do

{

system("CLS"); // Best NOT to use system calls, but I'll use for now. Find a better solution

// Just to drop request a bit down and over, for looks.

cout << endl << endl << endl << " How large of a sliding puzzle, do you want? (3 to 10)";

cout << endl << endl << " ";

cin >> amount;

if(amount <3 || amount > 10)

cout << " Sorry, I don't have that size, handy. Try again please!" << endl << endl;

Sleep(1300);

}while (amount <3 || amount > 10);

int gameBoard[10][10];

char input;

string direction;

bool invalid = false;

amount--; // Subtract 1, so checking of array would be from 0 to amount. No need to add -1 to checks

// to keep it in bounds of board

initializeBoard(gameBoard,amount);

printBoard(gameBoard,amount);

cout << boolalpha;

cout<<"isBoardSolved(): "<<isBoardSolved(gameBoard,amount)<<endl;

cout<<"Press enter to begin"<<endl;

WaitKey();

cout<<"Scrambling board..."<<endl;

scrambleBoard(gameBoard, amount);

cout<<"Scrambling complete, press enter to continue"<<endl;

cin.get();

system("CLS");

printBoard(gameBoard,amount);

cout<<endl<<endl;

cout<<"Use arrow keys to move the tiles in the desired direction!"<<endl;

cout<<"Input: ";

while(!isBoardSolved(gameBoard, amount))

{

input = _getch();

system("CLS");

switch(input)

{

case UP:

slideTile(gameBoard,2,amount);

direction = "Up";

break;

case LEFT:

slideTile(gameBoard,0,amount); // move

direction = "Left";

break;

case DOWN:

slideTile(gameBoard,3,amount);

direction = "Down";

break;

case RIGHT:

slideTile(gameBoard,1,amount);

direction = "Right";

break;

default:

invalid = true;

}

printBoard(gameBoard,amount);

cout<<endl<<endl;

cout<<"Use arrow keys to move the tiles in the desired direction!"<<endl;

if(invalid)

invalid = false;

else

cout<<"Last Input: "<<direction;

}

cout << endl;

cout << "BOARD SOLVED" << endl;

system("PAUSE");

return 0;

}

/* Print board and replace zero with a character 177 */

void printBoard(int board[][10], int amt)

{

HANDLE hConsole;

hConsole = GetStdHandle(STD_OUTPUT_HANDLE);

for(int row = 0; row <= amt; row++)

{

for(int column = 0; column <= amt; column++)

{

if(board[row][column] == 0)

{

SetConsoleTextAttribute(hConsole, 7); //Default color

cout << " ";

}

else

{

if(board[row][column] == solvedBoard[row][column]) //If board location is equal to solvedBoard location then set to green

SetConsoleTextAttribute(hConsole, 10);

else

SetConsoleTextAttribute(hConsole, 12); //else, set to red

if (board[row][column]<10) // Print a 0 first if # < 10

cout<<"0";

cout<<board[row][column] << " ";

}

}

cout<<endl;

}

SetConsoleTextAttribute(hConsole, 7);

}

/*Set up board*/

void initializeBoard(int board[][10], int amt)

{

int i = 1;

for(int row = 0; row <= amt; row++)

{

for(int column = 0; column <= amt; column++)

{

board[row][column] = i;

solvedBoard[row][column] = i;

i++;

}

board[amt][amt] = 0;

solvedBoard[amt][amt] = 0;

}

}

/*Make a move*/

void slideTile(int board[][10],int move, int amt)

{

int emptyRow;

int emptyCol;

bool legalMoves[4] = {1,1,1,1}; //array of legal moves, [0] = left, [1] = right, [2] = up, [3] = down. true (1) indicates a legal move.

for(int row = 0; row <= amt; row++)

{

for(int column = 0; column <= amt; column++)

{

if(board[row][column] == 0) //Find location of empty space

{

emptyRow = row;

emptyCol = column;

}

}

}

if(emptyRow + 1 > amt) //Can i move up?

legalMoves[2] = false; //If no, set move flag to false

else if(emptyRow - 1 < 0) //Move down?

legalMoves[3] = false;

if(emptyCol - 1 < 0) //Move right?

legalMoves[1] = false;

else if(emptyCol + 1 > amt) //Move left?

legalMoves[0] = false;

switch(move) //Replace zero space with space to the left right up or down.

{

case 0:

if(legalMoves[move])

{

board[emptyRow][emptyCol] = board[emptyRow][emptyCol + 1];

board[emptyRow][emptyCol + 1] = 0;

emptyCol = emptyCol+1;

}

break;

case 1:

if(legalMoves[move])

{

board[emptyRow][emptyCol] = board[emptyRow][emptyCol - 1];

board[emptyRow][emptyCol- 1] = 0;

emptyCol = emptyCol-1;

}

break;

case 2:

if(legalMoves[move])

{

board[emptyRow][emptyCol] = board[emptyRow+1][emptyCol];

board[emptyRow+1][emptyCol] = 0;

emptyRow = emptyRow+1;

}

break;

case 3:

if(legalMoves[move])

{

board[emptyRow][emptyCol] = board[emptyRow-1][emptyCol];

board[emptyRow-1][emptyCol] = 0;

emptyRow = emptyRow-1;

}

break;

}

}

bool isBoardSolved(int board[][10], int amt)

{

bool boardSolved = true;

int row = 0;

int col = 0;

while(boardSolved && row<=amt)

{

if(solvedBoard[row][col] == board[row][col]) //Compare each index of solved board with game board

{

col++;

if(col == amt)

{

row++;

col = 0;

}

}

else //Once a discrepancy is found, set boardSolved to false to break the loop

boardSolved = false;

}

return boardSolved;

}

void scrambleBoard(int board[][10], int amt)

{

time_t t;

srand((unsigned) time(&t));

int move;

while(isBoardSolved(board,amt)) //If the board ends up being solved at the end of the scramble, scramble the board again

{

for(int i = 0; i < 100000;i++) //Series of random moves

{

move = rand() % 4;

slideTile(board,move,amt);

}

}

}

void WaitKey()

{

while (_kbhit()) _getch(); // Empty the input buffer

_getch(); // Wait for a key

while (_kbhit()) _getch(); // Empty the input buffer (some keys sends two messages)

}

sliding tile puzzle

void puzzle::swap(int d) //d where 1 = up, 2 = left, 3 = down, 4 = right

{

int temp = 0;

switch (d) //determines direction

{

case 1://swaps empty with upward tile

if (Y == 0) //checks if null is on upper border, if true returns to prevent error

{

return;

}

temp = grid[X][Y - 1]; //swapping positions

grid[X][Y - 1] = grid[X][Y];

grid[X][Y] = temp;

Y -= 1;//null tile's new position

break;

case 2://swaps empty with left tile

if (X == 0)//checks if null is on left border, if true returns to prevent error

{

return;

}

temp = grid[X - 1][Y]; //swapping positions

grid[X - 1][Y] = grid[X][Y];

grid[X][Y] = temp;

X -= 1;

break;

case 3: //swaps empty with downward tile

if (Y == 3) //checks if null is on bottom border, if true returns to prevent error

{

return;

}

temp = grid[X][Y + 1]; //swapping positions

grid[X][Y + 1] = grid[X][Y];

grid[X][Y] = temp;

Y += 1; //null tile's new position

break;

case 4: //swaps null with rightward tile

if (X == 3) //checks if null is on right border, if true returns to prevent error

{

return;

}

temp = grid[X + 1][Y]; //swapping positions

grid[X + 1][Y] = grid[X][Y];

grid[X][Y] = temp;

X += 1; //empty tile's new position

break;

}

return;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote