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: 1760

PostPost subject: evaluate loose pieces    Posted: Sun Feb 26, 2012 5:20 am Reply to topic Reply with quote

One of the many eval components that was missing in my program. After several attempts, I eventually implemented this in the following simplistic way
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
      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
      uint64_t enemy_pieces = B->all[them] & ~B->b[them][Pawn];
      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 (a bit simplistic at the moment, at least it's fast)
      while (hanging) {
         unsigned sq = next_bit(&hanging), victim = B->piece_on[sq];
         e->op[us] += 5 + Material[Opening][victim]/32;
         e->eg[us] += 10 + Material[EndGame][victim]/32;
      }
   }
}

Just to clarify the code a little, B->st->attacks[color][piece] is a bitboard of squares attacked by (color,piece). For example B->st->attacks[Black][Knight] is the set of squares attacked by black knights. And B->st->attacks[color][NoPiece] is the set of squares attacked by any piece of color. The rest should hopefully be self-obvious.

So what I'm doing is basically:
1/ loose pawn = pawn that is not defended
2/ loose piece = piece that is not defended by a pawn, or piece that is attacked by a pawn (regardless of whether it's defended or not).
3/ hanging = loose + attacked

And the scoring function is very simplistic. There is a base score and a linear part proportional to the hanging piece (victim) value.

This approach seems rather stupid when I think about it, but in self-testing it scored almost +48 elo (1000 games) to my surprise. I suppose this kind of feature will never give a huge elo increase anyway, so a compromise has to be found between slowing down the eval and doing something intelligent but complex, and having an over simplistic fast code.

I wonder how others have done this, what they've tried, and with what kind of results.

Intuitively, my thought of hanging pieces is the following:
1/ the quiescent search will grab hanging pieces if it can. but it will choose a stand pat score when the side to move has pieces hanging. so if your opponent has a hanging piece and the quiescent search doesn't chose to take it, there's generally a good reason for it (losing SEE, checks involved, or other complications such as discovering new attacks etc.). However, even if the opponent hanging piece is SEE defended, or defended by other considerations (discovering other attacks etc.) it also means that in a way some opponent pieces are not free of movement and are tied to maintain these defensive tactics
2/ when you have only one hanging piece, it shouldn't be penalized too strongly, and the penalty should typically be the cost of a tempo (unless the piece is actually trapped and a tempo won't save it, but this would be hard to code in the eval in an efficient way).
3/ when you have several hanging pieces, there is no 100% rule nor even a 90% rule, but there are some significant chances that you'll end up losing one. Of course tactical complications such as forks, checks, passed pawn pushes can allow you to leave hanging pieces, so it's hard to know in the eval whether you're going to lose a piece or not.
4/ when you have many hanging pieces, the chances of being able to defend all of them by means of tactical threats becomes smaller and smaller. Perhaps I should start increasing the hanging piece penalty with the number of hanging pieces ?

Anyway, thoughts, suggestions welcome
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