pawn attacks in mobility

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

outAtime
Posts: 226
Joined: Sun Mar 08, 2009 3:08 pm
Location: Canada

pawn attacks in mobility

Post by outAtime »

Hi, Ive been trying to get mobility to stop counting squares which are attacked by opponent pawns as mobile. This code seems to work but Im wondering if it cant be improved or if someone can spot a bug somewhere. Im not sure how many games I would need to run to tell if this is an improvement or not, what type of gain should be expected by not counting squares attacked by opp pawns in mobility? Thanks.

Code: Select all

int rook_mobility_white(int sq, int offsets[])
{
  int p, *d = offsets, s = 0;
  
 do {
        for (p = sq + *d; board[p] == npiece && !pawn_attack(board[p], 0); p += *d)
            s++;
  } while (*++d);

  if ((board[p] & 1) == 1) 
      s++;	   
	   		   
  return s;		    
}
where pawn_attack is in move generation..

Code: Select all

bool pawn_attack(int square, int color) {

	/* this function will return TRUE if square "square" is attacked by a pawn
	 of color "color", and return FALSE otherwise */

	int bishop_o[4] = { 11, -11, 13, -13 };
	int a_sq, i;

	/* white pawn attacks: */
	if (color % 2) {
		
		/* pawn-style moves: */
		for &#40;i = 0; i < 4; i++) &#123;
			a_sq = square + bishop_o&#91;i&#93;;
			/* check for pawn attacks&#58; */
			if &#40;board&#91;a_sq&#93; == wpawn && i % 2&#41;
				return TRUE;
			while &#40;board&#91;a_sq&#93; != frame&#41; &#123;				
				if &#40;board&#91;a_sq&#93; != npiece&#41;
					break;
				a_sq += bishop_o&#91;i&#93;;
			&#125;
		&#125;

		/* if we haven't hit a white attacker by now, there are none&#58; */
		return FALSE;

	&#125;

	/* black pawn attacks&#58; */
	else &#123;
		
		/* pawn-style moves&#58; */
		for &#40;i = 0; i < 4; i++) &#123;
			a_sq = square + bishop_o&#91;i&#93;;
			/* check for pawn attacks&#58; */
			if &#40;board&#91;a_sq&#93; == bpawn && !&#40;i % 2&#41;)
				return TRUE;
			while &#40;board&#91;a_sq&#93; != frame&#41; &#123;				
				if &#40;board&#91;a_sq&#93; != npiece&#41;
					break;
				a_sq += bishop_o&#91;i&#93;;
			&#125;
		&#125;

		/* if we haven't hit a black attacker by now, there are none&#58; */
		return FALSE;

	&#125;

&#125;
I'm thinking it could be ok, but maybe there is something im not doing right?
outAtime
outAtime
Posts: 226
Joined: Sun Mar 08, 2009 3:08 pm
Location: Canada

Re: pawn attacks in mobility

Post by outAtime »

I guess i shouldn't count protected pawns either..
outAtime
User avatar
hgm
Posts: 27796
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: pawn attacks in mobility

Post by hgm »

I often wondered if it would hurt not to count captures at all. (Mainly because it made incremental update of mobility more difficult.)

Captures are more often bad than not. If they were good, they would already have been made earlier, or the position is not quiet now. If they are bad, they'd better not count as mobility. So only equal captures could be a useful asset.
Aleks Peshkov
Posts: 892
Joined: Sun Nov 19, 2006 9:16 pm
Location: Russia

Re: pawn attacks in mobility

Post by Aleks Peshkov »

NxB and BxN captures are unique as they are asymmetrical, but still equal.
outAtime
Posts: 226
Joined: Sun Mar 08, 2009 3:08 pm
Location: Canada

Re: pawn attacks in mobility

Post by outAtime »

I think i saw somewhere an idea where different attacks (captures) were given more weight than others in mobility according to piece type and also the type of piece attacked. It seems to make some sense logically to give different bonuses in this way, but I can't see where counting only empty squares in mobility could be an advantage (although your thought does make some sense, maybe it could). As far as I can see, Gull does something with bishops during mobility that other pieces do not along these lines...

Code: Select all

choose_popcnt<HPopCnt>((~Board->bb&#91;Black&#93;) & att & BishopMajorBlack&#41; * BishopMobMajor + BishopMobMinor&#91;choose_popcnt<HPopCnt>&#40;free & att&#41;&#93;;
so from what I can gather, this takes all unoccupied squares(regardless of if it is a square attacked by opponent pawn) and attacked opponent pieces in a 32 square forward area:

Code: Select all

01111110
11111111
11111111
01111110
00111100
00000000
00000000
00000000 
and multiplies this by 4. Then to this is added again all unoccupied squares but this time subtracting squares attacked by opponent pawns. also counting again the same attacked opponent pieces and multiplying this score by roughly (-2) * 3. It seems to me very complicated but again I wonder why it could possibly be such an advantage when all other pieces calculate just once attacks and unoccupied squares (-) squares attacked by opp pawns. Like you say, since most captures appear to be bad (are they?) it would seem important to not count these squares protected by pawns since it would almost always be bad to make the move. Or, Im currently thinking maybe its best to just count all possible moves, so only not counting squares occupied by friendly pieces. Here again some strong programs also count these squares!! ( i think if the piece is not a pawn) :)
outAtime
outAtime
Posts: 226
Joined: Sun Mar 08, 2009 3:08 pm
Location: Canada

Re: pawn attacks in mobility

Post by outAtime »

What is so special about Bishop attacks? Surely I have seen examples of a well posted knight which cannot be driven away, yet attacks nothing therefore having little function (value). Maybe only including unoccupied squares in the mobility scores does not do enough to guarantee the piece is not just "shooting at air" and given a high score for it. I like the idea of rewarding a piece for attacking(pressurizing) opponents position and maybe decreasing the other part for empty squares. I cant think of why this would be more important for bishops and not rooks etc... I'm thinking of the example of a rook on an uncontested (by opponents rooks) open file given a high mobility score for controlling these unoccupied squares, yet it attacks nothing on the file and has no chance to penetrate because the >5 ranks are protected by the bishop pair (e.g.) or other pieces. Maybe its better to treat attacks and potential moves separately.
outAtime
outAtime
Posts: 226
Joined: Sun Mar 08, 2009 3:08 pm
Location: Canada

Re: pawn attacks in mobility

Post by outAtime »

hgm wrote:I often wondered if it would hurt not to count captures at all. (Mainly because it made incremental update of mobility more difficult.)

Captures are more often bad than not. If they were good, they would already have been made earlier, or the position is not quiet now. If they are bad, they'd better not count as mobility. So only equal captures could be a useful asset.
This has been on my mind ever since your post and my initial replies were just rants. Undoubtedly the perfect mobility scoring routine has not yet been invented or cannot exist. It seems to me each has its own deficiency yet improves upon none at all. I'm sure anyone who has tried tuning mobility scores or changing mobility scoring methods can attest to this. Of course most fall generally into the 5,4,2,1 routine, I have seen many strong programs which choose to leave out queen mobility. Most do follow each other closely at a safe distance. My biggest surprise is that all programs without exception that I have looked at score Bishop mobility above all others. The question, I guess, is just how many possible variations of scores below 8 (multiplication factor) and also the adjustment to initial score (e.g. rook_mobility - 3, - 7, -2 etc,, *... ) are possible?
I think its impossible to test. Run all the possibilities to arrive at the best mobility scores. 1111, 1112, 1113, etc....... etc ....... * 10,000 games + variations etc? Has anyone tried this on a cluster?
outAtime