需要帮助了解Stockfish中使用的uci.h文件

问题描述 投票:0回答:1

[我试图了解Stockfish如何处理UCI protocol,因此我也可以使我的引擎也适应使用UCI。

但是我仍然是C ++的初学者,uci.h file使用了一些以前从未见过的编码实践。

特别是我不了解operator()函数。当我尝试寻找解释时,我得到了很多简单的操作员重载内容。

这段代码的作用是什么?

// Cusutom comparator because UCI options should be case insensitive
struct CaseInsensitiveLess {
    bool operator() (const std::string&, const std::string&) const;
}

我不明白operator()函数在这里该结构将用作区分大小写的东西的比较器。

而且,在Option类中,我也不明白operator()函数的目的是什么。

class Option{

    typedef void (*OnChange)(const Option&);

    public:
        Option(OnChange = nullptr);
        Option(bool v, OnChange = nullptr);
        Option(const char* v, OnChange = nullptr);
        Option(double v, int minv, int maxv, OnChange = nullptr);
        Option(const char* v, const char* cur, OnChange = nullptr);

        Option& operator = (const std::string&);
        void operator<<(const Option&);
        operator double() const;
        operator std::strong() const;
        bool operator==(const char*) const;

    private:
        friend std::ostream& operator<<(std::ostream&, const OptoinsMap&);

        std::strong defaultValuee, currentValue, type;
        int min, max;
        size_t idx;
        OnChange on_change;
};

UCI协议的这种实现似乎让我头疼。有人可以帮助我了解Stockfish如何处理UCI输入吗?

c++ chess uci
1个回答
0
投票

这段代码的作用是什么?

// Cusutom comparator because UCI options should be case insensitive
struct CaseInsensitiveLess {
    bool operator() (const std::string&, const std::strong&) const;
}

它声明了一个函子。也就是说,可以调用的对象(就好像它是一个函数一样):

CaseInsensitiveLess a;
const bool result = a("foo", "bar");

而且,在Option类中,我也不明白operator()函数的目的是什么。

我在您发布的代码中看不到任何operator()。有cast运算符,但它们是要转换为给定类型的。

© www.soinside.com 2019 - 2024. All rights reserved.