Excluding squares from mobility

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

OliverBr
Posts: 725
Joined: Tue Dec 18, 2007 9:38 pm
Location: Munich, Germany
Full name: Dr. Oliver Brausch

Excluding squares from mobility

Post by OliverBr »

Hello together,
inspired by Terje's great engine Weiss I implemented the exclusion of "bad squares" from mobility with following rules:

A "bad mobility square" is:
1) squares that are attacked by enemy's pawns.
2) friendly pawns blocked by any piece
3) friendly pawns on 2. rank

(I wanted to implement 1) since many years. I had 2) implemented in another way before, but didn't gain ELO. 3) is completely new for me.)

1) and 2) are illustrated by this position:

[d]8/5k1p/1p1pRp2/3P4/PpP3Pp/6bP/6K1/8 w - - 0 2 bm c4c5

yields to this MobilityBoard for white:

Code: Select all

 1 1 1 1 1 1 1 1
 1 1 1 1 1 1 1 1
 1 1 1 1 1 1 0 1
 0 1 0 0 0 1 0 1
 1 1 1 1 1 1 1 1
 0 1 0 1 1 1 0 0
 1 1 1 1 1 1 1 1
 1 1 1 1 1 1 1 1
Now, masking every mobility evaluation with it:

Code: Select all

mn += _bitcnt(a & mobilityb) << 3;
instead of

Code: Select all

mn += _bitcnt(a) << 3;
I personally find this very logical and would have wagered that it improved the engine.

But, actually, it's playing 20-30 ELO weaker with the mobility mask.
Who has an idea, why it doesn't work?

PS: Here the commit: https://github.com/olithink/OliThink/co ... 7536087b9b
Chess Engine OliThink: http://brausch.org/home/chess
OliThink GitHub:https://github.com/olithink
mar
Posts: 2559
Joined: Fri Nov 26, 2010 2:00 pm
Location: Czech Republic
Full name: Martin Sedlak

Re: Excluding squares from mobility

Post by mar »

What I did (years ago) was "safe mobility" a trivial and obvious idea:

- for knights and bishops, exclude squares attacked by opponent's pawns
- for rooks, exclude squares attacked by opponent's pawns, knights and bishops
- for queens, exclude squares attacked by opponent's pawns, knights, bishops and rooks

simply put: exclude squares attacked by opponent's pieces, that have a lower value than the piece you're computing mobility for

IIRC it was a small elo gainer, but nothing spectacular
Martin Sedlak
mar
Posts: 2559
Joined: Fri Nov 26, 2010 2:00 pm
Location: Czech Republic
Full name: Martin Sedlak

Re: Excluding squares from mobility

Post by mar »

OliverBr wrote: Sun Sep 27, 2020 8:21 am yields to this MobilityBoard for white:

Code: Select all

 1 1 1 1 1 1 1 1
 1 1 1 1 1 1 1 1
 1 1 1 1 1 1 0 1
 0 1 0 0 0 1 0 1
 1 1 1 1 1 1 1 1
 0 1 0 1 1 1 0 0
 1 1 1 1 1 1 1 1
 1 1 1 1 1 1 1 1
But, actually, it's playing 20-30 ELO weaker with the mobility mask.
Who has an idea, why it doesn't work?
I very much doubt this will lose 20-30 Elo, I suspect a bug.
btw - your mask seems to include 0es for squares that are in front of some of opponent's pawns but not actually attacked by them
Martin Sedlak
Joost Buijs
Posts: 1564
Joined: Thu Jul 16, 2009 10:47 am
Location: Almere, The Netherlands

Re: Excluding squares from mobility

Post by Joost Buijs »

mar wrote: Sun Sep 27, 2020 8:35 am What I did (years ago) was "safe mobility" a trivial and obvious idea:

- for knights and bishops, exclude squares attacked by opponent's pawns
- for rooks, exclude squares attacked by opponent's pawns, knights and bishops
- for queens, exclude squares attacked by opponent's pawns, knights, bishops and rooks

simply put: exclude squares attacked by opponent's pieces, that have a lower value than the piece you're computing mobility for

IIRC it was a small elo gainer, but nothing spectacular
This is exactly what I also do. I compute attacks on the fly in the evaluation function and start with the lowest valued pieces first, than it is just a matter of adding a single mask. I never found much difference in strength compared to other schemes though, but like you said it is an obvious thing to do.

In my engine I use milli-pawn resolution for the positional evaluation, to calculate the mobility I use separate PSQT's for each piece-type tuned by logistic regression, this gives some improvement over multiplying the mobility count with a single term.
chrisw
Posts: 4319
Joined: Tue Apr 03, 2012 4:28 pm

Re: Excluding squares from mobility

Post by chrisw »

Joost Buijs wrote: Sun Sep 27, 2020 9:34 am
mar wrote: Sun Sep 27, 2020 8:35 am What I did (years ago) was "safe mobility" a trivial and obvious idea:

- for knights and bishops, exclude squares attacked by opponent's pawns
- for rooks, exclude squares attacked by opponent's pawns, knights and bishops
- for queens, exclude squares attacked by opponent's pawns, knights, bishops and rooks

simply put: exclude squares attacked by opponent's pieces, that have a lower value than the piece you're computing mobility for

IIRC it was a small elo gainer, but nothing spectacular
This is exactly what I also do. I compute attacks on the fly in the evaluation function and start with the lowest valued pieces first, than it is just a matter of adding a single mask. I never found much difference in strength compared to other schemes though, but like you said it is an obvious thing to do.
I've tried that but found it slightly negative, so now no longer bother. Pawns yes, everything else no.

In my engine I use milli-pawn resolution for the positional evaluation, to calculate the mobility I use separate PSQT's for each piece-type tuned by logistic regression, this gives some improvement over multiplying the mobility count with a single term.
User avatar
hgm
Posts: 27809
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Excluding squares from mobility

Post by hgm »

The following thought might be relevant:

It has never been clear to me whether the (obviously beneficial) effect of optimizing mobility is due to number of moves (enhancing the probability that there is a good one amongst those), or due to board control these moves provide. A Bishop move to a square attacked by an enemy Pawn still prevents an enemy Rook or Queen going there, and allows you to eliminate a nasty minor that would appear there at virtually no cost. That seems a good aspect of the position, so why not award it? OTOH, a Bishop move to a square attacked by a friendly Pawn helps much less to control that square. The Pawn already interdicted access to it by any non-Pawn, and it might not be possible for an enemy Pawn to go there.

For this reason I cannot exclude that it would work better to mask out squares attacked by your own Pawns from the mobility, instead of those by enemy Pawns. Perhaps 'square control' is a more relevant term than 'piece mobility', although the two will obviously correlate.
OliverBr
Posts: 725
Joined: Tue Dec 18, 2007 9:38 pm
Location: Munich, Germany
Full name: Dr. Oliver Brausch

Re: Excluding squares from mobility

Post by OliverBr »

mar wrote: Sun Sep 27, 2020 8:50 am I very much doubt this will lose 20-30 Elo, I suspect a bug.
btw - your mask seems to include 0es for squares that are in front of some of opponent's pawns but not actually attacked by them
I doubted it, too, but see the result a down below:

There may be a bug, but not in the mask. You are correct that there are two 0es in front of opponent's pawns (d5, h3), because they fulfil condition 2:
2) friendly pawns blocked by any piece
Here is the result with new Feature (5.8.1a):

Code: Select all

   # PLAYER             :  RATING  ERROR  POINTS  PLAYED   (%)     W    D     L  D(%)  CFS(%)
   1 Weiss 1.0          :     257     21  1137.5    1400  81.2  1027  221   152  15.8     100
   2 Murka 3 x64        :     219     19  1088.5    1400  77.8   992  193   215  13.8     100
   3 Glaurung 2.2       :     149     19   981.5    1400  70.1   875  213   312  15.2     100
   4 OliThink 5.8.1a    :       0   ----   992.5    4200  23.6   679  627  2894  14.9     --
992.5 point compared to 1158.0 before:

Code: Select all

   # PLAYER            :  RATING  ERROR  POINTS  PLAYED   (%)    W    D     L  D(%)  CFS(%)
   1 Weiss 1.0         :     210     19  1075.0    1400  76.8  949  252   199  18.0      86
   2 Murka 3 x64       :     196     17  1055.0    1400  75.4  936  238   226  17.0     100
   3 Glaurung 2.2      :     110     17   912.0    1400  65.1  787  250   363  17.9     100
   4 OliThink 5.8.1    :       0   ----  1158.0    4200  27.6  788  740  2672  17.6     ---
Chess Engine OliThink: http://brausch.org/home/chess
OliThink GitHub:https://github.com/olithink
Joost Buijs
Posts: 1564
Joined: Thu Jul 16, 2009 10:47 am
Location: Almere, The Netherlands

Re: Excluding squares from mobility

Post by Joost Buijs »

chrisw wrote: Sun Sep 27, 2020 9:52 am
Joost Buijs wrote: Sun Sep 27, 2020 9:34 am
mar wrote: Sun Sep 27, 2020 8:35 am What I did (years ago) was "safe mobility" a trivial and obvious idea:

- for knights and bishops, exclude squares attacked by opponent's pawns
- for rooks, exclude squares attacked by opponent's pawns, knights and bishops
- for queens, exclude squares attacked by opponent's pawns, knights, bishops and rooks

simply put: exclude squares attacked by opponent's pieces, that have a lower value than the piece you're computing mobility for

IIRC it was a small elo gainer, but nothing spectacular
This is exactly what I also do. I compute attacks on the fly in the evaluation function and start with the lowest valued pieces first, than it is just a matter of adding a single mask. I never found much difference in strength compared to other schemes though, but like you said it is an obvious thing to do.
I've tried that but found it slightly negative, so now no longer bother. Pawns yes, everything else no.

In my engine I use milli-pawn resolution for the positional evaluation, to calculate the mobility I use separate PSQT's for each piece-type tuned by logistic regression, this gives some improvement over multiplying the mobility count with a single term.
BTW I meant square tables and not PSQT's, I expressed myself wrongly.

I think the problem with excluding squares that are under attack by enemy pieces is that the mobility score often changes very rapidly by moving a single piece and that this has an adversary effect on the search as a whole.
Pio
Posts: 334
Joined: Sat Feb 25, 2012 10:42 pm
Location: Stockholm

Re: Excluding squares from mobility

Post by Pio »

OliverBr wrote: Sun Sep 27, 2020 12:33 pm
mar wrote: Sun Sep 27, 2020 8:50 am I very much doubt this will lose 20-30 Elo, I suspect a bug.
btw - your mask seems to include 0es for squares that are in front of some of opponent's pawns but not actually attacked by them
I doubted it, too, but see the result a down below:

There may be a bug, but not in the mask. You are correct that there are two 0es in front of opponent's pawns (d5, h3), because they fulfil condition 2:
2) friendly pawns blocked by any piece
Here is the result with new Feature (5.8.1a):

Code: Select all

   # PLAYER             :  RATING  ERROR  POINTS  PLAYED   (%)     W    D     L  D(%)  CFS(%)
   1 Weiss 1.0          :     257     21  1137.5    1400  81.2  1027  221   152  15.8     100
   2 Murka 3 x64        :     219     19  1088.5    1400  77.8   992  193   215  13.8     100
   3 Glaurung 2.2       :     149     19   981.5    1400  70.1   875  213   312  15.2     100
   4 OliThink 5.8.1a    :       0   ----   992.5    4200  23.6   679  627  2894  14.9     --
992.5 point compared to 1158.0 before:

Code: Select all

   # PLAYER            :  RATING  ERROR  POINTS  PLAYED   (%)    W    D     L  D(%)  CFS(%)
   1 Weiss 1.0         :     210     19  1075.0    1400  76.8  949  252   199  18.0      86
   2 Murka 3 x64       :     196     17  1055.0    1400  75.4  936  238   226  17.0     100
   3 Glaurung 2.2      :     110     17   912.0    1400  65.1  787  250   363  17.9     100
   4 OliThink 5.8.1    :       0   ----  1158.0    4200  27.6  788  740  2672  17.6     ---
What happens if you increase the weight of mobility now to compensate the fewer squares on average?
OliverBr
Posts: 725
Joined: Tue Dec 18, 2007 9:38 pm
Location: Munich, Germany
Full name: Dr. Oliver Brausch

Re: Excluding squares from mobility

Post by OliverBr »

hgm wrote: Sun Sep 27, 2020 12:14 pm A Bishop move to a square attacked by an enemy Pawn still prevents an enemy Rook or Queen going there, and allows you to eliminate a nasty minor that would appear there at virtually no cost. That seems a good aspect of the position, so why not award it?
Of course! Attacking a square attacked by an enemy Pawn is still better than doing nothing. Also, defending a friendly pawn (blocked or not), is better than doing nothing.

Something like

Code: Select all

mn += (_bitcnt(a) + _bitcnt(a & mobilityb)) << 2;
which means, such squares are still awarded half the points than empty squares.
I am running a test at the moment and it's better than before. Unfortunately this also means two times call of _bitcnt. (popcnt)
Chess Engine OliThink: http://brausch.org/home/chess
OliThink GitHub:https://github.com/olithink