["R", "N", "B", "Q", "K", "B", "N", "R"],
["P", "P", "P", "P", "P", "P", "P", "P"],
[" ", " ", " ", " ", " ", " ", " ", " "],
[" ", " ", " ", " ", " ", " ", " ", " "],
[" ", " ", " ", " ", " ", " ", " ", " "],
[" ", " ", " ", " ", " ", " ", " ", " "],
["p", "p", "p", "p", "p", "p", "p", "p"],
["r", "n", "b", "q", "k", "b", "n", "r"]
def get_piece(self, row, col):
return self.board[row][col]
def move_piece(self, from_row, from_col, to_row, to_col):
piece = self.get_piece(from_row, from_col)
# Check if starting location has a piece
# Check if it's the correct player's turn
if piece.islower() != self.white_turn:
# Check if ending location is within the board
if to_row < 0 or to_row > 7 or to_col < 0 or to_col > 7:
# Check if ending location has an ally piece
if piece.lower() == self.get_piece(to_row, to_col).lower():
# Check the specific move rules for each piece
if from_row - to_row != 1 or abs(from_col - to_col) > 1:
if from_col != to_col and self.get_piece(to_row, to_col) == " ":
if to_row - from_row != 1 or abs(from_col - to_col) > 1:
if from_col != to_col and self.get_piece(to_row, to_col) == " ":
elif piece.upper() == "N":
if abs(from_row - to_row) not in (2, 1) or abs(from_col - to_col) not in (2, 1):
elif piece.upper() == "B":
if abs(from_row - to_row) != abs(from_col - to_col):
row_step = (to_row - from_row)