def remove_rook_from_original_square(self, original_square, destination_square, move_played): originalrank = -1 if move.is_move_indicating_movement_of_onepiece_outofpossibility_of_two(move_played): originalrank = int(move_played[1]) - 1 if originalrank != -1: originalf = self.Files.index(move_played[2]) self.board[originalrank][originalf]=chessrules.make_square_blank() elif move.is_move_indicates_same2pieces_can_move(move_played): for rook in original_square: if rook.filep == self.Files.index(move_played[1]): self.board[rook.rank][rook.filep]=chessrules.make_square_blank() break elif len(original_square) >= 1: #is it horizontal movement, if both rooks are on same rank in original position for rook in original_square: diffsqrank = abs(rook.rank - destination_square[0]) diffsqfile = abs(rook.filep - destination_square[1]) if diffsqrank == 0 and diffsqfile == 1: self.board[rook.rank][rook.filep]=chessrules.make_square_blank() break elif diffsqrank == 0: apieceexists = False start_loop = rook.filep + 1 end_loop = diffsqfile if (rook.filep > destination_square[1]): #oh boy!! just check if rooks file is greater than dest file like Rf8 is greater than d8 start_loop = destination_square[1] + 1 end_loop = start_loop + diffsqfile - 1 for ifile in range(start_loop,end_loop): if self.board[rook.rank][ifile] != "": apieceexists = True break if apieceexists == False: self.board[rook.rank][rook.filep]=chessrules.make_square_blank() #same file movement,vertical rook movement elif diffsqfile == 0: self.board[rook.rank][rook.filep]=chessrules.make_square_blank() break
def remove_knight_from_original_square(self, original_square,\ destination_square, move_played): if move.is_move_indicates_same2pieces_can_move(move_played): for pp in original_square: if pp.filep == self.Files.index(move_played[1]): self.board[pp.rank][pp.filep]= chessrules.make_square_blank() else: for pp in original_square: if (pp.filep - destination_square[1] == 1 or \ pp.filep - destination_square[1] == -1) and \ abs(pp.rank - destination_square[0]) == 2: self.board[pp.rank][pp.filep]=chessrules.make_square_blank() if destination_square[0] - pp.rank == 1 and pp.filep - destination_square[1] == 2: self.board[pp.rank][pp.filep]=chessrules.make_square_blank() if abs(destination_square[0] - pp.rank) == 1 and abs(pp.filep - destination_square[1]) == 2: self.board[pp.rank][pp.filep]=''