So my questions are:
1) Is it impossible to get correct results using only material balance?
2) Are my Negascout & Quiescence functions implemented correctly?
3) Is there a way to make sure that the search functions are working?
4) Are there any other forums or resources that would help me solve this problem?
Code: Select all
int ComputerPlayer::Quiescence(MovesPly *&ptr, int alpha, int beta, int depth)
{
int score;
if (!ptr)
ptr = board->getMovesList(board->currentPlayer());
if (!ptr->size)
return -(INT_MAX - 2);
score = board->CalcScore();
if (tactical[depth])
score -= Board::pieceValues[15];
if (score >= beta || depth >= maxQs)
return score;
alpha = max(score, alpha);
sort(ptr->list.begin(), ptr->list.begin() + ptr->size, cmpHiLow);
getKillerMoves(ptr, depth);
if (!tactical[depth]) {
for (int n = 0; n < ptr->size; n++) {
if (ptr->list[n].move.xindex == NONE && !ptr->list[n].check)
return alpha;
tactical[depth + 1] = ptr->list[n].check;
board->doMove(ptr->list[n].move);
score = -Quiescence(ptr->list[n].next, -beta, -alpha, depth + 1);
board->undo(ptr->list[n].move);
delete ptr->list[n].next;
ptr->list[n].next = NULL;
if (score >= beta) {
setKillerMoves(ptr->list[n].move, depth);
return score;
}
alpha = max(alpha, score);
}
} else {
for (int n = 0; n < ptr->size; n++) {
tactical[depth + 1] = ptr->list[n].check;
board->doMove(ptr->list[n].move);
score = -Quiescence(ptr->list[n].next, -beta, -alpha, depth + 1);
board->undo(ptr->list[n].move);
delete ptr->list[n].next;
ptr->list[n].next = NULL;
if (score >= beta) {
setKillerMoves(ptr->list[n].move, depth);
return score;
}
alpha = max(alpha, score);
}
}
return alpha;
}
int ComputerPlayer::NegaScout(MovesPly *&ptr, int alpha, int beta, int depth, int limit)
{
int b = beta;
if (!ptr)
ptr = board->getMovesList(board->currentPlayer());
if (!ptr->size)
return -(INT_MAX - 2);
if (depth >= limit)
return Quiescence(ptr, alpha, beta, depth);
sort(ptr->list.begin(), ptr->list.begin() + ptr->size, cmpHiLow);
if (depth)
getKillerMoves(ptr, depth);
for (int n = 0; n < ptr->size; n++) {
tactical[depth + 1] = ptr->list[n].check;
board->doMove(ptr->list[n].move);
ptr->list[n].score = -NegaScout(ptr->list[n].next, -b, -alpha, depth + 1, limit);
if (ptr->list[n].score > alpha && ptr->list[n].score < beta && n > 0)
ptr->list[n].score = -NegaScout(ptr->list[n].next, -beta, -alpha, depth + 1, limit);
board->undo(ptr->list[n].move);
delete ptr->list[n].next;
ptr->list[n].next = NULL;
alpha = max(ptr->list[n].score, alpha);
if (alpha >= beta) {
setKillerMoves(ptr->list[n].move, depth);
return alpha;
}
b = alpha + 1;
}
return alpha;
}
void ComputerPlayer::think()
{
srand(time(NULL));
tactical[0] = board->inCheck(board->currentPlayer());
for (int depth = 0; depth <= maxNg; depth++)
NegaScout(curr, -INT_MAX, INT_MAX, 0, depth);
pickMove(curr);
assert(board->doMove(curr->list[0].move, color) == VALID_MOVE);
cout << board->printMove(curr->list[0].move) << endl;
delete curr;
curr = NULL;
}