[SOLVED] 代写 graph Section 5.3.2 of the text describes the “Eight Queens Problem”. Read the description of the problem very carefully, but stop reading when the details of the implementation begin to be discussed. I believe that I have a simpler approach. This means you should read through the paragraph that ends with “you need to backtrack, as has already been described.” This is bottom-of-page-177 through the first complete paragraph on page 179.

30 $

File Name: 代写_graph_Section_5.3.2_of_the_text_describes_the_“Eight_Queens_Problem”._Read_the_description_of_the_problem_very_carefully,_but_stop_reading_when_the_details_of_the_implementation_begin_to_be_discussed._I_believe_that_I_have_a_simpler_approach. This_means_you_should_read_through_the_paragraph_that_ends_with_“you_need_to_backtrack,_as_has_already_been_described.” This_is_bottom-of-page-177_through_the_first_complete_paragraph_on_page_179..zip
File Size: 4295.52 KB

SKU: 7440014909 Category: Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Or Upload Your Assignment Here:


Section 5.3.2 of the text describes the “Eight Queens Problem”. Read the description of the problem very carefully, but stop reading when the details of the implementation begin to be discussed. I believe that I have a simpler approach. This means you should read through the paragraph that ends with “you need to backtrack, as has already been described.” This is bottom-of-page-177 through the first complete paragraph on page 179.
We will have two classes: a “Board” class to represent the chessboard and a “Queen” class to represent a single Queen.
The Board class could be represented in a number of ways. The most intuitive representation might be a two-dimensional array; however, such an array wastes space because only eight squares out of 64 are used. Instead we will use an STL vector that contains the 8 Queens. Each Queen will be stored in the position of the vector that corresponds to the Queen’s column (i.e., the Queen in column 0 will be stored in position 0 of the vector, the Queen in column 1 will be stored in position 1 of the vector, and so on). Since each Queen will know its own location on the board, this vector will fully specify the state of the board.
Here is the pseudocode that I highly recommend. I have modified it from the pseudocode given in the text after a lot of experimentation with different approaches to determine the simplest approach.

pre: row < BOARD_SIZE && col < BOARD_SIZEpost: places a queen in each column of the calling object, beginning with the column “col”, and considering rows in that column beginning with row “row”, in such a way that none of them are under attack by any others.Returns true if successful, false if no such configuration can be foundplaceQueens(row: integer, col: integer): boolean {while (unconsidered squares exist in column “col” AND the problem is unsolved) {Beginning with row “row”, find the next row in column “col” that is not under attack by a queen in an earlier column;if (such a square exists) {Set the location of the Queen in column “col” to that squareif (this was the final queen to be placed OR placeQueens(firstRow, col + 1)) {return true;} else {// placing the queen in column “col” into row “row” didn’t work, so:Move the queen in column “col” to the next square in that columnrow = queens[col].getRow();}}}// exited the while loop, which means that all rows in this column have been considered.return false;}#include
#include
using namespace std;

class Queen {
public:
void setRow(int inRow);
int getRow() const;
private:
int row;
};
int Queen::getRow() const {

}
void Queen::setRow(int inRow) {

}
class Board {
public:
static const int BOARD_SIZE = 8;
Board();
void do8Queens();
void display() const;
private:
bool placeQueens(int row, int col);
bool findNextNotUnderAttackSquare(int& row, int col);
bool isUnderAttack(int row, int col);
vector queens;
};
Board::Board() {
queens.resize(BOARD_SIZE);
}
void Board::do8Queens() {
placeQueens(0, 0);
}
bool Board::placeQueens(int row, int col) {
// use the pseudocode above to complete this function.
}
bool Board::isUnderAttack(int testRow, int testCol) {

}

bool Board::findNextNotUnderAttackSquare(int& row, int col) {

}

void Board::display() const {

}
int main() {
Board board;
board.do8Queens();
board.display();
}

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] 代写 graph Section 5.3.2 of the text describes the “Eight Queens Problem”. Read the description of the problem very carefully, but stop reading when the details of the implementation begin to be discussed. I believe that I have a simpler approach. This means you should read through the paragraph that ends with “you need to backtrack, as has already been described.” This is bottom-of-page-177 through the first complete paragraph on page 179.
30 $