?? eval.c
字號:
/* Bishop defended by own pawn */
if (MoveArray[ptype[xside]][sq] & board.b[side][pawn])
s1 += OUTPOSTBISHOP;
}
/* Fianchetto bishop */
if (side == white)
{
if (board.king[side] >= F1 && board.king[side] <= H1 && sq == G2)
s1 += FIANCHETTO;
if (board.king[side] >= A1 && board.king[side] <= C1 && sq == B2)
s1 += FIANCHETTO;
}
else if (side == black)
{
if (board.king[side] >= F8 && board.king[side] <= H8 && sq == G7)
s1 += FIANCHETTO;
if (board.king[side] >= A8 && board.king[side] <= C8 && sq == B7)
s1 += FIANCHETTO;
}
/* Attack on weak opponent pawns */
if (BishopAttack(sq) & weaked[xside])
s1 += ATAKWEAKPAWN;
s += s1;
}
/* Doubled bishops */
if (n > 1)
s += DOUBLEDBISHOPS;
return (s);
}
int BishopTrapped (short side)
/****************************************************************************
*
* Check for bishops trapped at A2/H2/A7/H7
*
****************************************************************************/
{
int s = 0;
/* Don't waste time */
if (board.b[side][bishop] == NULLBITBOARD)
return (0);
if (side == white)
{
if ((board.b[white][bishop] & BitPosArray[A7]) &&
(board.b[black][pawn] & BitPosArray[B6]) && SwapOff(MOVE(A7,B6)) < 0)
s += BISHOPTRAPPED;
if ((board.b[white][bishop] & BitPosArray[H7]) &&
(board.b[black][pawn] & BitPosArray[G6]) && SwapOff(MOVE(H7,G6)) < 0)
s += BISHOPTRAPPED;
}
else
{
if ((board.b[black][bishop] & BitPosArray[A2]) &&
(board.b[white][pawn] & BitPosArray[B3]) && SwapOff(MOVE(A2,B3)) < 0)
s += BISHOPTRAPPED;
if ((board.b[black][bishop] & BitPosArray[H2]) &&
(board.b[white][pawn] & BitPosArray[G3]) && SwapOff(MOVE(H2,G3)) < 0)
s += BISHOPTRAPPED;
}
return (s);
}
int ScoreR (short side)
/****************************************************************************
*
* 1. rook on 7th rank and Enemy king on 8th rank or pawns on 7th rank.
* 2. rook on open/half-open file.
* 3. rook in front/behind passed pawns (pawn >= 5th rank)
*
****************************************************************************/
{
int s, s1, sq, xside, fyle, EnemyKing;
BitBoard c;
if (board.b[side][rook] == NULLBITBOARD)
return (0);
s = s1 = 0;
c = board.b[side][rook];
xside = side ^ 1;
EnemyKing = board.king[xside];
if ( c & pinned )
{
s += PINNEDROOK * nbits(c & pinned);
}
while (c)
{
sq = leadz (c);
CLEARBIT (c, sq);
/* Control */
s1 = CTL(sq,rook,side);
fyle = ROW(sq);
if (PHASE < 7)
{
if (!(board.b[side][pawn] & FileBit[fyle]))
{
if (fyle == 5 && ROW(board.king[xside])>=E_FILE)
s1 += ROOKLIBERATED;
s1 += ROOKHALFFILE;
if (!(board.b[xside][pawn] & FileBit[fyle]))
s1 += ROOKOPENFILE;
}
}
if (phase > 6 && (FileBit[fyle] & passed[white] & brank58[white]))
{
if (nbits (Ray[sq][7] & passed[white]) == 1)
s1 += ROOKBEHINDPP;
else if (Ray[sq][4] & passed[white])
s1 += ROOKINFRONTPP;
}
if (FileBit[fyle] & passed[black] & brank58[black])
{
if (nbits (Ray[sq][4] & passed[black]) == 1)
s1 += ROOKBEHINDPP;
else if (Ray[sq][7] & passed[black])
s1 += ROOKINFRONTPP;
}
/* Attack on weak opponent pawns */
if (RookAttack(sq) & weaked[xside])
s1 += ATAKWEAKPAWN;
/* Rook on 7th rank */
if (RANK (sq) == rank7[side] && (RANK (EnemyKing) == rank8[side] ||
board.b[xside][pawn] & RankBit[RANK(sq)]))
s1 += ROOK7RANK;
s += s1;
}
return (s);
}
int DoubleQR7 (short side)
/***************************************************************************
*
* This code just check to see if there is a QQ or QR or RR combo on the
* 7th rank. This is very strong and given quite a big bonus. This
* routine is called by the lazy section.
*
***************************************************************************/
{
int xside;
xside = 1^side;
if (nbits ((board.b[side][queen]|board.b[side][rook]) & brank7[side]) > 1
&& ((board.b[xside][king] & brank8[side]) ||
(board.b[xside][pawn] & brank7[side])))
return (ROOKS7RANK);
else
return (0);
}
int ScoreQ (short side)
/***************************************************************************
*
* 1. queen centralization.
* 2. king tropism.
* 3. Bonus if opponent king is exposed.
*
***************************************************************************/
{
int xside;
int s, s1, sq, EnemyKing;
BitBoard c;
s = s1 = 0;
/* Try to keep our queen on the board for attacking purposes. */
if (board.b[side][queen] == NULLBITBOARD) {
if (side == computer) {
s += QUEEN_NOT_PRESENT;
}
return(s);
}
xside = 1 ^ side;
c = board.b[side][queen];
EnemyKing = board.king[xside];
if ( c & pinned )
{
s += PINNEDQUEEN * nbits(c & pinned);
}
while (c)
{
sq = leadz (c);
CLEARBIT (c, sq);
/* Control */
s1 = CTL(sq,queen,side);
if (distance[sq][EnemyKing] <= 2)
s1 += QUEENNEARKING;
/* Attack on weak opponent pawns */
if (QueenAttack(sq) & weaked[xside])
s1 += ATAKWEAKPAWN;
s += s1;
}
return (s);
}
static const int KingSq[64] =
{
24, 24, 24, 16, 16, 0, 32, 32,
24, 20, 16, 12, 12, 16, 20, 24,
16, 12, 8, 4, 4, 8, 12, 16,
12, 8, 4, 0, 0, 4, 8, 12,
12, 8, 4, 0, 0, 4, 8, 12,
16, 12, 8, 4, 4, 8, 12, 16,
24, 20, 16, 12, 12, 16, 20, 24,
24, 24, 24, 16, 16, 0, 32, 32
};
static const int EndingKing[64] =
{
0, 6, 12, 18, 18, 12, 6, 0,
6, 12, 18, 24, 24, 18, 12, 6,
12, 18, 24, 32, 32, 24, 18, 12,
18, 24, 32, 48, 48, 32, 24, 18,
18, 24, 32, 48, 48, 32, 24, 18,
12, 18, 24, 32, 32, 24, 18, 12,
6, 12, 18, 24, 24, 18, 12, 6,
0, 6, 12, 18, 18, 12, 6, 0
};
static const int pawncover[9] = { -60, -30, 0, 5, 30, 30, 30, 30, 30 };
static const int factor[9] = { 7, 8, 8, 7, 6, 5, 4, 2, 0, };
int ScoreK (short side)
/***************************************************************************
*
* 1. king in the corner. ?? SRW 2002-08-02 Unclear if implemented
* 2. pawns around king.
* 3. king on open file.
* 4. Uncastled king.
* 5. Open rook file via Ng5 or Bxh7 sac.
* 6. No major or minor piece in the king's quadrant.
*
***************************************************************************/
{
int xside;
int s, sq, sq1, n, n1, n2, file, fsq, rank;
BitBoard b, x;
s = 0;
xside = 1^side;
sq = board.king[side];
file = ROW (sq);
rank = RANK (sq);
KingSafety[side] = 0;
if (!ENDING)
{
s += ((6 - phase) * KingSq[sq] + phase * EndingKing[sq]) / 6;
/* After castling kingside, reward having all 3 pawns in front but not if
there is a threatening pawn. This permits the freeing move F3/F6. */
if (side == white)
n = nbits (MoveArray[king][sq] & board.b[side][pawn] & RankBit[rank+1]);
else
n = nbits (MoveArray[king][sq] & board.b[side][pawn] & RankBit[rank-1]);
s += pawncover[n];
/* Penalize compromised wing pawn formations prior to castle. */
if (!board.castled[side]) {
n = -1;
if (side == white) {
/* King on original square and unmoved */
if (sq == 4 && Mvboard[sq] == 0) {
/* Kingside - rook on original square and unmoved. */
if ( (board.b[side][rook] & BitPosArray[H1])!=NULLBITBOARD &&
Mvboard[H1] == 0)
n = nbits (MoveArray[king][G1] &
board.b[side][pawn] & RankBit[rank+1]);
/* Queenside */
if ( (board.b[side][rook] & BitPosArray[A1])!=NULLBITBOARD &&
Mvboard[A1] == 0)
n = nbits (MoveArray[king][C1] &
board.b[side][pawn] & RankBit[rank+1]);
}
} else {
if (sq == 60 && Mvboard[sq] == 0) {
/* Kingside */
if ( (board.b[side][rook] & BitPosArray[H8])!=NULLBITBOARD &&
Mvboard[H8] == 0)
n = nbits (MoveArray[king][G8] &
board.b[side][pawn] & RankBit[rank-1]);
/* Queenside */
if ( (board.b[side][rook] & BitPosArray[A8])!=NULLBITBOARD &&
Mvboard[A8] == 0)
n = nbits (MoveArray[king][C8] &
board.b[side][pawn] & RankBit[rank-1]);
}
}
/* Penalize breaking the wing pawn formations prior to castle */
if (n != -1) s += pawncover[n];
}
if (side == computer && file >= F_FILE &&
!(FileBit[G_FILE] & board.b[side][pawn]))
{
if (side == white && cboard[F2] == pawn)
s += GOPEN;
else if (side == black && cboard[F7] == pawn)
s += GOPEN;
}
/* No friendly pawns on this king file */
if (!(FileBit[file] & board.b[side][pawn]))
s += KINGOPENFILE;
/* No enemy pawns on this king file */
if (!(FileBit[file] & board.b[xside][pawn]))
s += KINGOPENFILE1;
switch (file)
{
case A_FILE :
case E_FILE :
case F_FILE :
case G_FILE : if (!(FileBit[file+1] & board.b[side][pawn]))
s += KINGOPENFILE;
if (!(FileBit[file+1] & board.b[xside][pawn]))
s += KINGOPENFILE1;
break;
case H_FILE :
case D_FILE :
case C_FILE :
case B_FILE : if (!(FileBit[file-1] & board.b[side][pawn]))
s += KINGOPENFILE;
if (!(FileBit[file-1] & board.b[xside][pawn]))
s += KINGOPENFILE1;
break;
default :
break;
}
if (board.castled[side]) {
if (side == white) {
if (file > E_FILE) {
if (!(BitPosArray[F2] & board.b[side][pawn]) ||
!(BitPosArray[G2] & board.b[side][pawn]) ||
!(BitPosArray[H2] & board.b[side][pawn]) )
s += RUPTURE;
} else if (file < E_FILE) {
if (!(BitPosArray[A2] & board.b[side][pawn]) ||
!(BitPosArray[B2] & board.b[side][pawn]) ||
!(BitPosArray[C2] & board.b[side][pawn]) )
s += RUPTURE;
}
} else {
if (file > E_FILE) {
if (!(BitPosArray[F7] & board.b[side][pawn]) ||
!(BitPosArray[G7] & board.b[side][pawn]) ||
!(BitPosArray[H7] & board.b[side][pawn]) )
s += RUPTURE;
} else if (file < E_FILE) {
if (!(BitPosArray[A7] & board.b[side][pawn]) ||
!(BitPosArray[B7] & board.b[side][pawn]) ||
!(BitPosArray[C7] & board.b[side][pawn]) )
s += RUPTURE;
}
}
}
if (side == computer) {
/* Stock piece sacrifice on h file */
if (file >= E_FILE && board.b[xside][queen] && board.b[xside][rook] &&
!((board.b[side][pawn]|board.b[xside][pawn]) & FileBit[7]))
s += HOPEN;
/* King trapping rook */
if (side == white) {
if (file > E_FILE) {
if (board.b[side][rook]&mask_kr_trapped_w[H_FILE-file]) {
s += ROOKTRAPPED;
}
} else if (file < D_FILE) {
if (board.b[side][rook]&mask_qr_trapped_w[file]) {
s += ROOKTRAPPED;
}
}
} else {
if (file > E_FILE) {
if (board.b[side][rook]&mask_kr_trapped_b[H_FILE-file]) {
s += ROOKTRAPPED;
}
} else if (file < D_FILE) {
if (board.b[side][rook]&mask_qr_trapped_b[file]) {
s += ROOKTRAPPED;
}
}
}
}
/* Don't give fianchetto target for advanced pawns */
if (file > E_FILE && ROW(board.king[xside]) < D_FILE) {
if (side == white) fsq = G3; else fsq = G6;
if ((BitPosArray[fsq] & board.b[side][pawn]) != NULLBITBOARD)
if (((BitPosArray[F4]|BitPosArray[H4]|
BitPosArray[F5]|BitPosArray[H5])
& board.b[xside][pawn]) != NULLBITBOARD)
s += FIANCHETTO_TARGET;
}
if (file < E_FILE && ROW(board.king[xside]) > E_FILE) {
if (side == white) fsq = B3; else fsq = B6;
if ((BitPosArray[fsq] & board.b[side][pawn]) != NULLBITBOARD)
if (((BitPosArray[A4]|BitPosArray[C4]|
BitPosArray[A5]|BitPosArray[C5])
& board.b[xside][pawn]) != NULLBITBOARD)
s += FIANCHETTO_TARGET;
}
/* No major/minor piece in king's quadrant */
/* First identify the quadrant */
x = boardhalf[side] & boardside[file<=D_FILE];
/* Now identify the number of non-pawn enemy in quadrant */
n1 = nbits(x & (board.friends[xside]));
if (n1 > 0) {
/* Now identify the number of non-pawn friends in quadrant */
n2 = nbits(x & (board.friends[side] & ~board.b[side][pawn] &
~board.b[side][king]));
if (n1 > n2)
s += (n1 - n2) * KING_DEFENDER_DEFICIT;
}
KingSafety[side] = s;
s = (s * factor[phase]) / 8;
}
else
{
s += EndingKing[sq];
s += CTL(sq,king,side);
b = (board.b[white][pawn] | board.b[black][pawn]);
while (b)
{
sq1 = leadz (b);
CLEARBIT (b, sq1);
if (BitPosArray[sq1] & board.b[white][pawn])
s -= distance[sq][sq1+8] * 10 - 5;
else if (BitPosArray[sq1] & board.b[white][pawn])
s -= distance[sq][sq1-8] * 10 - 5;
else
s -= distance[sq][sq1] - 5;
}
/* Attack on weak opponent pawns */
if (MoveArray[king][sq] & weaked[xside])
s += ATAKWEAKPAWN * 2;
}
if (phase >= 4) {
/* Weak back rank */
if (side == white) {
if (sq < A2)
if (!(MoveArray[king][sq] & (~board.b[side][pawn] & RankBit[1])))
s += KING_BACK_RANK_WEAK;
} else {
if (sq > H7)
if (!(MoveArray[king][sq] & (~board.b[side][pawn] & RankBit[6])))
s += KING_BACK_RANK_WEAK;
}
}
return (s);
}
int LoneKing (int side, int loser)
/**************************************************************************
*
* One side has a lonely king and the other has no pawns, but enough
* mating material. We give an additional bonus of 150 points for the
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -