Win a K vs KQ endgame
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 will then a output a move which will eventually lead to checkmate.
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.
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
Triples representing pieces and coordinates such as
('K', 0, 2)
After three squares are taken as input, the computer outputs a single legal move. Behaviour on invalid input is undefined.
This procedure must terminate using your program or function:
User sets up a legal KQ vs K position on a physical chessboard.
User inputs the board position. The computer outputs a legal move. If the move is a checkmate, STOP. If the move is a stalemate or allows the computer's queen to be captured, your solution is invalid.
User makes the computer's move on the physical board.
User makes a legal move for the lone king on the physical board.
User goes to step 2 and repeats.
In other words, the computer must eventually win by checkmate, through repeatedly using your program or function.
Furthermore, from any legal starting position the checkmate must occur in 50 or fewer moves by the computer, i.e. the above procedure will be repeated no more than 50 times. An explanation as to why your solution will always win in 50 moves or fewer is appreciated.
(Of course, a physical chessboard is in 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
- The checkmate must occur in 50 or fewer moves by the computer, but it does not need to be as fast as possible.
- Chess libraries are not permitted.
- Shortest program in each language (in bytes) wins.