Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Language is in C Problem 1: Checkmate mate! In this problem you are given a chess board with pieces on (all formatted as characters), you
Language is in C
Problem 1: Checkmate mate! In this problem you are given a chess board with pieces on (all formatted as characters), you have to detect whether black is on check, checkmate or not threatened at all Input is given as 8 lines of 8 characters. Capital letters stand for "white" and lower-case letters stand for "black" pieces. Don't assume the input is a proper/complete chess game (e.g. there might be all queens) but there always be only one king of each color. A hyphen "-" stands for empty cell. The output must be either "check", "checkmate" or "not threatened". You can read the piece moves on Wikipedia (https://en.wikipedia.org/wiki/Chess). In short, all pieces move and capture the same except for Pawn. Rook moves horizontally or vertically, Bishop moves diagonally, Knight has L shaped jumps, Queen moves like both Rook and Bishop, and King can move to its adjacent 8 cells only. Pawn moves straight toward the opponent but can capture the piece on its immediate right or left diagonal cell (that is what matters for checking the king) The king is in check, if it is threatened by an enemy piece (the piece can capture the king). If it is in check and the player doesn't have any move to get the king out of the check, it is checkmate and the player loses the match. A king may get out of the check by either moving out of the threatened cell (into a non- threatened one) or if another piece blocks the way of the opponent's piece that can capture the king (or knocks out the opponent's piece that is threatening the king). Note that the king might be threatened by two opponent pieces. In that case the only valid move is for the king to move to a non-threatened cell. White: K-king, Q-queen, R- rook, B-bishop, N-knight, P-pawn Black: k-king, q-queen r-rook, b-bishop, n-knight, p-pawn Sample input (the text is the input, the picture corresponds to the board it is representing and is only here for demonstration): p- P-RP PP--PK Output: checkmate Problem 1: Checkmate mate! In this problem you are given a chess board with pieces on (all formatted as characters), you have to detect whether black is on check, checkmate or not threatened at all Input is given as 8 lines of 8 characters. Capital letters stand for "white" and lower-case letters stand for "black" pieces. Don't assume the input is a proper/complete chess game (e.g. there might be all queens) but there always be only one king of each color. A hyphen "-" stands for empty cell. The output must be either "check", "checkmate" or "not threatened". You can read the piece moves on Wikipedia (https://en.wikipedia.org/wiki/Chess). In short, all pieces move and capture the same except for Pawn. Rook moves horizontally or vertically, Bishop moves diagonally, Knight has L shaped jumps, Queen moves like both Rook and Bishop, and King can move to its adjacent 8 cells only. Pawn moves straight toward the opponent but can capture the piece on its immediate right or left diagonal cell (that is what matters for checking the king) The king is in check, if it is threatened by an enemy piece (the piece can capture the king). If it is in check and the player doesn't have any move to get the king out of the check, it is checkmate and the player loses the match. A king may get out of the check by either moving out of the threatened cell (into a non- threatened one) or if another piece blocks the way of the opponent's piece that can capture the king (or knocks out the opponent's piece that is threatening the king). Note that the king might be threatened by two opponent pieces. In that case the only valid move is for the king to move to a non-threatened cell. White: K-king, Q-queen, R- rook, B-bishop, N-knight, P-pawn Black: k-king, q-queen r-rook, b-bishop, n-knight, p-pawn Sample input (the text is the input, the picture corresponds to the board it is representing and is only here for demonstration): p- P-RP PP--PK Output: checkmateStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started