【发布时间】:2015-01-05 06:03:29
【问题描述】:
我目前正在用 C++ 编写一个国际象棋程序。搜索算法是 alphaBeta,这就是为什么我在遍历它们并评估它们之前对它们进行排序。我的主要类是 Position 类,它执行所有搜索,还包含一个比较两个 Move 的函数。
class Position{
private:
//This vector holds the moves of the current line, to be evaluated
vector<Move> currentSearch(4000);
// This function uses internal fields of class Position to determine, whether move1 or move2 should be searched first
bool compare(const Move& move1, const Move& move2);
int alphaBeta(int ply, int depth, int alpha, int beta);
}
现在要对 currentSearch 中的移动进行排序,我总是调用 alphaBeta
sort(currentSearch.begin(), currentSearch.end(), bind(mem_fn(&Position::compare),this,_1,_2));
所以这会生成一个带有bind(mem_fn(&Position::compare),this,_1,_2)); 的函子
在一次搜索中执行多次以生成相同的函子。
我希望有一个初始化为 bind(mem_fn(&Position::compare),this,_1,_2)); 的 Position 类的成员,但是该成员必须具有什么类型,或者设计它的正确方法是什么?
【问题讨论】:
标签: c++ functional-programming function