Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use the knowledge from adversarial search find optimal solution. Write a python code to check if any King is unsafe on the Chessboard or not.

Use the knowledge from adversarial search find optimal solution. Write a python code to check if any King is unsafe on the Chessboard or not. Given a matrix board [8][8] comprising of the king (K), the queen(q), the bishop(b), the knight(t), the rook (r)and pawns (p) of black and white color. Empty spaces are represented by *.

To accomplish the task, you need to check which of the king i.e. black of white is unsafe. If you find him under attack by any of the piece, the answer will be according to the situation with explanation that black bishop can attack the white king. In case of both kings are safe then explanation would be like no King is in danger.

White Side: K, Q, B, T, R, P

Black Side: k, q, b, t, r, p

Examples:

Input:

board[][] = {{* * * k * * * *},

{p p p * p p p p},

{* * * * * b * *},

{* * * R * * * *},

{* * * * * * * *},

{* * * * * * * *},

{t P P P P P P *},

{* * K * * * * *}}

Output: White King in danger

Explanation: Black knight can attack the white king.

B. You are a robot assigned to place three Knights on a 3 x 3 chess board such that (1) all Knights do not attack each other, (2) only one Knight is placed in each row, and (3) only one Knight is placed in each column. Recall that a knight attacks in an L pattern, i.e., a knight moves two spaces rectilinearly and then one space at right angles to the initial movement.

For the benefit of students who do not play chess, the following boards illustrate the allowed cells (marked as O) and prohibited cells (marked as X) after you place a knight (marked as K) at a cell. Once a knight is placed at a cell marked as K, any other knight may be placed only in a cell marked as O, and may not be placed in a cell marked as X. Only symmetry-collapsed positions are shown below. All other constraint positions may be obtained by symmetry reflections and rotations.

row 3

K

X

X

row 3

X

O

X

row 3

O

X

O

row 2

X

O

X

row 2

K

X

X

row 2

X

K

X

row 1

X

X

O

row 1

X

O

X

row 1

O

X

O

col

C1

col

C2

col

C3

col

C1

col

C2

col

C3

col

C1

col

C2

col

C3

You decide to formulate this task as a CSP in which columns are the variables (named C1 through C3) and rows are the domain values (named 1, 2, and 3). After you have solved the CSP, each column (variable) will be assigned a row (value), and all constraints will be satisfied. The columns (variables) are C1-C3:

  • C1, col 1 - will be assigned the row number of the knight in column 1
  • C2, col 2 - will be assigned the row number of the knight in column 2
  • C3, col 3 - will be assigned the row number of the knight in column 3

The rows (domain values) are the digits 1-3:

1, the knight in that column is in row 1

2, the knight in that column is in row 2

3, the knight in that column is in row 3

There are no unitary constraints, and so the initial variable domains include all possible values:

D1 = {1, 2, 3} D2 = {1, 2, 3} D3 = {1, 2, 3}

First of all think all CSP constraints as explicit relations of all allowed pairs of variable values: Implement constraint graph associated with your CSP and then Run arc consistency also comment on your results.

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_2

Step: 3

blur-text-image_3

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

Real Time Database And Information Systems Research Advances

Authors: Azer Bestavros ,Victor Fay-Wolfe

1st Edition

1461377803, 978-1461377801

More Books

Students also viewed these Databases questions