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 »

Sorry, the code above won't work. I would have removed it but it was too late.
outAtime
outAtime
Posts: 226
Joined: Sun Mar 08, 2009 3:08 pm
Location: Canada

Re: Mobility

Post by outAtime »

Trying this...

Code: Select all

int wknight_mobility(int squaren)
{
  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 || board&#91;squaren + n_offsets&#91;n&#93;&#93; == &#40;black_piece&#41;) // or == opponent
      g++;
  return g;
&#125; 

int bknight_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 || board&#91;squaren + n_offsets&#91;n&#93;&#93; == &#40;white_piece&#41;) // or == opponent
      g++;
  return g;
&#125; 
where..

Code: Select all

#define black_piece bpawn | bknight | bbishop | brook | bqueen | bking 
#define white_piece wpawn | wknight | wbishop | wrook | wqueen | wking 
seems to work.. testing. Thanks.
outAtime
Harald
Posts: 318
Joined: Thu Mar 09, 2006 1:07 am

Re: Mobility

Post by Harald »

outAtime wrote:Trying this...

Code: Select all

int wknight_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 || board&#91;squaren + n_offsets&#91;n&#93;&#93; == &#40;black_piece&#41;) // or == opponent
      g++;
  return g;
&#125; 

int bknight_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 || board&#91;squaren + n_offsets&#91;n&#93;&#93; == &#40;white_piece&#41;) // or == opponent
      g++;
  return g;
&#125; 
where..

Code: Select all

#define black_piece bpawn | bknight | bbishop | brook | bqueen | bking 
#define white_piece wpawn | wknight | wbishop | wrook | wqueen | wking 
seems to work.. testing. Thanks.
This won't work! :-(

Please read my last posting again. Carefully!
And understand it first before you change your source.

You need to understand the difference between
-6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6
and the powers of 2 that have only one bit set in their binary representation:
2048, 1024, 512, 256, 128, 64, 0, 1, 2, 4, 8, 16, 32
Google for binary numbers.

You need to understand the difference between the | operator and the || operator.

You need to understand why the condition in the first case is
if ( board[sq] > 0 ) or if ( board[sq] < 0 ) // omitting the border test
and the condition in the latter case is
if ( board[sq] & opp_pieces )
where opp_pieces is a | combination of power_of_2 piece bits.
And may I suggest that you please notice the usage of the & operator
in the latter case.

Do not mix both models!
Most people prefer the simple number model.
That is -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6

Harald
mcostalba
Posts: 2684
Joined: Sat Jun 14, 2008 9:17 pm

Re: Mobility

Post by mcostalba »

outAtime wrote: seems to work.. testing. Thanks.
Please just one thing and I won't bother you anymore. If you want your positive attitude at learning a computer language do survives more then one month then I humbly suggest the following:

1) Understand the difference between debugging and testing. It seems is absolutely blurred for you, actually this two activities are _completely_ different and aimed at completely different purposes.

2) Learn the basic of debugging, printf, setting a given position, monitoring the input and the output values out of a function. A book (in case an on-line one) could be extremely beneficial for you.

3) Run the code (what you call "to test") only when it is absolutely clear for you what the code does, don't run a black box you don't understand: you learn nothing and just waste your time.

4) Trying to do by yourself is a good thing, but at this so early stage of programming language knowledge I have to suggest to look (and try to understand) other's people code: it is fine trying to write a novel by yourself, but first you should learn the grammar. ;-)

Have fun and good luck !
outAtime
Posts: 226
Joined: Sun Mar 08, 2009 3:08 pm
Location: Canada

Re: Mobility

Post by outAtime »

Code: Select all

void init_game&#40;void&#41; &#123;

	/* set up a new game&#58; */

	int i;

	int init_board&#91;144&#93; = &#123;
		0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
		0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
		0,   0,   7,   3,  11,   9,   5,  11,   3,   7,   0,   0,
		0,   0,   1,   1,   1,   1,   1,   1,   1,   1,   0,   0,
		0,   0,  13,  13,  13,  13,  13,  13,  13,  13,   0,   0,
		0,   0,  13,  13,  13,  13,  13,  13,  13,  13,   0,   0,
		0,   0,  13,  13,  13,  13,  13,  13,  13,  13,   0,   0,
		0,   0,  13,  13,  13,  13,  13,  13,  13,  13,   0,   0,
		0,   0,   2,   2,   2,   2,   2,   2,   2,   2,   0,   0,
		0,   0,   8,   4,  12,  10,   6,  12,   4,   8,   0,   0,
		0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
		0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0 &#125;;


	memcpy&#40;board, init_board, sizeof&#40;init_board&#41;);
	for &#40;i = 0; i <= 143; i++)
		moved&#91;i&#93; = 0;
so frame (or border) is defined as 0 and npiece is defined as 13. The rest of the pieces are defined by number - e.g. #define wrook 8 #define brook 7. Then you posted "..And then the white opponent can be found with
if (board[sq] < 0)" and I was a bit lost because I never thought to define them as negative #'s for opposite color.... Thanks. [/code]
outAtime
outAtime
Posts: 226
Joined: Sun Mar 08, 2009 3:08 pm
Location: Canada

Re: Mobility

Post by outAtime »

I've tried using negative #'s for the black pieces, and also the power of 2 numbers to define the pieces but neither seems to be working, a number like 2048 is just too big it seems and gets changed at compile to an unregistered int. I also tried using 7 as npiece and larger numbers for black pieces (>7), smaller for white (<7) and the program was returning illegal moves. I've looked at alot of code (fruit, sloppy, daydreamer, pawny, gull, etc..) and just cant find any solutions. :( Oh, well... Are there any good programs that _don't_ count attacked enemy pieces as a mobility bonus? I was also thinking of maybe trying something simple like...

Code: Select all

#define b_opponent wking || wqueen || wrook || wbishop || wknight || wpawn
the idea being even though if there is a wking and a wpawn being attacked by.. say a black knight, the bonus will be attributed to attacking the king, no bonus for attacking the pawn... but maybe its more valuable to attack the king and the rest worked out by search...

maybe it would be better to have wbishop before wrook in case of a knight to try and get that bonus first...

BTW.. I really do appreciate the help I have received here on this topic (and others) and I hope it has also proved of some use to people with similar questions. Thanks.
outAtime
rbarreira
Posts: 900
Joined: Tue Apr 27, 2010 3:48 pm

Re: Mobility

Post by rbarreira »

Whatever you do, always put parentheses around macro contents:

Code: Select all

#define b_opponent &#40;wking || wqueen || wrook || wbishop || wknight || wpawn&#41;
Otherwise you're setting yourself up for weird and hard to find bugs due to operator priorities messing up the usage of your macro.