Chess is a game with 6 different types of pieces that can move in different ways:
Pawns - They can only move up or capture diagonally (also forward). Capturing a piece behind them or beside them is illegal. The only exception is en passant. For this challenge, if a pawn reaches the 8th rank (or row), assume it becomes a queen.
Bishops - They move diagonally and the squares they travel on will always have the same color (i.e if the square the bishop is currently on is white, the bishop can't move to a darker square for instance).
Knights - They move pretty awkwardly. They can move two spaces up/down then one space to the right/left or two spaces right/left then on space up/down.
Rooks - They can only move in straight lines, up or down or left or right.
Queens - They can move diagonally like a bishop or in straight lines like a rook
Kings - They can only move to squares they are touching (including diagonals).
This chess.com link to clarify the above. A chessboard and its coordinates are shown below:
So given an entirely empty chessboard except for one piece and the inputs -- the piece's type and its current position, what are the piece's legal moves?
Examples
Input: Rook a8
Output: a1 a2 a3 a4 a5 a6 a7 b8 c8 d8 e8 f8 g8 h8
Input: Pawn a2
Output: a4 a3
Input: Pawn a3
Output: a4
Input: Knight a1
Output: c2 b3
Input: Bishop h1
Output: a8 b7 c6 d5 e4 f3 g2
Input: King b2
Output: c2 c3 c1 b3 b1 a1 a2 a3
Input: Queen h1
Output: a8 b7 c6 d5 e4 f3 g2 h2 h3 h4 h5 h6 h7 h8 a1 b1 c2 d1 e1 f1 g1
Rules and Specifications
A legal move is defined as a move in which the piece can go to while being on the board. So a rook at a1 can go to a8 (moving to the right) but not to b2 since you can't get there with a straight line (only possible in two or more moves)
Pawns will never be in the first or eighth rank (it would then be another piece). If a pawn is in the second rank, it can move up two spaces (not for captures). Otherwise, it can only move forward a square.
Notation for Queening a pawn is not needed
Capitalization does not matter though the letter must come before and attached to the number
The acceptable moves must be separated in some way (i.e commas, spaces, different lines, in a list)
Always assume that the bottom left corner is a1 and you are playing as White
The input can be a single string (i.e
rooka3
orRook a3
orrook a3
orRook A3
) is acceptable and can be in any order (i.e the position before the type likeA3 rook
). Multiple strings are also acceptable.
Winning Criteria
Shortest code wins!
a1 a2 a3 a4 a5 a6 a7 b8 c8 d8 e8 f8 g8 h8
, notb1 ... h1
. \$\endgroup\$