Discussion of chess software programming and technical issues.
Moderator: Ras
outAtime
Posts: 226 Joined: Sun Mar 08, 2009 3:08 pm
Location: Canada
Post
by outAtime » Fri Oct 15, 2010 11:12 pm
Yes, and further testing shows breaking even or slightly less, I guess I'll replace the current code for bishops, rooks, and queen with:
Code: Select all
/*int bishop_mobility(int squareb)
{
register int d;
register int s = 0;
for (d = squareb+13; board[d] == npiece; d+=13)
s++;
for (d = squareb-13; board[d] == npiece; d-=13)
s++;
for (d = squareb+11; board[d] == npiece; d+=11)
s++;
for (d = squareb-11; board[d] == npiece; d-=11)
s++;
return s;
}
int rook_mobility(int squarer)
{
register int f;
register int c = 0;
for (f = squarer+12; board[f] == npiece; f+=12)
c++;
for (f = squarer-12; board[f] == npiece; f-=12)
c++;
for (f = squarer+1; board[f] == npiece; f+=1)
c++;
for (f = squarer-1; board[f] == npiece; f-=1)
c++;
return c;
} */
*int queen_mobility(int square)
{
register int l;
register int m = 0;
for (l = square+13; board[l] == npiece; l+=13)
m++;
for (l = square-13; board[l] == npiece; l-=13)
m++;
for (l = square+11; board[l] == npiece; l+=11)
m++;
for (l = square-11; board[l] == npiece; l-=11)
m++;
for (l = square+12; board[l] == npiece; l+=12)
m++;
for (l = square-12; board[l] == npiece; l-=12)
m++;
for (l = square+1; board[l] == npiece; l+=1)
m++;
for (l = square-1; board[l] == npiece; l-=1)
m++;
return m;
}
Too bad it only works for knights.
outAtime
bob
Posts: 20943 Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL
Post
by bob » Fri Oct 15, 2010 11:47 pm
I assume you use 0x88 or some other approach that has at least one ring of border squares outside the real board, initialized to the value "npiece"???
outAtime
Posts: 226 Joined: Sun Mar 08, 2009 3:08 pm
Location: Canada
Post
by outAtime » Sat Oct 16, 2010 12:40 am
Yeah. its either a piece (wqueen, bqueen, wpawn etc.), npiece, or frame.
outAtime
outAtime
Posts: 226 Joined: Sun Mar 08, 2009 3:08 pm
Location: Canada
Post
by outAtime » Sat Oct 16, 2010 12:45 am
Why? Should I be concerned about the frame?
outAtime
outAtime
Posts: 226 Joined: Sun Mar 08, 2009 3:08 pm
Location: Canada
Post
by outAtime » Sat Oct 16, 2010 1:01 am
Code: Select all
int b_offsets[4] = { 11, -11, 13, -13 };
int bishop_mobility(int squareb)
{
int d;
int s = 0;
for (d = 0; d < 4; d++)
if (board[squareb + b_offsets[d]] == npiece) // or == opponent
s++;
return s;
}
are you sure you aren't missing somthing? Im confused... how is this only counting 4 squares?
outAtime
outAtime
Posts: 226 Joined: Sun Mar 08, 2009 3:08 pm
Location: Canada
Post
by outAtime » Sat Oct 16, 2010 2:22 am
yeah, sorry I guess this code is wrong. Too bad, because it seemed less expensive, lol
outAtime
outAtime
Posts: 226 Joined: Sun Mar 08, 2009 3:08 pm
Location: Canada
Post
by outAtime » Sat Oct 16, 2010 6:29 pm
There is something wrong with this, because I'm getting double the mobility score expected. I was wondering why this method seemed expensive and maybe its because I'm counting something twice. Can anybody see where this code might be counting the squares twice?
Code: Select all
int bishop_mobility(int squareb)
{
register int d;
register int s = 0;
for (d = squareb+13; board[d] == npiece; d+=13)
s++;
for (d = squareb-13; board[d] == npiece; d-=13)
s++;
for (d = squareb+11; board[d] == npiece; d+=11)
s++;
for (d = squareb-11; board[d] == npiece; d-=11)
s++;
return s;
}
Thanks.
outAtime
mcostalba
Posts: 2684 Joined: Sat Jun 14, 2008 9:17 pm
Post
by mcostalba » Sat Oct 16, 2010 6:59 pm
outAtime wrote: Can anybody see where this code might be counting the squares twice?
It seems correct to me. Are you sure you call function bishop_mobility() only once ?
BTW what about this ?
Code: Select all
int b_offsets[] = { 11, -11, 13, -13 };
int bishop_mobility(int squareb)
{
int d, ofs, s = 0;
for (d = 0; d < 4; d++)
{
ofs = b_offsets[d];
for (p = squareb + ofs; board[p] == npiece; p += ofs)
s++;
}
return s;
}
outAtime
Posts: 226 Joined: Sun Mar 08, 2009 3:08 pm
Location: Canada
Post
by outAtime » Sat Oct 16, 2010 7:35 pm
Thanks Marco. I was looking for something like what you have suggested, if not just to have the code look more uniform. Hopefully this way might be a bit less expensive too. As far as calling mobility(), I call it only when scoring the piece (so it is called in ending, middlegame, and opening) and the position where I noticed a double score was in an endgame with only kings and 1 bishop (for black) on the board with no other pieces or pawns. (I haven't added draw code yet)
in the endgame..
Code: Select all
case (wbishop):
score += 325;
score += bishop[i];
score += bishop_mobility(i) * bme;
break;
case (bbishop):
score -= 325;
score -= bishop[i];
score -= bishop_mobility(i) * bme;
break;
-outAtime
outAtime
outAtime
Posts: 226 Joined: Sun Mar 08, 2009 3:08 pm
Location: Canada
Post
by outAtime » Sat Oct 16, 2010 7:43 pm
mcostalba wrote: outAtime wrote: Can anybody see where this code might be counting the squares twice?
It seems correct to me. Are you sure you call function bishop_mobility() only once ?
BTW what about this ?
Code: Select all
int b_offsets[] = { 11, -11, 13, -13 };
int bishop_mobility(int squareb)
{
int d, ofs, s = 0;
for (d = 0; d < 4; d++)
{
ofs = b_offsets[d];
for (p = squareb + ofs; board[p] == npiece; p += ofs)
s++;
}
return s;
}
Shouldn't "p" be "d" ? or is p new.. I dont see int p.
outAtime