本文整理汇总了C++中board::getToMove方法的典型用法代码示例。如果您正苦于以下问题:C++ board::getToMove方法的具体用法?C++ board::getToMove怎么用?C++ board::getToMove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类board
的用法示例。
在下文中一共展示了board::getToMove方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: findMove
bool findMove(board b, move &bestMove, int wtime, int btime, int movestogo)
{
if (queryBook(b, bestMove))
{
clock_t start = clock();
while (clock() < start + CLOCKS_PER_SEC/10);
return true;
}
clock_t deadline = 0;
clock_t hardline = 0;
if (b.getToMove())
{
if (btime != 0)
{
int target = btime/(movestogo+MOVE_LEAWAY) - OVERHEAD;
deadline = (CLOCKS_PER_SEC/1000)*target + clock();
hardline = (CLOCKS_PER_SEC/1000)*HARDLINE_FACTOR*target+clock();
}
}
else
{
if (wtime != 0)
{
int target = wtime/(movestogo+MOVE_LEAWAY) - OVERHEAD;
deadline = (CLOCKS_PER_SEC/1000)*target + clock();
hardline = (CLOCKS_PER_SEC/1000)*HARDLINE_FACTOR*target+clock();
}
}
if (deadline != 0)
return calcMoveID(b, bestMove, deadline, hardline);
else
return calcMove(b, bestMove);
}
示例2: minimax
int minimax(int depth, board b, int alpha, int beta, int movesDone)
{
lookupResult res;
bool haveHit = queryTable(b, res);
if (haveHit && depth <= res.depth)
{
if (res.type == SCORE_LOWERBOUND)
{
if (res.evaluation >= beta)
return -res.evaluation;
else
alpha = max(alpha, res.evaluation);
}
if (res.type == SCORE_UPPERBOUND)
{
if (res.evaluation <= alpha)
return -res.evaluation;
else
beta = min(beta, res.evaluation);
}
if (res.type == SCORE_EXACT)
return -res.evaluation;
}
//if (depth == 0)
// return quiesence(b, alpha, beta, false);
if (depth == 0)
return -b.eval();
if (inHistory(b))
return 0;
moveOrderer order(b);
vector<move> moves = b.genMoves();
sort(moves.begin(), moves.end(), order);
if (moves.size() == 0)
{
if (b.inCheck().first && !b.getToMove())
return MATESCORE(movesDone);
if (b.inCheck().second && b.getToMove())
return MATESCORE(movesDone);
return 0;
}
if (b.getPlyClock() >= 100)
return 0;
int bestSoFar = -MATESCORE_MAX;
if (haveHit)
{
board temp = b;
temp.executeMove(res.bestMove);
pushHistory(temp);
bestSoFar = minimax(depth-1, temp, -beta, -alpha, movesDone+1);
popHistory();
}
int besti = -1;
for (int i=0; i<moves.size() && bestSoFar < beta; i++)
{
if (haveHit && moves[i] == res.bestMove)
continue;
board temp = b;
temp.executeMove(moves[i]);
pushHistory(temp);
int curScore = minimax(depth-1, temp, -beta, -max(alpha, bestSoFar), movesDone+1);
popHistory();
if (curScore > bestSoFar)
{
bestSoFar = curScore;
besti = i;
}
}
if (besti == -1 && haveHit)
putTable(b, depth, bestSoFar, res.bestMove, alpha, beta);
else
putTable(b, depth, bestSoFar, moves[besti], alpha, beta);
return -bestSoFar;
}