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
Eelco de Groot



Joined: 12 Mar 2006
Posts: 2595
Location: Groningen

PostPost subject: Re: evaluate loose pieces    Posted: Mon Feb 27, 2012 12:46 am Reply to topic Reply with quote

mcostalba wrote:
Here is the code in SF:


Hi Marco,

I think the change you propose is not really what Lucas means with "loose pieces" the usual term, I don't use it myself much though, is as Gerd says "hanging pieces" The definition on Wikipedia for hanging pieces, hanging pawns are another matter, from http://en.wikipedia.org/wiki/Glossary_of_chess

Quote:
Hanging
Unprotected and exposed to capture. It is not the same as en prise since a piece en prise may be protected. To "hang a piece" is to lose it by failing to move or protect it


So if a pice is not defended by a pawn and there is already a bonus given for attacking it, the extra effort to see if there are non-pawn material defenders is not so great anymore, and in that case the piece really is "hanging". My own version of that code in Stockfish is a bit experimental and not very streamlined code (if the indents are wrong; I tried to fix them for about forty minutes, it probably has to do with original Stockfish code made in Unix and modified under Windows and some conflicting line endings still there):

Code:


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

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

    Bitboard b;
    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;

    // Add bonus according to type of attacked enemy piece [pt2] and to the
    // type of attacking piece [pt1], from knights to queens. Kings are not
    // considered under pt2 because that is 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++)
            {
                Bitboard bb = b & pos.pieces(pt2);
                if (bb)
                {
                   score += ThreatBonus[pt1][pt2];
                   do { // Is the piece undefended?
                         Square s = pop_1st_bit(&bb);
                         if (!(ei.attackedBy[Them][0] & s))
                         {
                            score += ThreatBonus[pt1][pt2];
                            if (pt2 == PAWN && (!pos.square_is_empty(s + pawn_push(Them)) || (ei.attackedBy[Us][0] & s + pawn_push(Them))))
                            {
                               score += make_score(5, 10);
                               // Nearing a pawn ending and the pawn may become a candidate pawn or a passed pawn?
                               File f = file_of(s);
                               if (ei.pi->file_is_half_open(Us, f) && !pos.non_pawn_material(Them))
                                   score += make_score(0, 2*relative_rank(Them, s));
                            }
                          }
                          // Does the piece attack our king?
                          if ((ei.kingAttackersBB[Us] & s))
                              score += make_score(25, 0);
                   } while (bb);
                }
             }
    }
    return score;
  }

Some of the extra bonuses introduced are just small and may not make much of a difference.

Eelco
_________________
Debugging is twice as hard as writing the code in the first
place. Therefore, if you write the code as cleverly as possible, you
are, by definition, not smart enough to debug it.
-- Brian W. Kernighan
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