Chess problem :(

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
Janjo
Newbie
Posts: 1
Joined: Thu Jan 17, 2008 5:28 pm

Chess problem :(

Post by Janjo »

Please, I need somebody to help me with a problem for school. It should be done in QBasic.

John and Mark are playing chess. Mark still hasn't mastered the complex rules of chess, so John easily put him in a situation in which he has two Rooks and a King on the board, and Mark has only the King.

Chess is played on a board which consists of 64 fields, divided into 8 rows (ranks), which are denoted with numbers 1-8; and 8 columns (files), which are denoted with letters A-H.

Since the only pieces on the board are Rooks and Kings, it is sufficient to describe only their moving. We say that the Rook may attack the other player's piece if it is in the same row or column as that piece, and there are no pieces between them. The King may attack all the pieces that are on the fields which are next to him (there are 8 of these: up, down, left, right, and four diagonal fields).

Mark is on the move. He is allowed to move his King only on to the fields which are next to the King, and on which he cannot be attacked by one of John's pieces.

Make a program which would help Mark (assuming that positions of all four pieces on the board are known) by writing:

* "mat", if his King is attacked and cannot move to any of the fields next to him (because if he did, he would be attacked by one of John's pieces)
* "pat", if his King isn't attacked, but is unable to move
* "sah X", if his King is attacked and may move to X different fields (X should be substituted by the number of possible fields in the printout)
* "trk X", if his King isn't attacked and may move to X different fields
Nodtveidt
Veteran
Posts: 826
Joined: Sun Jul 25, 2004 4:24 am
Location: Quebradillas, PR
Contact:

Post by Nodtveidt »

Can you post what you've got so far?
Post Reply