Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

GIVEN THIS CODE IMPLEMENT HILL CLIMBING SOLUTION FOR THE FOLLOWING PARAMETERS. THE CODE WILL ASK YOU TO SELECT A NUMBER OF QUEENS, KNIGHTS, AND BOARD

GIVEN THIS CODE IMPLEMENT HILL CLIMBING SOLUTION FOR THE FOLLOWING PARAMETERS. THE CODE WILL ASK YOU TO SELECT A NUMBER OF QUEENS, KNIGHTS, AND BOARD SIZE AND THEN PRINT A BOARD.

image text in transcribedimage text in transcribed

image text in transcribed

#include #include #include #include using namespace std; bool check(char **board,int i,int j,int st,int N){ if(st == 1){ if(board[i][j] == 'K'){ return false; } for(int k = 0;k if(board[i][k] == 'Q'){ return false; } } for(int k = 0;k if(board[k][j] == 'Q'){ return false; } } for(int k = i-1,s = j-1;k >= 0 && s >= 0;k--,s--){ if(board[k][s] == 'Q'){ return false; } } for(int k=i+1,s=j+1;k if(board[k][s] == 'Q'){ return false; } } for(int k=i-1,s=j+1;k>=0 && s if(board[k][s] == 'Q'){ return false; } } for(int k = i+1,s = j-1;k= 0;k++,s--){ if(board[k][s] == 'Q'){ return false; } } int k = i; int s = j; if( k-2 >= 0){ if(s-1 >= 0){ if(board[k-2][s-1] == 'K'){ return false; } } if(s+1 = 0){ if(board[k+2][s-1] == 'K'){ return false; } } if(s+1 = 0){ if(k-1 >= 0){ if(board[k-1][s-2] == 'K'){ return false; } } if(k+1 = 0){ if(board[k-1][s+2] == 'K'){ return false; } } if(k+1 = 0){ if(s-1 >= 0){ if(board[k-2][s-1] == 'K'){ return false; } } if(s+1 = 0){ if(board[k+2][s-1] == 'K'){ return false; } } if(s+1 = 0){ if(k-1 >= 0){ if(board[k-1][s-2] == 'K'){ return false; } } if(k+1 = 0){ if(board[k-1][s+2] == 'K'){ return false; } } if(k+1 0){ if(check(board,i,j,1,N)){ board[i][j] = 'Q'; Q--; } } if(K > 0){ if(check(board,i,j,2,N)){ board[i][j] = 'K'; K--; } } if(Q == 0 && K == 0){ break; } } } } void printBoard(char **Board,int N){ cout> N; cout 4."; exit(0); } std::cout > Q; cout 1."; exit(0); } std::cout > K; cout 1."; exit(0); } char **board = new char*[N]; for(int i = 0;i board[i] = new char[N]; } initializeBoard(board,Q,K,N); printBoard(board,N); return 0; }

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 to Expert-Tailored 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

Recommended Textbook for

Relational Database Design With Microcomputer Applications

Authors: Glenn A. Jackson

1st Edition

0137718411, 978-0137718412

More Books

Students also viewed these Databases questions

Question

Would you change the ending of the book? If so, how?

Answered: 1 week ago

Question

Effective Delivery Effective

Answered: 1 week ago