private final int pieceSquareEval(Position pos){
  int score=0;
  final int wMtrl=pos.wMtrl;
  final int bMtrl=pos.bMtrl;
  final int wMtrlPawns=pos.wMtrlPawns;
  final int bMtrlPawns=pos.bMtrlPawns;
{
    final int t1=qV + 2 * rV + 2 * bV;
    final int t2=rV;
{
      final int k1=pos.psScore1[Piece.WKING];
      final int k2=pos.psScore2[Piece.WKING];
      final int t=bMtrl - bMtrlPawns;
      score+=interpolate(t,t2,k2,t1,k1);
    }
{
      final int k1=pos.psScore1[Piece.BKING];
      final int k2=pos.psScore2[Piece.BKING];
      final int t=wMtrl - wMtrlPawns;
      score-=interpolate(t,t2,k2,t1,k1);
    }
  }
{
    final int t1=qV + 2 * rV + 2 * bV;
    final int t2=rV;
    int wp1=pos.psScore1[Piece.WPAWN];
    int wp2=pos.psScore2[Piece.WPAWN];
    if ((wp1 != 0) || (wp2 != 0)) {
      final int tw=bMtrl - bMtrlPawns;
      score+=interpolate(tw,t2,wp2,t1,wp1);
    }
    int bp1=pos.psScore1[Piece.BPAWN];
    int bp2=pos.psScore2[Piece.BPAWN];
    if ((bp1 != 0) || (bp2 != 0)) {
      final int tb=wMtrl - wMtrlPawns;
      score-=interpolate(tb,t2,bp2,t1,bp1);
    }
  }
{
    final int t1=qV + 2 * rV + 1 * bV + 1 * nV + 6 * pV;
    final int t2=nV + 8 * pV;
    int n1=pos.psScore1[Piece.WKNIGHT];
    int n2=pos.psScore2[Piece.WKNIGHT];
    if ((n1 != 0) || (n2 != 0)) {
      score+=interpolate(bMtrl,t2,n2,t1,n1);
    }
    n1=pos.psScore1[Piece.BKNIGHT];
    n2=pos.psScore2[Piece.BKNIGHT];
    if ((n1 != 0) || (n2 != 0)) {
      score-=interpolate(wMtrl,t2,n2,t1,n1);
    }
  }
{
    score+=pos.psScore1[Piece.WBISHOP];
    score-=pos.psScore1[Piece.BBISHOP];
  }
{
    final long occupied=pos.whiteBB | pos.blackBB;
    score+=pos.psScore1[Piece.WQUEEN];
    long m=pos.pieceTypeBB[Piece.WQUEEN];
    while (m != 0) {
      int sq=BitBoard.numberOfTrailingZeros(m);
      long atk=BitBoard.rookAttacks(sq,occupied) | BitBoard.bishopAttacks(sq,occupied);
      wAttacksBB|=atk;
      score+=queenMobScore[Long.bitCount(atk & ~(pos.whiteBB | bPawnAttacks))];
      bKingAttacks+=Long.bitCount(atk & bKingZone) * 2;
      m&=m - 1;
    }
    score-=pos.psScore1[Piece.BQUEEN];
    m=pos.pieceTypeBB[Piece.BQUEEN];
    while (m != 0) {
      int sq=BitBoard.numberOfTrailingZeros(m);
      long atk=BitBoard.rookAttacks(sq,occupied) | BitBoard.bishopAttacks(sq,occupied);
      bAttacksBB|=atk;
      score-=queenMobScore[Long.bitCount(atk & ~(pos.blackBB | wPawnAttacks))];
      wKingAttacks+=Long.bitCount(atk & wKingZone) * 2;
      m&=m - 1;
    }
  }
{
    int r1=pos.psScore1[Piece.WROOK];
    if (r1 != 0) {
      final int nP=bMtrlPawns / pV;
      final int s=r1 * Math.min(nP,6) / 6;
      score+=s;
    }
    r1=pos.psScore1[Piece.BROOK];
    if (r1 != 0) {
      final int nP=wMtrlPawns / pV;
      final int s=r1 * Math.min(nP,6) / 6;
      score-=s;
    }
  }
  return score;
}

private final int pieceSquareEval ( Position pos ) { int score = 0 ; final int wMtrl = pos . wMtrl ; final int bMtrl = pos . bMtrl ; final int wMtrlPawns = pos . wMtrlPawns ; final int bMtrlPawns = pos . bMtrlPawns ; { final int t1 = qV + 2 * rV + 2 * bV ; final int t2 = rV ; { final int k1 = pos . psScore1 [ Piece . WKING ] ; final int k2 = pos . psScore2 [ Piece . WKING ] ; final int t = bMtrl - bMtrlPawns ; score += interpolate ( t , t2 , k2 , t1 , k1 ) ; } { final int k1 = pos . psScore1 [ Piece . BKING ] ; final int k2 = pos . psScore2 [ Piece . BKING ] ; final int t = wMtrl - wMtrlPawns ; score -= interpolate ( t , t2 , k2 , t1 , k1 ) ; } } { final int t1 = qV + 2 * rV + 2 * bV ; final int t2 = rV ; int wp1 = pos . psScore1 [ Piece . WPAWN ] ; int wp2 = pos . psScore2 [ Piece . WPAWN ] ; if ( ( wp1 != 0 ) || ( wp2 != 0 ) ) { final int tw = bMtrl - bMtrlPawns ; score += interpolate ( tw , t2 , wp2 , t1 , wp1 ) ; } int bp1 = pos . psScore1 [ Piece . BPAWN ] ; int bp2 = pos . psScore2 [ Piece . BPAWN ] ; if ( ( bp1 != 0 ) || ( bp2 != 0 ) ) { final int tb = wMtrl - wMtrlPawns ; score -= interpolate ( tb , t2 , bp2 , t1 , bp1 ) ; } } { final int t1 = qV + 2 * rV + 1 * bV + 1 * nV + 6 * pV ; final int t2 = nV + 8 * pV ; int n1 = pos . psScore1 [ Piece . WKNIGHT ] ; int n2 = pos . psScore2 [ Piece . WKNIGHT ] ; if ( ( n1 != 0 ) || ( n2 != 0 ) ) { score += interpolate ( bMtrl , t2 , n2 , t1 , n1 ) ; } n1 = pos . psScore1 [ Piece . BKNIGHT ] ; n2 = pos . psScore2 [ Piece . BKNIGHT ] ; if ( ( n1 != 0 ) || ( n2 != 0 ) ) { score -= interpolate ( wMtrl , t2 , n2 , t1 , n1 ) ; } } { score += pos . psScore1 [ Piece . WBISHOP ] ; score -= pos . psScore1 [ Piece . BBISHOP ] ; } { final long occupied = pos . whiteBB | pos . blackBB ; score += pos . psScore1 [ Piece . WQUEEN ] ; long m = pos . pieceTypeBB [ Piece . WQUEEN ] ; while ( m != 0 ) { int sq = BitBoard . numberOfTrailingZeros ( m ) ; long atk = BitBoard . rookAttacks ( sq , occupied ) | BitBoard . bishopAttacks ( sq , occupied ) ; wAttacksBB |= atk ; score += queenMobScore [ Long . bitCount ( atk & ~ ( pos . whiteBB | bPawnAttacks ) ) ] ; bKingAttacks += Long . bitCount ( atk & bKingZone ) * 2 ; m &= m - 1 ; } score -= pos . psScore1 [ Piece . BQUEEN ] ; m = pos . pieceTypeBB [ Piece . BQUEEN ] ; while ( m != 0 ) { int sq = BitBoard . numberOfTrailingZeros ( m ) ; long atk = BitBoard . rookAttacks ( sq , occupied ) | BitBoard . bishopAttacks ( sq , occupied ) ; bAttacksBB |= atk ; score -= queenMobScore [ Long . bitCount ( atk & ~ ( pos . blackBB | wPawnAttacks ) ) ] ; wKingAttacks += Long . bitCount ( atk & wKingZone ) * 2 ; m &= m - 1 ; } } { int r1 = pos . psScore1 [ Piece . WROOK ] ; if ( r1 != 0 ) { final int nP = bMtrlPawns / pV ; final int s = r1 * Math . min ( nP , 6 ) / 6 ; score += s ; } r1 = pos . psScore1 [ Piece . BROOK ] ; if ( r1 != 0 ) { final int nP = wMtrlPawns / pV ; final int s = r1 * Math . min ( nP , 6 ) / 6 ; score -= s ; } } return score ; }
compute score based on piece square tables . positive values are good for white .
