ChessUSA.com TalkChess.com
Hosted by Your Move Chess & Games
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

evaluate loose pieces
Post new topic    TalkChess.com Forum Index -> Computer Chess Club: Programming and Technical Discussions Flat
View previous topic :: View next topic  
Author Message
Lucas Braesch



Joined: 31 May 2010
Posts: 1756

PostPost subject: Re: evaluate loose pieces    Posted: Mon Feb 27, 2012 1:40 pm Reply to topic Reply with quote

mcostalba wrote:
Eelco de Groot wrote:

I think the change you propose is not really what Lucas means with "loose pieces" the usual term,


I have looked at his code, not how it is called.

Eelco de Groot wrote:

My own version of that code in Stockfish is a bit experimental and not very streamlined code


Your code is too complicated to work Wink

You are attacking 3 concepts (loose pieces, passed pawns and king attacks) in a single piece of code: it doesn't work like this. I'd suggest a more orthogonal approach, one different function for each concept. A possible implementation of your idea that seems an acceptable compromise between speed and accuracy could be:

Code:

  template<Color Us>
  Score evaluate_threats(const Position& pos, EvalInfo& ei) {

    const Color Them = (Us == WHITE ? BLACK : WHITE);

    Bitboard b, bb;
    Score score = SCORE_ZERO;

    // Enemy pieces not defended by a pawn and under our attack
    Bitboard weakEnemies =  pos.pieces(Them)
                          & ~ei.attackedBy[Them][PAWN]
                          & ei.attackedBy[Us][0];
    if (!weakEnemies)
        return SCORE_ZERO;

    Bitboard undefended = weakEnemies & ~ei.attackedBy[Them][0];

    // Add bonus according to type of attacked enemy piece and to the
    // type of attacking piece, from knights to queens. Kings are not
    // considered because are already handled in king evaluation.
    for (PieceType pt1 = KNIGHT; pt1 < KING; pt1++)
    {
        b = ei.attackedBy[Us][pt1] & weakEnemies;
        if (b)
            for (PieceType pt2 = PAWN; pt2 < KING; pt2++)
                if (bb = b & pos.pieces(pt2), bb)
                    score += bb & undefended ? 2 * ThreatBonus[pt1][pt2]
                                             : 1 * ThreatBonus[pt1][pt2];
    }
    return score;
  }

I think I've found another compromise that (in my testing) performs better. The idea is to make the bonus non linear, in the same logic as king safety. After all the reason why these bonus for attacking hanging pieces are small, are because the hanging pieces can be defended and it's hard to know whether we'll end up losing a piece or not. But one thing is sure, the more undefended hanging pieces, the more probability we won't be able to defend all of them.
Code:
static void eval_loose(const Board *B, eval_t *e)
// detect loose pieces and attribute small bonuses for attacking them
{
   assert(B->initialized && e);

   for (unsigned color = White; color <= Black; color++) {
      const unsigned us = color, them = opp_color(us);
      
      // loose pawns = undefended pawns
      const uint64_t loose_pawns = B->b[them][Pawn] & ~B->st->attacks[them][NoPiece];
      
      // loose pieces = pieces either attacked by a pawn or not defended by a pawn
      const uint64_t enemy_pieces = B->all[them] & ~B->b[them][Pawn];
      const uint64_t loose_pieces = enemy_pieces & (~B->st->attacks[them][Pawn] | B->st->attacks[us][Pawn]);
      
      // hanging = loose and attacked
      uint64_t hanging = (loose_pawns | loose_pieces) & B->st->attacks[us][NoPiece];
      
      // scoring (non linear)
      unsigned weighted_bonus[NB_PHASE] = {0, 0}, risk = 1;
      while (hanging) {
         const unsigned sq = next_bit(&hanging), victim = B->piece_on[sq];
         weighted_bonus[Opening] += 5 + Material[Opening][victim]/32;
         weighted_bonus[EndGame] += 10 + Material[EndGame][victim]/32;
         if (!test_bit(B->st->attacks[them][NoPiece], sq))
            risk++;
      }
      e->op[us] += weighted_bonus[Opening] * risk;
      e->eg[us] += weighted_bonus[EndGame] * risk;
   }
}

You might want to try something like this in SF, although you'll need to modify it somehow as SF separates clearly the case of pawn attacks from the rest (I mix it all together here)
Back to top
View user's profile Send private message
Display posts from previous:   
Subject Author Date/Time
evaluate loose pieces Lucas Braesch Sun Feb 26, 2012 5:20 am
      Re: evaluate loose pieces Larry Kaufman Sun Feb 26, 2012 3:57 pm
            Re: evaluate loose pieces Lucas Braesch Sun Feb 26, 2012 4:11 pm
                  Re: evaluate loose pieces Eelco de Groot Sun Feb 26, 2012 5:57 pm
                        Re: evaluate loose pieces Michael Hoffmann Sun Feb 26, 2012 6:53 pm
                        Re: evaluate loose pieces Marco Costalba Sun Feb 26, 2012 7:04 pm
                              Re: evaluate loose pieces Eelco de Groot Mon Feb 27, 2012 12:46 am
                                    Re: evaluate loose pieces Marco Costalba Mon Feb 27, 2012 7:17 am
                                          Re: evaluate loose pieces Lucas Braesch Mon Feb 27, 2012 10:20 am
                                                Re: evaluate loose pieces Sam Hamilton Mon Feb 27, 2012 10:23 am
                                          Re: evaluate loose pieces Lucas Braesch Mon Feb 27, 2012 1:40 pm
                                                Re: evaluate loose pieces Evert Glebbeek Mon Feb 27, 2012 2:34 pm
                                          Re: evaluate loose pieces Marek Kwiatkowski Mon Feb 27, 2012 2:58 pm
                                          Re: evaluate loose pieces Eelco de Groot Mon Feb 27, 2012 9:45 pm
                                          Re: evaluate loose pieces Gary Tue Feb 28, 2012 1:35 pm
                                                Re: evaluate loose pieces Marek Kwiatkowski Tue Feb 28, 2012 2:35 pm
                                                      Re: evaluate loose pieces Joona Kiiski Tue Feb 28, 2012 4:04 pm
                                                            Re: evaluate loose pieces Marek Kwiatkowski Tue Feb 28, 2012 5:57 pm
                                                            Re: evaluate loose pieces Eelco de Groot Fri May 25, 2012 11:36 pm
                                                      Re: evaluate loose pieces Gary Tue Feb 28, 2012 4:04 pm
                              Re: evaluate loose pieces Lucas Braesch Mon Feb 27, 2012 3:57 am
                        Re: evaluate loose pieces Sam Hamilton Sun Feb 26, 2012 7:12 pm
            Re: evaluate loose pieces Miguel A. Ballicora Sun Feb 26, 2012 5:11 pm
                  Re: evaluate loose pieces Larry Kaufman Sun Feb 26, 2012 5:20 pm
                        Re: evaluate loose pieces Sam Hamilton Sun Feb 26, 2012 6:50 pm
                              Re: evaluate loose pieces Lucas Braesch Mon Feb 27, 2012 3:59 am
                                    Re: evaluate loose pieces Sam Hamilton Mon Feb 27, 2012 4:28 am
                  Re: evaluate loose pieces Ed Schroder Mon Feb 27, 2012 11:42 am
            Re: evaluate loose pieces Gerd Isenberg Sun Feb 26, 2012 7:56 pm
Post new topic    TalkChess.com Forum Index -> Computer Chess Club: Programming and Technical Discussions

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




Powered by phpBB © 2001, 2005 phpBB Group
Enhanced with Moby Threads