Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Using the code below follow the prompt for N,Q,K to solve for hill climbing. The code below generates the board in c++. #include #include #include

Using the code below follow the prompt for N,Q,K to solve for hill climbing. The code below generates the board in c++.

image text in transcribedimage text in transcribed

image text in transcribed

#include

#include

#include

using namespace std;

void print_board(int[10][10], int);

int main(){ int brd[10][10]; int n = 10; srand(time(NULL)); int k = 0, q = 0;

int i = 0; int j = 0;

for(i = 0; i

cout>k; cout>q; cout>n;

//Making a board of n X n, with k Kings and q Queens.

int p = 0;//For placing of the kings/queens for(; k+q > 0;){ i = 2; p = rand()%(n*n);//Get a random number from 0 to sqr(n) - 1 //using p and p%n as row and column number respectively if(brd[p][p%n] == 2){//it's empty lets add something i = rand()%2; // randomly assign king or queen( 0 or 1) if( i == 0 && k > 0) k--;//king added, one less to add else if(i == 1 && q > 0) q--;//queen added else continue;//there's no point if k = 0, or q = 0 brd[p][p%n] = i; } } print_board(brd, n);

}

void print_board(int brd[10][10], int n){ int i = 0; int j = 0; for(i = 0; i

}

1 Solving Queens-and-Knights Problem with Hill Climbing Given an N N board, Q queens, and K knights, the objective is to place the queens and the knights on the board so that no queen attacks another queen no knight attacks another knight no knight attacks a queen Note that it is ok for a queen to attack a knight

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Minta tolong untuk mengerjakan soal ini mohon di bantu

Answered: 1 week ago