The engine that I try to create it's based from Vice 1.0 --> https://chessprogramming.wikispaces.com/Vice
The things that I added to the engine are:
SqAttacked bitboard version
Added SearchRoot with PVS and Aspiration Window
Alphabeta PVS with LMR --> http://www.glaurungchess.com/lmr.html
IID for: pvnode && depth >= 4
IID for: cut_node && depth >= 6
And few other details
Now some code
Here is the "think" function:
Code: Select all
BestScore = SearchRoot(-INFINITE, INFINITE, 1, pos, info, RootInCheck);
for (currentDepth = 2; currentDepth <= info->depth; ++currentDepth) {
rootDepth = currentDepth;
BestScore = SearchWithAspiration(currentDepth, BestScore, pos, info, RootInCheck);
if (info->stopped) {
break;
}
}
Code: Select all
int TempScore = Score;
int alpha = Score - ASPIRATION; // ASPIRATION = 50
int beta = Score + ASPIRATION;
TempScore = SearchRoot(alpha, beta, depth, pos, info, InCheck);
if (info->stopped) {
return 0;
}
if (TempScore <= alpha || TempScore >= beta) {
TempScore = SearchRoot(-INFINITE, INFINITE, depth, pos, info, InCheck);
if (info->stopped) {
return 0;
}
}
return TempScore;Code: Select all
int givesCheck = SqAttacked(pos->KingSq[pos->side], pos->side ^ 1, pos);
if (BestScore == -INFINITE) {
Score = -AlphaBeta(-beta, -alpha, depth - 1, pos, info, PV_NODE, givesCheck);
}
else {
Score = -AlphaBeta(-alpha - 1, -alpha, depth - 1, pos, info, CUT_NODE, givesCheck);
if (!info->stopped && Score > alpha && Score < beta) {
Score = -AlphaBeta(-beta, -alpha, depth - 1, pos, info, PV_NODE, givesCheck);
}
}
//....
if (Score > BestScore) {
BestScore = Score;
if (Score > alpha) {
BestMove = rootMove;
if (Score >= beta) {
if (Legal == 1) {
info->fhf++;
}
info->fh++;
StoreHashEntry(pos, BestMove, beta, HFBETA, depth);
return beta;
}
alpha = Score;
_pvMove[rootDepth - 1] = rootMove;
info->bound = EXACT_BOUND;
DisplayPv(BestScore, pos, info);
}
}
//...
Code: Select all
if (BestScore == -INFINITE) {
Score = -AlphaBeta(-beta, -alpha, depth - 1, pos, info, NEW_NODE(nodeType), givesCheck);
}
else {
if (!pvNode &&
Legal >= FullDepthMoves &&
depth >= ReductionLimit &&
!InCheck &&
!givesCheck &&
!ISCAPTURE(move) &&
move != ttMove &&
!PROMOTED(move)) {
Score = -AlphaBeta(-(alpha + 1), -alpha, depth - 2, pos, info, NEW_NODE(nodeType), givesCheck);
}
else
Score = alpha + 1;
if (Score > alpha) {
Score = -AlphaBeta(-(alpha + 1), -alpha, depth - 1, pos, info, CUT_NODE, givesCheck);
if (!info->stopped && Score > alpha && Score < beta)
Score = -AlphaBeta(-beta, -alpha, depth - 1, pos, info, PV_NODE, givesCheck);
}
}
//.....
if (Score > BestScore) {
BestScore = Score;
BestMove = move;
if (Score > alpha) {
if (Score >= beta) {
if (Legal == 1) {
info->fhf++;
}
info->fh++;
if (!ISCAPTURE(BestMove) && !InCheck) {
if (BestMove != pos->searchKillers[0][pos->ply]) {
pos->searchKillers[1][pos->ply] = pos->searchKillers[0][pos->ply];
pos->searchKillers[0][pos->ply] = BestMove;
}
}
StoreHashEntry(pos, BestMove, beta, HFBETA, depth);
return beta;
}
alpha = Score;
if (!ISCAPTURE(BestMove)) {
pos->searchHistory[pos->pieces[FROMSQ(BestMove)]][TOSQ(BestMove)] += depth;
}
if (pvNode) {
_pvMoves[pos->ply][0] = BestMove;
int j = 0;
for (j = 0; j < _pvLength[pos->ply + 1]; j++) {
_pvMoves[pos->ply][j + 1] = _pvMoves[pos->ply + 1][j];
}
_pvLength[pos->ply] = _pvLength[pos->ply + 1] + 1;
}
}
}
With this new code and the same Evaluation function from Vice, running 1000 games vs Vice 1.0 1m+1s(can't play bullet games yet) the new version is not giving good results, like 40-45%
I'm expecting 50/55%(without touching eval function) score vs V1.0, I'm sure that there is something wrong, or something I have to change based on the things I've added
