I have as task to create a code that should randomly place two chess pieces on the board
The board looks like this: Chess board
What I should do is "place" two randomly selected chess pieces (one black, one white) on this board above and find out if these pieces fall in places where they would threat each other based on chess rules. I should repeat this 10 000 times and find out how often a threatening situation is met. Pieces should not fall in the same square.
There are two different scenarios:
3a. The chess pieces are rooks(towers) - move horisontally or vertically OR 3b. The chess pieces are queens - move horisontally, vertically and diagonally OR
My assumption is that the approach in 3a should be that if either the first digit or last digit are same for both chess pieces the situation causes a threat. I would use the random-function to assign random numbers for both pieces and run this 10K times. I'm not sure though how to build this code to find out if the chess pieces cause a threat to each other. How to use the chess board (11-88) to define the random numbers?
the approach for 3b is, on the other hand, a big question mark due to the fact that queens can also move diagonally.
I would really appreciate some code example to understand how this is tackled. Thanks!
Aucun commentaire:
Enregistrer un commentaire