Umko 0.7
Posted: 02 Mar 2010, 07:50
Have a look at pos_eval.ccp(umko 0.7)
fruit 2.1 material.ccp
2 more samples,same files:
fruit 2.1:
the owf obf,ebf ,ewf calculations were introduced in toga iirc.
not that it matters.
- Code: Select all
void Position::eval_mat(MaterialHash* mh) const{
int recog;
int flags, cflags[2], mul[2];
const int wp = num[WP];
const int wn = num[WN];
const int wb = num[WB];
const int wr = num[WR];
const int wq = num[WQ];
const int bp = num[BP];
const int bn = num[BN];
const int bb = num[BB];
const int br = num[BR];
const int bq = num[BQ];
const int wt = num[W]-1;
const int bt = num[B]-1;
const int wm = wb + wn;
const int bm = bb + bn;
recog = EG_NONE;
if(wt == 0 && bt == 0) { recog = EG_KK; }
else if (wt == 1 && bt == 0) {
if (wb == 1) recog = EG_KBK;
if (wn == 1) recog = EG_KNK;
if (wp == 1) recog = EG_KPK;
} else if (wt == 0 && bt == 1) {
if (bb == 1) recog = EG_KKB;
if (bn == 1) recog = EG_KKN;
if (bp == 1) recog = EG_KKP;
} else if (wt == 1 && bt == 1) {
if (wq == 1 && bq == 1) recog = EG_KQKQ;
if (wq == 1 && bp == 1) recog = EG_KQKP;
if (wp == 1 && bq == 1) recog = EG_KPKQ;
if (wr == 1 && br == 1) recog = EG_KRKR;
if (wr == 1 && bp == 1) recog = EG_KRKP;
if (wp == 1 && br == 1) recog = EG_KPKR;
if (wb == 1 && bb == 1) recog = EG_KBKB;
if (wb == 1 && bp == 1) recog = EG_KBKP;
if (wp == 1 && bb == 1) recog = EG_KPKB;
if (wn == 1 && bn == 1) recog = EG_KNKN;
if (wn == 1 && bp == 1) recog = EG_KNKP;
if (wp == 1 && bn == 1) recog = EG_KPKN;
} else if (wt == 2 && bt == 0) {
if (wb == 1 && wp == 1) recog = EG_KBPK;
if (wn == 1 && wp == 1) recog = EG_KNPK;
} else if (wt == 0 && bt == 2) {
if (bb == 1 && bp == 1) recog = EG_KKBP;
if (bn == 1 && bp == 1) recog = EG_KKNP;
} else if (wt == 2 && bt == 1) {
if (wr == 1 && wp == 1 && br == 1) recog = EG_KRPKR;
if (wb == 1 && wp == 1 && bb == 1) recog = EG_KBPKB;
} else if (wt == 1 && bt == 2) {
if (wr == 1 && br == 1 && bp == 1) recog = EG_KRKRP;
if (wb == 1 && bb == 1 && bp == 1) recog = EG_KBKBP;
}
snip------------------------------
fruit 2.1 material.ccp
- Code: Select all
static void material_comp_info(material_info_t * info, const board_t * board) {
int wp, wn, wb, wr, wq;
int bp, bn, bb, br, bq;
int wt, bt;
int wm, bm;
int colour;
int recog;
int flags;
int cflags[ColourNb];
int mul[ColourNb];
int phase;
int opening, endgame;
ASSERT(info!=NULL);
ASSERT(board!=NULL);
// init
wp = board->number[WhitePawn12];
wn = board->number[WhiteKnight12];
wb = board->number[WhiteBishop12];
wr = board->number[WhiteRook12];
wq = board->number[WhiteQueen12];
bp = board->number[BlackPawn12];
bn = board->number[BlackKnight12];
bb = board->number[BlackBishop12];
br = board->number[BlackRook12];
bq = board->number[BlackQueen12];
wt = wq + wr + wb + wn + wp; // no king
bt = bq + br + bb + bn + bp; // no king
wm = wb + wn;
bm = bb + bn;
// recogniser
recog = MAT_NONE;
if (false) {
} else if (wt == 0 && bt == 0) {
recog = MAT_KK;
} else if (wt == 1 && bt == 0) {
if (wb == 1) recog = MAT_KBK;
if (wn == 1) recog = MAT_KNK;
if (wp == 1) recog = MAT_KPK;
} else if (wt == 0 && bt == 1) {
if (bb == 1) recog = MAT_KKB;
if (bn == 1) recog = MAT_KKN;
if (bp == 1) recog = MAT_KKP;
} else if (wt == 1 && bt == 1) {
if (wq == 1 && bq == 1) recog = MAT_KQKQ;
if (wq == 1 && bp == 1) recog = MAT_KQKP;
if (wp == 1 && bq == 1) recog = MAT_KPKQ;
if (wr == 1 && br == 1) recog = MAT_KRKR;
if (wr == 1 && bp == 1) recog = MAT_KRKP;
if (wp == 1 && br == 1) recog = MAT_KPKR;
if (wb == 1 && bb == 1) recog = MAT_KBKB;
if (wb == 1 && bp == 1) recog = MAT_KBKP;
if (wp == 1 && bb == 1) recog = MAT_KPKB;
if (wn == 1 && bn == 1) recog = MAT_KNKN;
if (wn == 1 && bp == 1) recog = MAT_KNKP;
if (wp == 1 && bn == 1) recog = MAT_KPKN;
} else if (wt == 2 && bt == 0) {
if (wb == 1 && wp == 1) recog = MAT_KBPK;
if (wn == 1 && wp == 1) recog = MAT_KNPK;
} else if (wt == 0 && bt == 2) {
if (bb == 1 && bp == 1) recog = MAT_KKBP;
if (bn == 1 && bp == 1) recog = MAT_KKNP;
} else if (wt == 2 && bt == 1) {
if (wr == 1 && wp == 1 && br == 1) recog = MAT_KRPKR;
if (wb == 1 && wp == 1 && bb == 1) recog = MAT_KBPKB;
} else if (wt == 1 && bt == 2) {
if (wr == 1 && br == 1 && bp == 1) recog = MAT_KRKRP;
if (wb == 1 && bb == 1 && bp == 1) recog = MAT_KBKBP;
}
2 more samples,same files:
- Code: Select all
if (wt == wb+wp && wp >= 1) cflags[White] |= MatRookPawnFlag;
if (wt == wb+wp && wb <= 1 && wp >= 1 && bt > bp) cflags[White] |= MatBishopFlag;
if (wt == 2 && wn == 1 && wp == 1 && bt > bp) cflags[White] |= MatKnightFlag;
if (bt == bb+bp && bp >= 1) cflags[Black] |= MatRookPawnFlag;
if (bt == bb+bp && bb <= 1 && bp >= 1 && wt > wp) cflags[Black] |= MatBishopFlag;
if (bt == 2 && bn == 1 && bp == 1 && wt > wp) cflags[Black] |= MatKnightFlag;
if (recog == EG_KQKQ || recog == EG_KRKR) {
mul[White] = 0;
mul[Black] = 0;
}
if (bq >= 1 && bq+br+bb+bn >= 2) cflags[White] |= MatKingFlag;
if (wq >= 1 && wq+wr+wb+wn >= 2) cflags[Black] |= MatKingFlag;
int phase = TotalPhase;
phase -= wp * PiecePhase[PAWN];
phase -= wn * PiecePhase[KNIGHT];
phase -= wb * PiecePhase[BISHOP];
phase -= wr * PiecePhase[ROOK];
phase -= wq * PiecePhase[QUEEN];
phase -= bp * PiecePhase[PAWN];
phase -= bn * PiecePhase[KNIGHT];
phase -= bb * PiecePhase[BISHOP];
phase -= br * PiecePhase[ROOK];
phase -= bq * PiecePhase[QUEEN];
if(phase < 0) phase = 0;
phase = (phase * 256 + (TotalPhase / 2)) / TotalPhase;
int opening = 0, endgame = 0;
const int owf = wn*MAT[KNIGHT][Opening] + wb*MAT[BISHOP][Opening] + wr*MAT[ROOK][Opening] + wq*MAT[QUEEN][Opening];
opening += wp * MAT[PAWN][Opening];
opening += owf;
const int obf = bn*MAT[KNIGHT][Opening] + bb*MAT[BISHOP][Opening] + br*MAT[ROOK][Opening] + bq*MAT[QUEEN][Opening];
opening -= bp * MAT[PAWN][Opening];
opening -= obf;
const int ewf = wn*MAT[KNIGHT][Endgame] + wb*MAT[BISHOP][Endgame] + wr*MAT[ROOK][Endgame] + wq*MAT[QUEEN][Endgame];
endgame += wp * MAT[PAWN][Endgame];
endgame += ewf;
const int ebf = bn*MAT[KNIGHT][Endgame] + bb*MAT[BISHOP][Endgame] + br*MAT[ROOK][Endgame] + bq*MAT[QUEEN][Endgame];
endgame -= bp * MAT[PAWN][Endgame];
endgame -= ebf;
fruit 2.1:
- Code: Select all
// potential draw for white
if (wt == wb+wp && wp >= 1) cflags[White] |= MatRookPawnFlag;
if (wt == wb+wp && wb <= 1 && wp >= 1 && bt > bp) cflags[White] |= MatBishopFlag;
if (wt == 2 && wn == 1 && wp == 1 && bt > bp) cflags[White] |= MatKnightFlag;
// potential draw for black
if (bt == bb+bp && bp >= 1) cflags[Black] |= MatRookPawnFlag;
if (bt == bb+bp && bb <= 1 && bp >= 1 && wt > wp) cflags[Black] |= MatBishopFlag;
if (bt == 2 && bn == 1 && bp == 1 && wt > wp) cflags[Black] |= MatKnightFlag;
// draw leaf (likely draw)
if (recog == MAT_KQKQ || recog == MAT_KRKR) {
mul[White] = 0;
mul[Black] = 0;
}
// king safety
if (bq >= 1 && bq+br+bb+bn >= 2) cflags[White] |= MatKingFlag;
if (wq >= 1 && wq+wr+wb+wn >= 2) cflags[Black] |= MatKingFlag;
// phase (0: opening -> 256: endgame)
phase = TotalPhase;
phase -= wp * PawnPhase;
phase -= wn * KnightPhase;
phase -= wb * BishopPhase;
phase -= wr * RookPhase;
phase -= wq * QueenPhase;
phase -= bp * PawnPhase;
phase -= bn * KnightPhase;
phase -= bb * BishopPhase;
phase -= br * RookPhase;
phase -= bq * QueenPhase;
if (phase < 0) phase = 0;
ASSERT(phase>=0&&phase<=TotalPhase);
phase = (phase * 256 + (TotalPhase / 2)) / TotalPhase;
ASSERT(phase>=0&&phase<=256);
// material
opening = 0;
endgame = 0;
opening += wp * PawnOpening;
opening += wn * KnightOpening;
opening += wb * BishopOpening;
opening += wr * RookOpening;
opening += wq * QueenOpening;
opening -= bp * PawnOpening;
opening -= bn * KnightOpening;
opening -= bb * BishopOpening;
opening -= br * RookOpening;
opening -= bq * QueenOpening;
endgame += wp * PawnEndgame;
endgame += wn * KnightEndgame;
endgame += wb * BishopEndgame;
endgame += wr * RookEndgame;
endgame += wq * QueenEndgame;
endgame -= bp * PawnEndgame;
endgame -= bn * KnightEndgame;
endgame -= bb * BishopEndgame;
endgame -= br * RookEndgame;
endgame -= bq * QueenEndgame;
the owf obf,ebf ,ewf calculations were introduced in toga iirc.
not that it matters.