Search and 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: Search and Mobility

Post by outAtime »

Yes :) Put in for bishops white and black, it seems to work very nicely!
Thankyou.

The poor knights are jealous now :)

Code: Select all

int white_knight_mobility(int squaren)
{   
  int n;
  int g = 0;
  
  for &#40;n = 0; n < 8; n++)
    if &#40;board&#91;squaren + n_ofs&#91;n&#93;&#93; == npiece&#41; 
      g++;
	 
	if &#40;board&#91;squaren + n_ofs&#91;n&#93;&#93; == bbishop&#41; 
      g++;
	 
	if &#40;board&#91;squaren + n_ofs&#91;n&#93;&#93; == bqueen&#41; 
      g++;
	 
	if &#40;board&#91;squaren + n_ofs&#91;n&#93;&#93; == brook&#41; 
      g++;
	  
	if &#40;board&#91;squaren + n_ofs&#91;n&#93;&#93; == bpawn&#41; 
      g++;
	  
	if &#40;board&#91;squaren + n_ofs&#91;n&#93;&#93; == bking&#41; 
      g++;
	  
  return g;
&#125; 
I know they will be different, for now i will add this to the queens and rooks also and test again... Im not sure if i will be able to use a similar idea bitwise for the knights.
outAtime
jwes
Posts: 778
Joined: Sat Jul 01, 2006 7:11 am

Re: Search and Mobility

Post by jwes »

outAtime wrote:Is that a bitwise way to differentiate between even or odd? Looks pretty good, Ill try it, but what about npiece which is odd (13) would it be counted twice? Sorry, my understanding of this type of bitwise statements is still near the beginning, I understand some but would like to know how its working. And thanks for the suggestion.
Right, it is a bitwise way to differentiate between even or odd. It can't be equal to npiece because it dropped out of the loop above.
PK
Posts: 893
Joined: Mon Jan 15, 2007 11:23 am
Location: Warsza

Re: Search and Mobility

Post by PK »

You can save an awful lot of effort by not evaluating mobility when You are a minor piece up or more - this is called "lazy evaluation". the margin might seem too high for now, but mobility function gathers data useful for calculating king safety, too.
JVMerlino
Posts: 1357
Joined: Wed Mar 08, 2006 10:15 pm
Location: San Francisco, California

Re: Search and Mobility

Post by JVMerlino »

PK wrote:You can save an awful lot of effort by not evaluating mobility when You are a minor piece up or more - this is called "lazy evaluation". the margin might seem too high for now, but mobility function gathers data useful for calculating king safety, too.
Given that Kenny appears to be new to writing a chess engine, maybe I should clarify Pawel's statement.

In my lazy eval calculation, I check to see if the difference in material is a certain amount less than Alpha or greater than Beta. If it is, then I simply return Alpha or Beta respectively. I do this check several times in my entire eval function, with different ranges depending on how much eval I've calculated so far.

In other words, if the material difference shows -300 cp, and Alpha is 200, AND if you are confident that the remaining parts of your evaluation will not bring the eval up to at least 200 (that's the critical part), then there's no point in continuing, and you should just return Alpha.

But I think simply checking the difference in material may be dangerous.

Pawel, please correct me if I'm wrong.

jm
PK
Posts: 893
Joined: Mon Jan 15, 2007 11:23 am
Location: Warsza

Re: Search and Mobility

Post by PK »

Yes, I agree that my description of lazy eval was too hasty, sorry if it caused any confusion. John Merlino described how to do it right. Version using just material difference and not referring to alpha and beta is used in only one program I am aware of - namely Sungorus.

Another mobility method that can help is to use a predefined table, something like:

int knight_mob[9] = { -12, -8, -4, 0, 3, 6, 8, 10, 12};

and use the results of Your functions as an index to it. after all, it's more important to activate a passive piece than to improve a mobility of a knight from 7 to 8.

regards,

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

Re: Search and Mobility

Post by outAtime »

mcostalba wrote:
outAtime wrote: returns a compile warning 'q' might be used uninitialized in this function.
Try this:

Code: Select all

int piece_mobility_white&#40;int sq, int offsets&#91;&#93;)
&#123;
  int q, *c = offsets, t = 0;

  do &#123;
       for &#40;q = sq + *c; board&#91;q&#93; == npiece; q += *c&#41;
           t++;
  &#125; while (*++c&#41;;

  if &#40;board&#91;q&#93; && (&#40;board&#91;q&#93; & 1&#41; == 0&#41;)
      t++;

  return t;
&#125;

BTW I'd rename the function as piece_mobility_black() because the code is the same for all the pieces, only the function parameter offsets[] changes.
where n_ofs is:

Code: Select all

int n_ofs&#91;&#93; = &#123; -10, 10, -14, 14, -23, 23, -25, 25, 0 &#125;;
and I'm doing:

Code: Select all

int white_knight_mobility&#40;int sq&#41;&#123; return piece_mobility_white&#40;sq, n_ofs&#41;; &#125;
why does this return a score of 12 for knight mobility?

seems I'm stuck with:

Code: Select all

int knight_mobility_white&#40;int sq&#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;sq + n_ofs&#91;n&#93;&#93; == npiece&#41; // or == opponent
      g++;
  return g;
&#125; 
as this returns 8, as expected...
not sure why the other code is returning 12.
Thanks.
outAtime
User avatar
Kempelen
Posts: 620
Joined: Fri Feb 08, 2008 10:44 am
Location: Madrid - Spain

Re: Search and Mobility

Post by Kempelen »

PK wrote: int knight_mob[9] = { -12, -8, -4, 0, 3, 6, 8, 10, 12};

and use the results of Your functions as an index to it. after all, it's more important to activate a passive piece than to improve a mobility of a knight from 7 to 8.

regards,

PK
I am using that schema, but to get what you say I penalize more dont having moves than going from 7 to 8. I mean, something like this:

Code: Select all

static const int MOV_CABALLO&#91;9&#93; = &#123; -40, -20, 0, 4, 8, 10, 12, 14, 16&#125;;
static const int MOV_ALFIL&#91;15&#93; =  &#123; -40, -20, -10, 0, 0, 2, 4,  6,  8, 10, 12, 14, 16, 18, 20, 20&#125;;
As you see, passing from 0 to 1 or 2 it is more important than goinf from 8 to 9. Improving mobility of a very trapped piece it is more important that increase mobility of a yet free piece.

EDIT: forget to say that somebody told to me to increase mobility even more, maybe a pawn for extreme situations, because it is demostrated is a correlation between game result and mobility
Fermin Serrano
Author of 'Rodin' engine
http://sites.google.com/site/clonfsp/
outAtime
Posts: 226
Joined: Sun Mar 08, 2009 3:08 pm
Location: Canada

Re: Search and Mobility

Post by outAtime »

Sorry, I was wondering why piece_mobility_white() seems to return ok scores for sliders but not for the knight. I wasnt referring to different types of non-linear mobility stuff, just that the return is incorrect. :)
outAtime
Sven
Posts: 4052
Joined: Thu May 15, 2008 9:57 pm
Location: Berlin, Germany
Full name: Sven Schüle

Re: Search and Mobility

Post by Sven »

outAtime wrote:and I'm doing:

Code: Select all

int white_knight_mobility&#40;int sq&#41;&#123; return piece_mobility_white&#40;sq, n_ofs&#41;; &#125;
why does this return a score of 12 for knight mobility?
piece_mobility_white(), as given in the post above, is written for sliders. It may increment the mobility count per direction more than once (nested loop), which is not what you want to get for knights.

Better rename the function into slider_mobility(). You'll also need a separate knight_mobility() function.

Sven
Sven
Posts: 4052
Joined: Thu May 15, 2008 9:57 pm
Location: Berlin, Germany
Full name: Sven Schüle

Re: Search and Mobility

Post by Sven »

<deleted by intent by the author>
Last edited by Sven on Thu May 05, 2011 4:39 pm, edited 1 time in total.