def apply(self, board):
    if (not board.owner[self.start_index]):
        msg = 'Cannot move from an empty square ({0})'.format(self.start_index)
        raise InvalidMoveException(msg)
    if board.owner[self.end_index]:
        msg = 'Cannot move to a non-empty square ({0})'.format(self.end_index)
        raise InvalidMoveException(msg)
    is_backward_move = (((board.owner[self.start_index] == Player.WHITE) and (self.end_index > self.start_index)) or ((board.owner[self.start_index] == Player.BLACK) and (self.end_index < self.start_index)))
    if (is_backward_move and (board.piece_class[self.start_index] != PieceClass.KING)):
        msg = 'Cannot freely move backwards unless the piece is a king'
        raise InvalidMoveException(msg)
    new_board = board.clone()
    new_board.move_piece(self.start_index, self.end_index)
    return new_board
def apply(self, board):
    if (not board.owner[self.start_index]):
        msg = 'Cannot move from an empty square ({0})'.format(self.start_index)
        raise InvalidMoveException(msg)
    if board.owner[self.end_index]:
        msg = 'Cannot move to a non-empty square ({0})'.format(self.end_index)
        raise InvalidMoveException(msg)
    is_backward_move = (((board.owner[self.start_index] == Player.WHITE) and (self.end_index > self.start_index)) or ((board.owner[self.start_index] == Player.BLACK) and (self.end_index < self.start_index)))
    if (is_backward_move and (board.piece_class[self.start_index] != PieceClass.KING)):
        msg = 'Cannot freely move backwards unless the piece is a king'
        raise InvalidMoveException(msg)
    new_board = board.clone()
    new_board.move_piece(self.start_index, self.end_index)
    return new_board