01 Jul C++ programming. Bid only if you know you can make a perfect score
Question Description
In C++
Concepts: multi-dimension array and the Knight’s Tour Problem
A chess board consists of an 8 x 8 “array” of squares:
int board[ROW][COL]={0};
A knight may move perpendicular to the edges of the board, two squares in any of the 4 directions, then one square at right angles to the two-square move. The following lists all 8 possible moves a knight could make from board [3][3]:
board[5][4] or
board[5][2] or
board[4][5] or
board[4][1] or
board[1][4] or
board[1][2] or
board[2][5] or
board[2][1] or
8 1 7 2 K 6 3 5 4
Write a function named LegalMove, in class knight, which accepts a ROW and COL parameter for the
knight’s current position, and a move number parameter (see table above) for the proposed new position.
The method should return true if the proposed move is legal, and false if not legal. The method should also pass reference parameters set by the method to the ROW and COL coordinates of the destination square if the move is legal.
You will need at least the following variables:
const int ROW = 8, COL = 8, MOVES = 8; int row; int col; int board[ROW][COL]; //chess board int offsets[MOVES][2]; //knight move offsets (delta values for row, col) int countLegalMoves; //number of legal moves from row, col int moves[MOVES]; //legal move indices Tour(int row=0, int col=0); void ClearBoard(); int GetLegalMoves(); void Move(int move, int sequence); //for brute force void ShowBoard();
A function should initialize row and col to passed values, and should initialize the offsets array to the array differences (+/- 1 or 2) for row and col for each of the 8 moves.
GetLegalMoves() should fill the moves array with the move number (1-8) and each legal move that is possible from row, col, and return the number of moves in the array (0-8) and store this value in countLegalMoves.
Write some driver code in main that will place a knight at a given position, and test some possible moves (including some off-the-board moves).
If you have time, code the ClearBoard and the ShowBoard methods as well. It might be even more interesting to start on a full brute-force type Knight’s Tour program. I say start on, because there is not enough time in a class period for even a fast programmer to complete such a program.
Our website has a team of professional writers who can help you write any of your homework. They will write your papers from scratch. We also have a team of editors just to make sure all papers are of HIGH QUALITY & PLAGIARISM FREE. To make an Order you only need to click Ask A Question and we will direct you to our Order Page at WriteDemy. Then fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.
Fill in all the assignment paper details that are required in the order form with the standard information being the page count, deadline, academic level and type of paper. It is advisable to have this information at hand so that you can quickly fill in the necessary information needed in the form for the essay writer to be immediately assigned to your writing project. Make payment for the custom essay order to enable us to assign a suitable writer to your order. Payments are made through Paypal on a secured billing page. Finally, sit back and relax.
About Writedemy
We are a professional paper writing website. If you have searched a question and bumped into our website just know you are in the right place to get help in your coursework. We offer HIGH QUALITY & PLAGIARISM FREE Papers.
How It Works
To make an Order you only need to click on “Order Now” and we will direct you to our Order Page. Fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.
Are there Discounts?
All new clients are eligible for 20% off in their first Order. Our payment method is safe and secure.