def get_possibles_moves(cls, piece): '''Get all possible moves (for a piece)''' if piece.name == 'pawn': movements = PossibleMove.get(piece, False) # for pawn attacking and non-attacking moves are completely differents attacks = PossibleMove.get(piece, True) for coord in attacks: if cls.players[inv_c(piece.color)].get_piece(coord): movements.append(coord) else: movements = PossibleMove.get(piece, True) # get movements as if the piece was attacking -> include capture moves return movements
def check_for_check(cls, color, kingcheck=True): '''Check if king is attacked by an opponent piece''' king_coord = cls.players[color].king.coord # check if king coord is attack by an opponent piece for piece in cls.players[inv_c(color)].pieces: if king_coord in PossibleMove.get(piece, True, kingcheck=kingcheck): return True
def check_can_move(cls, piece, coord, is_attacking): ''' Check if the given piece can move at the given destination ''' # first check if other pieces on coord if cls.players[piece.color].get_piece(coord): # other piece of same color on destination case -> can't move return False if coord in PossibleMove.get(piece, is_attacking): return True