Mate with King & Queen
Description:
Task:
Checkmate the opponent's king using a king and queen.
Input:
Three strings representing the locations of your king, your queen and the opponent's king (in that order). There are no other pieces on the board. The position is guaranteed to be legal, and the opponent's king will not be in check. It is your move.
Squares are indicated using algebraic notation, where "a1"
is the bottom-left corner of the board and "h8"
is the top-right.
Example: The input "e5", "b2", "d7"
represents the following position:
8 ........
7 ...k....
6 ........
5 ....K...
4 ........
3 ........
2 .Q......
1 ........
abcdefgh
Output:
The move you want to play, a string of 3 characters. The first character shows the piece moved, either "K"
or "Q"
. The remaining 2 characters identify the square to move it.
For example, in the position above the move "Qb7"
leads to the following position, checking (but not mating) the opponent's king:
8 ........
7 .Q.k....
6 ........
5 ....K...
4 ........
3 ........
2 ........
1 ........
abcdefgh
Testing:
First your function is called on the initial position. After its output is received, the testing framework makes a move for the opponent's king. It then calls your function on the updated position to get your next move. This process continues until the opponent's king is checkmated. Your function does not need to determine if mate occurs - the testing framework does this.
The function fails if any of the following occur:
- It makes a illegal move.
- Its move leaves the king in stalemate i.e. has no legal moves but is not in check.
- Its move allows the king to capture your queen. The opponent will do so!
- 50 moves elapse without the king being checkmated.
Example:
Here is a sequence of moves from the first position above resulting in checkmate. The move numbers are not part of the kata requirement - they just make the moves easier to read.
1.Qb8 ke7 2.Qc8 kf7 3.Qd8 kg7 4.Qe8 kh7 5.Kf6 kh6 6.Qg6
is the following checkmate:
8 ........
7 ........
6 .....KQk
5 ........
4 ........
3 ........
2 ........
1 ........
abcdefgh
Related kata:
This kata was inspired by Valid Checkmate.
Also related are Check and Mate? and Is the King in check ?
For a much harder checkmating problem, break your brain on Chess - checkmate with rook in 16 moves
To program a problem-solving agent for a non-chess puzzle, try Play Nerdle - It's Wordle for Calculations.
Similar Kata:
Stats:
Created | May 31, 2024 |
Published | May 31, 2024 |
Warriors Trained | 14 |
Total Skips | 0 |
Total Code Submissions | 12 |
Total Times Completed | 4 |
Python Completions | 4 |
Total Stars | 2 |
% of votes with a positive feedback rating | 100% of 1 |
Total "Very Satisfied" Votes | 1 |
Total "Somewhat Satisfied" Votes | 0 |
Total "Not Satisfied" Votes | 0 |
Total Rank Assessments | 1 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 5 kyu |