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

Re: Mobility

Post by outAtime »

I also agree that linear mobility is not the best, I was using a sqrt() function to try to combat some linearity, but its removed for now..
outAtime
outAtime
Posts: 226
Joined: Sun Mar 08, 2009 3:08 pm
Location: Canada

Re: Mobility

Post by outAtime »

Uri Blass wrote:
outAtime wrote:I can keep "p" but I'll need to adjust the other values - 1/2 I guess. ? I just don't know why the score seems to double with "p".
I do not know but if the score that you have is based on search and not static evaluation then it is possible that the bishop get 13 squares and not 7 squares because search can push the bishop to the centre of the board when it has 13 squares.
I do not have SEE, if that is what you mean.
outAtime
Uri Blass
Posts: 10309
Joined: Thu Mar 09, 2006 12:37 am
Location: Tel-Aviv Israel

Re: Mobility

Post by Uri Blass »

outAtime wrote:
Uri Blass wrote:
outAtime wrote:I can keep "p" but I'll need to adjust the other values - 1/2 I guess. ? I just don't know why the score seems to double with "p".
I do not know but if the score that you have is based on search and not static evaluation then it is possible that the bishop get 13 squares and not 7 squares because search can push the bishop to the centre of the board when it has 13 squares.
I do not have SEE, if that is what you mean.
I did not mean SEE but simply search.

I do not know if the scores that you get for KB vs K position are score of the static evaluation or scores of the position after searching like you do in a real game.
mcostalba
Posts: 2684
Joined: Sat Jun 14, 2008 9:17 pm

Re: Mobility

Post by mcostalba »

outAtime wrote:

Code: Select all

int bishop_mobility(int squareb)
{
  int p, d, bfs, s = 0;
 
  for &#40;d = 0; d < 4; d++)
  &#123;
       bfs = b_offsets&#91;d&#93;;
       for &#40;p = squareb + bfs; board&#91;p&#93; == npiece; p += bfs&#41;
           s++;
  &#125;
  return s;
&#125; 
This is the correct version. I forgot to define 'p'.

I suggest to print the score of just mobility. As a general rule while debugging you may want to go as near as possible in monitoring _just_ the function you are verifying, so I strongly suggest to add some printf that prints the position _and_ the bishop mobility for that position, i.e. the return value of bishop_mobility() no more no less. In this case it is easier to find the bug.

Another general rule that I'd suggest is to focus _only_ on bug fixing before to pass to something else (I have read about non-linear mobility here). If you mess too much stuff toghter at the end you got nothing. The standard approach is first fix the bug, then try to improve. The reverse does not work.
Last edited by mcostalba on Sat Oct 16, 2010 10:44 pm, edited 1 time in total.
outAtime
Posts: 226
Joined: Sun Mar 08, 2009 3:08 pm
Location: Canada

Re: Mobility

Post by outAtime »

interesting point. I should apologize for this ridiculous oversight. ridiculous.
In fact the version _without_ "p" is undervalued in this case. "p" is correct.
Thanks for pointing out my error. duh.
outAtime
mcostalba
Posts: 2684
Joined: Sat Jun 14, 2008 9:17 pm

Re: Mobility

Post by mcostalba »

outAtime wrote:interesting point. I should apologize for this ridiculous oversight. ridiculous.
In fact the version _without_ "p" is undervalued in this case. "p" is correct.
Thanks for pointing out my error. duh.
Actually error was mine :D
mcostalba
Posts: 2684
Joined: Sat Jun 14, 2008 9:17 pm

Re: Mobility

Post by mcostalba »

And if you like compact code here is another variation, although I guess is slower....but test is needed...as usual

Code: Select all

int b_offsets&#91;&#93; = &#123; 11, -11, 13, -13, 0 &#125;;

int bishop_mobility&#40;int squareb&#41;
&#123;
  int p, *d = b_offsets, s = 0;
 
  for ( ; *d; d++)
       for &#40;p = squareb + *d; board&#91;p&#93; == npiece; p += *d&#41;
           s++;
  return s;
&#125;
outAtime
Posts: 226
Joined: Sun Mar 08, 2009 3:08 pm
Location: Canada

Re: Mobility

Post by outAtime »

Im gonna test this :

Code: Select all

/* calculate mobitity scores -- Thanks to Harald Lüßen&#40;knight_mobility&#41; and Marco Costalba &#40;Bishop Mobility&#41;
   also Uri Blass and Ferdinand Mosca who helped to clarify and suggest improvements */
   
int knight_mobility&#40;int squaren&#41;
&#123;
  int n;
  int g = 0;
  
  for &#40;n = 0; n < 8; n++)
  //n_sq = squaren + n_offsets&#91;n&#93;;
    if &#40;board&#91;squaren + n_offsets&#91;n&#93;&#93; == npiece&#41; // or == opponent
      g++;
  return g;
&#125; 

int bishop_mobility&#40;int squareb&#41;
&#123;
  int p, d, bfs, s = 0;
 
  for &#40;d = 0; d < 4; d++)
  &#123;
       bfs = b_offsets&#91;d&#93;;
       for &#40;p = squareb + bfs; board&#91;p&#93; == npiece; p += bfs&#41;
           s++;
  &#125;
  return s;
&#125; 

int rook_mobility&#40;int squarer&#41;
&#123;
  int r, f, rfs, c = 0;
 
  for &#40;f = 0; f < 4; f++)
  &#123;
       rfs = r_offsets&#91;f&#93;;
       for &#40;r = squarer + rfs; board&#91;r&#93; == npiece; r += rfs&#41;
           c++;
  &#125;
  return c;
&#125; 
 
 int queen_mobility&#40;int squareq&#41;
&#123;
  int q, l, qfs, m = 0;
  
  for &#40;l = 0; l < 8; l++)
  &#123;
       qfs = q_offsets&#91;l&#93;;
       for &#40;q = squareq + qfs; board&#91;q&#93; == npiece; q += qfs&#41;
           m++;
  &#125;
  return m;
&#125; 

where...

Code: Select all

#define bmo 7
#define nmo 5
#define rmo 3
#define bme 4
#define nme 2
#define rme 4
#define qmo 1
#define qme 1
maybe it's still too high, not sure how many games to do or if 1 0 is ok, or if I should do 3 0.... 3 0 for now...
outAtime
mcostalba
Posts: 2684
Joined: Sat Jun 14, 2008 9:17 pm

Re: Mobility

Post by mcostalba »

outAtime wrote:Im gonna test this :
I prefer your version, is more reaadable and probably faster but....anyhow....

Code: Select all

int b_ofs&#91;&#93; = &#123; 11, -11, 13, -13, 0 &#125;;
int r_ofs&#91;&#93; = &#123; 12, -12,  1,  -1, 0 &#125;;

int piece_mobility&#40;int sq, int offsets&#91;&#93;)
&#123;
  int p, *d = offsets, s = 0;
 
  for ( ; *d; d++)
       for &#40;p = sq + *d; board&#91;p&#93; == npiece; p += *d&#41;
           s++;
  return s;
&#125;

int bishop_mobility&#40;int sq&#41;&#123; return piece_mobility&#40;sq, b_ofs&#41;; &#125;
int rook_mobility&#40;int sq&#41;  &#123; return piece_mobility&#40;sq, r_ofs&#41;; &#125;
int queen_mobility&#40;int sq&#41; &#123; return piece_mobility&#40;sq, b_ofs&#41;
                                  + piece_mobility&#40;sq, r_ofs&#41;; &#125;
outAtime
Posts: 226
Joined: Sun Mar 08, 2009 3:08 pm
Location: Canada

Re: Mobility

Post by outAtime »

Why the , 0 ?
it looks really sophisticated, Im wondering if nt b_ofs[] = { 11, -11, 13, -13, 0 };
is an improvement over the offset without 0.
outAtime