I remember very little about what exactly the code was or where exactly I put the code in Toga but I could borrow heavily from Glaurung, that I do remember. It was 2008 there was no Stockfish yet around
. I only slightly changed the board values from Glaurung that guide the Knight and Bishop in the right direction. Posted the code on
Code: Select all
static const int KBNKingposMatrix[64] = {
90, 70, 50, 30, 10, -10, -30, -50,
70, 40, 20, 0, -20, -40, -60, -30,
50, 20, -10, -30, -50, -70, -40, -10,
30, 0, -30, -60, -80, -50, -20, 10,
10, -20, -50, -80, -60, -30, 0, 30,
-10, -40, -70, -50, -30, -10, 20, 50,
-30, -60, -40, -20, 0, 20, 40, 50,
-50, -30, -10, 10, 30, 50, 70, 90,
};
.
static const int KingDistanceBonus[8] = {0, 0, 50, 40, 30, 20, 10, 5};
.
.
// eval()
int eval(board_t * board, int alpha, int beta, int ThreadId) {
int opening, endgame;
material_info_t mat_info[1];
pawn_info_t pawn_info[1];
int mul[ColourNb];
int phase;
int eval;
int wb, bb;
int winnerKSQ, loserKSQ;
int lazy_eval,probe_score; // Thomas
ASSERT(board!=NULL);
ASSERT(board_is_legal(board));
ASSERT(!board_is_check(board)); // exceptions are extremely rare
// init
opening = 0;
endgame = 0;
/* if (egbb_is_loaded && board->piece_nb <=5 && ABS(SearchBest[0].value) >= WIN_SCORE) {
if (probe_bitbases(board, probe_score)){
return probe_score;
}
} */
// material
material_get_info(mat_info,board,ThreadId);
opening += mat_info->opening;
endgame += mat_info->endgame;
mul[White] = mat_info->mul[White];
mul[Black] = mat_info->mul[Black];
// PST
opening += board->opening;
endgame += board->endgame;
// pawns
pawn_get_info(pawn_info,board,ThreadId);
opening += pawn_info->opening;
endgame += pawn_info->endgame;
// draw
eval_draw(board,mat_info,pawn_info,mul);
if (mat_info->mul[White] < mul[White]) mul[White] = mat_info->mul[White];
if (mat_info->mul[Black] < mul[Black]) mul[Black] = mat_info->mul[Black];
if (mul[White] == 0 && mul[Black] == 0) return ValueDraw;
// win
if (board->piece_nb == 4){ // KBNK?
if (board->number[WhiteKnight12] == 1 && board->number[WhiteBishop12] == 1){
eval = ValueWin;
wb = board->piece[White][1];
ASSERT(PIECE_IS_BISHOP(board->square[wb]));
winnerKSQ = KING_POS(board,White);
loserKSQ = KING_POS(board,Black);
if (SQUARE_COLOUR(wb) == SQUARE_COLOUR(A8)){
winnerKSQ = ((winnerKSQ)^0x0F);
loserKSQ = ((loserKSQ)^0x0F);
}
eval += KBNKingposMatrix[SquareTo64[loserKSQ]];
eval += KBNKingposMatrix[SquareTo64[loserKSQ]];
eval += KingDistanceBonus[DISTANCE(KING_POS(board,White),KING_POS(board,Black))];
}
else{ // KKBN?
if (board->number[BlackKnight12] == 1 && board->number[BlackBishop12] == 1){
eval = ValueWin;
bb = board->piece[Black][1];
ASSERT(PIECE_IS_BISHOP(board->square[bb]));
winnerKSQ = KING_POS(board,Black);
loserKSQ = KING_POS(board,White);
if (SQUARE_COLOUR(bb) == SQUARE_COLOUR(A8)){
winnerKSQ = ((winnerKSQ)^0x0F);
loserKSQ = ((loserKSQ)^0x0F);
}
eval += KBNKingposMatrix[SquareTo64[loserKSQ]];
eval += KBNKingposMatrix[SquareTo64[loserKSQ]];
eval += KingDistanceBonus[DISTANCE(KING_POS(board,White),KING_POS(board,Black))];
}
}
if (COLOUR_IS_WHITE(board->turn)){
return (eval);
}
else{
return (-eval);
}
} // End of KBNK block
.
.
.
I see that Teemu Pudas (Vempele) writes in the same thread that he adapted the code so that would imply it is already in one of the CMLX versions. I did not remember that... He probably placed the code better, my version was placed somewhere as one of of the 'win' recognizers/situations early in eval.cpp but I don't know how Teemu did it.
I will upload that eval.cpp into the Developers Discussions subforum of TDDB I hope you can find it there Jerry.