Code: Select all
int EvalWhiteKnight(const S_BOARD *pos)
{
int pceNum;
int index;
int sq;
int tempSq;
int score=0;
//loop through all the knights
for(pceNum = 0; pceNum < pos->pceNum[wN]; ++pceNum) {
sq = pos->pList[wN][pceNum];
//knight mobility
//loops through all the knight moves for the given knight
for(index = 0; index < 8; ++index) {
tempSq = sq + KnDir[index];
if(SqOnBoard(tempSq)) {
//bonus if the piece controls one of the center squares
if(tempSq == D4 || tempSq == D5 || tempSq==E4 || tempSq==E5)
{
score += knightCenterControl;
}
//if the move is controlled by an enemy pawn, ignore the move
if(pos->pieces[tempSq+11] != bP && pos->pieces[tempSq+9] != bP)
//otherwise add mobility score to the knight
score += knightMobility;
}
}
//undefended minor piece penalty
if(!SqAttacked(sq,WHITE,pos))
score += undefendedMinor;
//knight outpost using bitmasks
//the knight needs to be in the enemy half of the board
if(RanksBrd[sq]>RANK_4)
{
//no opposing black pawns to push the knight away, and the knight is supported by a white pawn
if((pos->pawns[BLACK] & WhiteOutpostMask[SQ64(sq)])==0 &&
(pos->pieces[sq-9]==wP || pos->pieces[sq-11]==wP))
{
//add bonus to this knight for having an outpost
score += outpost;
}
}
}
return score;
}
Code: Select all
int EvalWhiteBishop(const S_BOARD *pos)
{
int pceNum;
int sq;
int index;
int t_sq;
int score=0;
//loop through all the white bishops
for(pceNum = 0; pceNum < pos->pceNum[wB]; ++pceNum) {
sq = pos->pList[wB][pceNum];
//loop through all the bishop move directions
for(index = 0; index < 4; ++index) {
int dir = BiDir[index];
t_sq = sq + dir;
//loop through all the moves in each direction
while(SqOnBoard(t_sq)) {
//if the bishop is controlling the center, add bonus
if(t_sq == D4 || t_sq == D5 || t_sq==E4 || t_sq==E5)
{
score += bishopCenterControl;
}
//if the bishop is behind a black pawn chain, stop going through this direction
if(pos->pieces[t_sq]==bP)
{
if(pos->pieces[t_sq+11] == bP || pos->pieces[t_sq+9] == bP) {
break;
}
}
//similarly to white pawn chains
if(pos->pieces[t_sq]==wP)
{
if(pos->pieces[t_sq-11] == wP || pos->pieces[t_sq-9] == wP) {
break;
}
}
t_sq += dir;
//add mobility score to the bishop
score += bishopMobility;
}
}
}
//bishop pair
if(pos->pceNum[wB]>1)
score += BishopPair;
return score;
}