Not a duplicate of the valid move challenge because that asks for specific pieces.
Backstory
The other night I was doing a little trolling with ChatGPT and chess. I was trying to get it to call me out for making illegal moves, as a lot of the time, you can feed it whatever nonsense you want. While doing so, I wondered if it didn't recognise invalid moves because they were technically valid under some board arrangement. I then thought I'd make a code golf challenge.
The Challenge
Given a start and end square on an 8x8 chess board, determine whether the move is possible on any legal chess board.
Alternatively, can any kind of piece make a move from the start square to the end square.
Chess Pieces
For this challenge, you only need to know how the knight and queen move. King and pawn moves can be considered equivalent to a queen moving a single square. A rook move is a queen move restricted to vertical and horizontal movement. A bishop move is a queen move restricted to diagonal movement. Castling and En Passant (holy hell) aren't relevant either.
A valid move from the square highlighted in red is any square marked with a green circle:
This includes the vertical, horizontal and diagonal movement of the queen, as well as the L-shaped movement of the knight.
Rules
- The positions will be given in algebraic chess notation (letter then number of the square).
- The start and end squares will never be the same square.
- The start and end squares will always be valid squares on an 8x8 chess board.
- Positions can be given in any reasonable and convenient format, including:
- Strings (e.g.
["f4", "b8"]
) - A list of strings (e.g.
[["f", "4"], ["b", "8"]]
) - A list of numbers that represent the character codes of each string item (e.g.
[[102, 52], [98, 56]]
) - A string, number pairs (e.g.
[["f", 4], ["b", 8]]
) - A list of row/column pairs (e.g
[[5, 3], [1, 7]]
OR[[6, 4], [2, 8]]
). Can be 0-indexed or 1-indexed. Your choice.
- Strings (e.g.
- Output in any reasonable and convenient format.
- This is code-golf, so make sure your answer is as short as possible.
Test Cases
start, end -> plausible?
a1, a4 -> True
b2, d3 -> True
b2, e3 -> False
b2, c3 -> True
a1, h8 -> True
c7, g3 -> True
c7, g2 -> False