Win a K vs KQ endgame
Summary
The goal of this challenge is to create a program or function which will win a Chess game with a King and Queen against a lone King. The user will specify three squares, representing the locations of the computer's King, the computer's Queen, and the user's King. The computer and user will then take turns making legal chess moves (with the computer moving first) until the computer checkmates the user's kinga output a move which will eventually lead to checkmate.
Input/Output
The program or function will first take as input three squares, representing the locations of the computer's King, the computer's Queen, and the user's King (not necessarily in that order). It can be assumed that the input is a legal position from which it is possible to force checkmate in 50 or fewer moves.
Parsing input is not the point of this challenge, so all reasonable forms of input/output are allowed, including but not limited to
Strings with algebraic chess notation such as
"Ke4"
or"Qf6"
Triples representing pieces and coordinates such as
('K', 0, 2)
After three squares are taken as input, the following will alternatecomputer outputs a single legal move. Behaviour on invalid input is undefined.
Requirements
This procedure must terminate using your program or function:
ComputerUser sets up a legal KQ vs K position on a physical chessboard.
User inputs the board position. The computer outputs a single legal move. If the move is a checkmate, STOP.
User makes the computer's move on the physical board.
User inputsmakes a single legal move for the lone king on the physical board.
User goes to step 2 and repeats.
untilIn other words, the computer's move is acomputer must eventually win by checkmate, after which thethrough repeatedly using your program/function ends or function. Behaviour upon receiving illegal moves
Furthermore, from any legal starting position the checkmate must occur in 50 or invalid inputfewer moves by the computer.
(Of course, a physical chessboard is undefinedin no way necessary to test the code; I only mentioned it to help visualize the procedure. The chessboard could just as well be visualized in the user's head.)
Possible test cases
The squares are given in the order: computer's Queen, computer's King, user's King
c2, h8, a1
(must avoid stalemate)a1, a2, a8
a8, a1, e5
Rules
- The checkmate must occur in 50 or fewer moves by the computer, but it does not need to be as fast as possible.
- 3 move repetition does not matter.
- Chess libraries are not permitted.
- Shortest program in each language (in bytes) wins.
Questions for sandbox
Is it feasible/a good idea to disallow chess libraries?
How can I never specified white and black pieces because it's not relevant toword the challenge. But should Irules better if they are not currently sufficiently clear?