Ponder

Discussion of chess software programming and technical issues.

Moderator: Ras

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

Re: Ponder

Post by outAtime »

Thanks! Actually, Ive given up on that approach for now and am just struggling to figure out how to get it to ponder deeper than 3 ply.
In .search I have:

Code: Select all

 #ifndef ANSI
    if (xb_mode && bioskey ()) {
      time_exit = TRUE;
      return 0;
    }
    #endif
which seems connected to this in .utils

Code: Select all


#ifndef ANSI

#ifndef WIN32

int bioskey (void) {

  fd_set readfds;

  FD_ZERO (&readfds);
  FD_SET (fileno (stdin), &readfds);
  tv.tv_sec=0; tv.tv_usec=0;
  select (16, &readfds, 0, 0, &tv);

  return (FD_ISSET (fileno (stdin), &readfds));

}

#else

#undef frame
#include <windows.h>
#define frame 0

int bioskey (void) {

  static int init = 0, pipe;
  static HANDLE inh;
  DWORD dw;

  if (!init) {
    init = 1;
    inh = GetStdHandle (STD_INPUT_HANDLE);
    pipe = !GetConsoleMode (inh, &dw);
    if (!pipe) {
      SetConsoleMode(inh, dw & ~(ENABLE_MOUSE_INPUT|ENABLE_WINDOW_INPUT));
      FlushConsoleInputBuffer (inh);
    }
  }
  if (pipe) {
    if (!PeekNamedPipe (inh, NULL, 0, NULL, &dw, NULL)) {
      return 1;
    }
    return dw;
  } else {
    GetNumberOfConsoleInputEvents (inh, &dw);
    return dw <= 1 ? 0 : dw;
  }

  return (0);

}

#endif

#endif

and im trying to get it to work with this code, which has the interrupt:

Code: Select all

int interrupt(void)
{
  int c;

#ifdef HAVE_SELECT
  FD_ZERO(&read_fds);
  FD_SET(0,&read_fds);
  tv.tv_sec = tv.tv_usec = 0;
  select(1,&read_fds,NULL,NULL,&tv);
  if(FD_ISSET(0,&read_fds)) 
    {
      c = getc(stdin);

      if (c == '?')   /*Move now*/
	{
	  return 1;
	}
      else if (c == '.')     /* Stat request */
	{
	  getc(stdin);
	  post_stat_thinking();
	  return 0;
	}

      ungetc(c, stdin);

      if (!is_pondering && (Variant == Bughouse || Variant == Crazyhouse)) return 0; 

      return 1;
    }
  else return 0;
#else 
#ifdef _WIN32
  static int init = 0, pipe;
  static HANDLE inh;
  DWORD dw;
  if(xb_mode) {     // winboard interrupt code taken from crafty
    if (!init) {
      init = 1;
      inh = GetStdHandle(STD_INPUT_HANDLE);
      pipe = !GetConsoleMode(inh, &dw);
      if (!pipe) {
	SetConsoleMode(inh, dw & ~(ENABLE_MOUSE_INPUT|ENABLE_WINDOW_INPUT));
	FlushConsoleInputBuffer(inh);
	FlushConsoleInputBuffer(inh);
      }
    }
    if(pipe) {
      if(!PeekNamedPipe(inh, NULL, 0, NULL, &dw, NULL)) 
	{
	  c = getc(stdin);

	  if (c == '?')   /*Move now*/
	    {
	      return 1;
	    }
	  else if (c == '.')     /* Stat request */
	    {
	      getc(stdin);
	      post_stat_thinking();
	      return 0;
	    }
	  
	  ungetc(c, stdin);
	  
	  if (!is_pondering && (Variant == Bughouse || Variant == Crazyhouse)) return 0; 
	  
	  return 1;
	}
      if (dw)
	{
	  c = getc(stdin);
	  
	  if (c == '?')   /*Move now*/
	    {
	      return 1;
	    }
	  else if (c == '.')     /* Stat request */
	    {
	      getc(stdin);
	      post_stat_thinking();
	      return 0;
	    }
	  
	  ungetc(c, stdin);
	  
	  if (!is_pondering && (Variant == Bughouse || Variant == Crazyhouse)) return 0; 
	  
	  return 1;
	}
      else return 0;
    } else {
      GetNumberOfConsoleInputEvents(inh, &dw);
      if (dw <= 1)
	{ 
	  return 0; 
	}
      else 
	{ 
	  c = getc(stdin);

	  if (c == '?')   /*Move now*/
	    {
	      return 1;
	    }
	  else if (c == '.')     /* Stat request */
	    {
	      getc(stdin);
	      post_stat_thinking();
	      return 0;
	    }
	  
	  ungetc(c, stdin);
	  
	  if (!is_pondering && (Variant == Bughouse || Variant == Crazyhouse)) return 0; 
	  
	  return 1;
	};
    }
  }
#else
#endif
#endif

  return 0;
}
So far Im considering removing the bioskey() in search again, but obviously at this point its really hit and miss...plenty of broken versions so far...I did manage to get one which would only ponder and never stop though, and that was after removing bioskey() last time.
outAtime
outAtime
Posts: 226
Joined: Sun Mar 08, 2009 3:08 pm
Location: Canada

Re: Ponder

Post by outAtime »

I cant find that code, if there is any :(
outAtime
outAtime
Posts: 226
Joined: Sun Mar 08, 2009 3:08 pm
Location: Canada

Re: Ponder

Post by outAtime »

I dont know what to do, everything so far has failed. Any suggestions? I just cant figure out what is stopping it.
outAtime
Sven
Posts: 4052
Joined: Thu May 15, 2008 9:57 pm
Location: Berlin, Germany
Full name: Sven Schüle

Re: Ponder

Post by Sven »

outAtime wrote:I dont know what to do, everything so far has failed. Any suggestions? I just cant figure out what is stopping it.
Do you check for availability of input every N nodes?

If so, how many nodes have been searched when your pondering stops?

It might be possible that you stop by accident when checking for input for the very first time, which means that your checking function always returns "yes, there is input available" even if there isn't any.

Just one possible reason that comes into my mind.

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

Re: Ponder

Post by outAtime »

Well, it's quite interesting, although I haven't figured it out yet. I ran some test games and found that sometimes (rarely) it will ponder to greater depths. That was during a 15 0 game. havent seen it ponder deeply in a 3 0 or 5 0 yet tho. Im just getting started at it again today, so hopefully I can get it running fully.
outAtime
outAtime
Posts: 226
Joined: Sun Mar 08, 2009 3:08 pm
Location: Canada

Re: Ponder

Post by outAtime »

Ok, I just posted a bunch of code, but removed it after trying an experiment. I would like to know what you guys think: I changed mindepth to 10 , and now it appears to ponder at every move. When mindepth was set to 3 , it always stopped at three. It appears to be trying for 10 at every move now, although not always successful. Im a bit confused and wondering how this is working exactly. I'd like to know if this is a useful ponder, or if everything is just getting cleared after ponder. hmmm.
outAtime
outAtime
Posts: 226
Joined: Sun Mar 08, 2009 3:08 pm
Location: Canada

Re: Ponder

Post by outAtime »

hgm wrote:Are you sure you disabled the code that makes the search stop on timeout, during ponder? (Or, alternatively, give it a generous new time allotment?)

Could be that on the first time it checks the clock, it thinks it is already out of time, because it is still applying the standards of the previous search.
I came back to this comment after realizing making mindepth larger was simply wrong and added to the search:

Code: Select all

 /* allocate our time for this move: */
  if (!is_pondering)
     {
  time_for_move = allocate_time ();
     }
     else
     {
       time_for_move = 999999;
  }  
With that added it now compiles perfectly and ponders on every move as expected! :) I will run some tests tonight.
outAtime