当我在g++下编译时,会得到以下错误:
函数
中的
'int search(int, int, int)':
1584:错误:'operator='在'* tt = & core.<anonymous union>::tt[((hash_stack[ply] >> 16) & 2047ul)]'中不匹配
1584:错误:注:候选人是:
118:注:tt_type& tt_type::operator=(const tt_type&)
118:注:参数1从'tt_type*'到'const tt_type&'没有已知的转换
static int search(int depth, int alpha, int beta) {
int best_score = -INF;
int best_move = 0;
int score;
struct move *moves;
int incheck = 0;
struct tt_type *tt; //LINE 1584
int oldalpha = alpha;
int oldbeta = beta;
int i, count=0;
nodes++;
/* test for draw by repetition */
hash_stack[ply] = compute_hash();
for (i=ply-4; i>=board[LAST]; i-=2) {
if (hash_stack[i] == hash_stack[ply]) count++;
if (count>=2) return 0;
}
/*
* check transposition table
*/
*tt = &TTABLE[ ((hash_stack[ply]>>16) & (CORE-1)) ];
if (tt->hash == (hash_stack[ply] & 0xffffU)) {
if (tt->depth >= depth) {
if (tt->flag >= 0) alpha = MAX(alpha, tt->score);
if (tt->flag <= 0) beta = MIN(beta, tt->score);
if (alpha >= beta) return tt->score;
}
best_move = tt->move & 07777;
}我之前定义过的
struct tt_type { //LINE 118
unsigned short hash; /* - Identifies position */
short move; /* - Best recorded move */
short score; /* - Score */
char flag; /* - How to interpret score */
char depth; /* - Remaining search depth */
};发布于 2011-10-14 21:03:57
错误消息中最重要的一行是:
118:note: no known conversion for argument 1 from 'tt_type*' to 'const tt_type&'它实质上意味着您正在尝试为引用指定一个指针。
这反过来使我认为,将代码中的* tt = & core.::tt[((hash_stack[ply] >> 16) & 2047ul)]更改为* tt = core.::tt[((hash_stack[ply] >> 16) & 2047ul)]进行深度复制或将tt = & core.::tt[((hash_stack[ply] >> 16) & 2047ul)]更改为浅拷贝将解决问题(取决于您的视角)。
发布于 2011-10-14 21:04:35
我怀疑你的第1584行确实是这样的:
*tt = &TTABLE[ ((hash_stack[ply]>>16) & (CORE-1)) ];*tt是struct tt_type型的。RHS的形式是&...,所以它是某种指针类型。可以将结构分配给结构,也可以将指针分配给指针,但不能将指针值分配给结构(除非重载了赋值运算符)。
我还没有研究足够的代码来理解它,但是您可能希望将*tt = ...更改为tt = ...。
发布于 2011-10-14 21:05:02
*tt = &TTABLE[ ((hash_stack[ply]>>16) & (CORE-1)) ];您正在尝试将指针存储到不是指针的变量中。
你要么需要
*tt = TTABLE[ ((hash_stack[ply]>>16) & (CORE-1)) ];创建数组的一个元素的副本(这是行不通的,因为tt没有初始化)
或
tt = &TTABLE[ ((hash_stack[ply]>>16) & (CORE-1)) ];若要使指针指向数组,请执行以下操作。
另一种编写第二个版本的方法是
tt = TTABLE + ((hash_stack[ply]>>16) & (CORE-1));https://stackoverflow.com/questions/7773495
复制相似问题