Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Given the position of a bishop and a queen in a n*n chessboard, mark the remaining positions in the chess board as follows:

'*' --- if it is under attack from bishop

'$' --- if it is under attack from queen

'%' --- if it is under attack from both queen and bishop.

'.' --- if it is not under attack.
Input consists of 5 integers where first integer, n, corresponds to the size of the chess board.  Second and third integers correspond to the x and y coordinates of the bishop respectively, and fourth and fifth integers correspond to the x and y coordinates of the queen respectively.     Output consists of a nxn matrix obtained by applying the above rules.


What I have tried:

please help i aint even able to understand the question
Posted
Updated 4-Jul-19 11:44am
Comments
F-ES Sitecore 4-Jul-19 5:05am    
We're not here to do your homework for you. If you don't understand the problem then your first task is to learn the basics of how to play chess, and that is most certainly outside the remit of this forum.
Richard MacCutchan 4-Jul-19 5:45am    
If you do not understand the question then you need to talk to your teacher about it.

We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

Start by reading it carefully, and if you need to, get a chessboard an pieces to work out what you need.
Think about how the pieces attack: a pan for example can only "take" pieces if they are diagonally one space "above" them:
x.x
.p.
...
What the question want you to do is print out a chessboard showing how each square is "under attack" when you are given the location of two pieces. So start with a board that is "not under attack", and place the queen and bishop. Then modify the squares that the queen could move to, and the squares that the bishop could move to.

Try it on a real board with little bits of paper, and you'll see what your tutor means.
 
Share this answer
 
This isnt a hard job to do. You only need some basic C knowledge like from any "C for Dummies" tutorial and so do it.

Tip: create a data structure on which you apply some functions to get the result. Than print it on screen.

Like:
C++
char board[8][8] = {0};//memset to zero
//function parameter is the board and the position of the bishop
void applyBishop( char *board, int line, int row)
{
   board[line][row] = 'B';//mark position of bishop
   //here goes your code
}
bonus tip: check EVERY position that it is in the board (>= 0 and <8)
 
Share this answer
 
You know, the bishop attacks positions:
  • {x+i,y+i} with 0<=x+i<n, 0<=y+i<n
and
  • {x+i,y-i}, with 0<=x+1<n, 0<=y-i<n


The queen formulas are the same, with the addition of
  • {x+i,y} with 0<=x+i<n
and
  • {x,y+i}, with 0<=y+i<n

If you apply (as suggested) such formulas to your board matrix positions then the constraints are automatically satisfied.
 
Share this answer
 
Comments
KarstenK 4-Jul-19 13:09pm    
Dont ferget to respect the positions of this figures. They change with every move. And the bishop can change his color fields.
Quote:
please help i aint even able to understand the question

You need to talk to your teacher to at least understand the question.
We will not give you a full blowup solution because it- will not help you to learn anything.

First of all bishop and queen are 2 pieces of a chess game, their moves are well known. A little search should give you needed knowledge.
Once you know enough, take a sheet of paper and pencil.
Draw a sample chessboard and place both pieces.
Then draw a cross on each cell under attack of queen and a circle on each cell under attack of bishop.
That basically your algorithm which you have to translate to program.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900