Chess Pieces

Published by Kavin Umasankar in

Create a function that takes the name of a chess piece, its position and a target position. The function should return True if the piece can move to the target and False if it can't.

The possible inputs are "Pawn", "Knight", "Bishop", "Rook", "Queen" and "King".

Examples

can_move("Rook", "A8", "H8") ➞ True

can_move("Bishop", "A7", "G1") ➞ True

can_move("Queen", "C4", "D6") ➞ False

Notes

  • Do not include pawn capture moves and en passant.
  • Do not include castling.
  • Remember to include pawns' two-square move on the second rank!
  • Look for patterns in the movement of the pieces.
Watch a quick demo on how Edabit works.