Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Wac or Wacnew?

Author: Stuart Cracraft

Date: 20:21:42 10/12/04

Go up one level in this thread


On October 12, 2004 at 14:50:21, Pallav Nawani wrote:

>On October 11, 2004 at 18:50:15, Stuart Cracraft wrote:
>
>>On October 11, 2004 at 14:55:14, Pallav Nawani wrote:
>>
>>>
>>>I was testing new version of my engine on WAC and I got a surprise:
>>>Natwarlal scores 263/300 in 1 second searches and 253/300 in 10 second searches!
>>>I am using 1.4Ghz athlon.
>>
>>Hi -- not related specifically to your post but your code appears to be
>>comparable. Would you consider simultaneous code exchange of Natwarlal
>>for my GA?
>>
>
>Hi,
>
>Natwarlal is open source. Engine + code available here:
>http://www.ironcode.com/natwarlal.html
>Code for the latest version (0.08) is not uploaded yet (code of 0.07 is
>available), but I will put it up in due time.
>
>Pallav

Here is my SEE. This significantly increased my results on short
tests at 1 second per move and cut my tree size by 50% at normal
time controls. Don't investigate captures in the quiescence
search when the result of this is < 0.

#define DEFEND(sq,pc) (ABS(bd[sq])==pc && ((c == white && bd[sq]>=WP &&
bd[sq]<=WK)||(c == black && bd[sq]>=BK && bd[sq]<=BP)))
#define ATTACK(sq,pc) (ABS(bd[sq])==pc && ((c == black && bd[sq]>=WP &&
bd[sq]<=WK)||(c == white && bd[sq]>=BK && bd[sq]<=BP)))

int see(int *bd, int sq)
{
  int attackcolor, defendcolor;
  int stm = 1;        // side
  int capturedfig = bd[sq];
  int gain = stm*mat_value[capturedfig + 6];
  int next_fig;
  int counter = 1;
  int c, oppcolor, i, nsq, offset, starti, lasti;
  int value;

  swap_score[0] = gain;
  stm = -stm;
  at1=at2=at3=de1=de2=de3=0;

  // look for hidden figure
  // produce a move vector form source to target square, go along this vector
  // from the captured piece to the border to find hidden pieces

  if (ISWHITE(sq)) { c = defendcolor = white; oppcolor = attackcolor = black; }
  else if (ISBLACK(sq)) { c = defendcolor = black; oppcolor = attackcolor =
white; }
  else {
    printf("assert, see, impossible color at %s\n",sqnames[sq]);
    fprintf(lfp,"assert, see, impossible color at %s\n",sqnames[sq]);
  }

  for (offset = 0; offset < 8; offset++) {
    if (DEFEND(sq+knightoffsets[offset],knight)) defender[de1++]=knight;
    else if (ATTACK(sq+knightoffsets[offset],knight)) attacker[at1++]=knight;
    if (DEFEND(sq+sliders[offset],king)) defender[de1++]=king;
    else if (ATTACK(sq+sliders[offset],king)) attacker[at1++]=king;
  }

  if (ISWHITE(sq)) {
    if (DEFEND(sq+BCAPL,pawn))
      defender[de1++]=pawn;
    if (DEFEND(sq+BCAPR,pawn))
      defender[de1++]=pawn;
    if (ATTACK(sq+WCAPR,pawn))
      attacker[at1++]=pawn;
    if (ATTACK(sq+WCAPL,pawn))
      attacker[at1++]=pawn;
  } else {
    if (DEFEND(sq+WCAPL,pawn))
      defender[de1++]=pawn;
    if (DEFEND(sq+WCAPR,pawn))
      defender[de1++]=pawn;
    if (ATTACK(sq+BCAPR,pawn))
      attacker[at1++]=pawn;
    if (ATTACK(sq+BCAPL,pawn))
      attacker[at1++]=pawn;
  }

  starti = 0; lasti = 7;
  for (i = starti; i <= lasti; i++) {
     nsq = sq;
     while (1) {
       nsq += sliders[i];
       if (OFFBD(nsq))
         break;
       else if (EMPTY(nsq)) continue;
       else if (i < 4) {
         if (DEFEND(nsq,bishop))
	   defender[de1++]=bishop;
         if (DEFEND(nsq,queen))
	   defender[de1++]=queen;
         if (ATTACK(nsq,bishop))
	   attacker[at1++]=bishop;
         if (ATTACK(nsq,queen))
	   attacker[at1++]=queen;
//	 break;
       } else if (i >= 4) {
         if (DEFEND(nsq,rook))
	   defender[de1++]=rook;
         if (DEFEND(nsq,queen))
	   defender[de1++]=queen;
         if (ATTACK(nsq,rook))
	   attacker[at1++]=rook;
         if (ATTACK(nsq,queen))
	   attacker[at1++]=queen;
//	 break;
       }
       else
         break;
     }
  }
  qsort(attacker,at1,sizeof(int),compare0);
  qsort(defender,de1,sizeof(int),compare0);

#ifdef NEVER
  printf("attackers (%d): ",at1);
  for (i = 0; i<at1; i++) printf("%d ",attacker[i]);
  printf("defender (%d): ",de1);
  for (i = 0; i<de1; i++) printf("%d ",defender[i]);
  if (attackcolor == white) {printf("attacking is white, defending is
black\n");}
  else if (defendcolor == white) {printf("attacking is black, defending is
white\n");}
  else { printf("see, impossible\n"); return(0); }
  if (attackcolor == white) {
    for (i = 0; i < de1; i++)
      defender[i] = -defender[i];
  } else {
    for (i = 0; i < at1; i++)
      attacker[i] = -attacker[i];
  }
#endif
  // next figure, from the back of the att/def arrays to the front
  for (;;)
    {
      if (de1 > 0)
	{
	  gain = gain + stm*mat_value[attacker[at1-1]+6];
	  swap_score[counter] = gain;
	  stm = -stm;
	  counter++;
	  at1--;
	}
      else
	break;  // no more defenders

      if (at1 > 0)
	{
	  gain = gain + stm*mat_value[defender[de1-1]+6];
	  swap_score[counter] = gain;
	  stm = -stm;
	  counter++;
	  de1--;
	}
      else
	break;     // no more attackers
    }

  // minimax through swap_scores from back to top
  // back up swap_scores if there is  a gain, else stand pat
  stm = -stm;
  counter--;
  while(counter)
    {
      if (stm < 0)
	{
	  if(swap_score[counter] <= swap_score[counter-1])
	    swap_score[counter-1] = swap_score[counter];        // else stand pat
	}
      else
	{
	  if(swap_score[counter] >= swap_score[counter-1])
	    swap_score[counter-1] = swap_score[counter];       // else stand pat
	}
      counter--;
      stm = -stm;
    }

  return (swap_score[0]);
}



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.