Phalanx source code

Discussion of anything and everything relating to chess playing software and machines.

Moderators: hgm, Rebel, chrisw

stevenaaus
Posts: 608
Joined: Wed Oct 13, 2010 9:44 am
Location: Australia

Re: Phalanx source code

Post by stevenaaus »

Anyway - i've updated the Phalanx homepage , including Jims zip archive and a note about it's status. The short of it is both versions have bugs :(
http://phalanx.sourceforge.net/

I'd recommend using JA's for Windows hosted tournaments and Andoid of course.

Josh - perhaps try passing this arg "-p+" , or ensuring ponder/"hard" is enabled. I don't think it plays well at per-move time controls, but seems to go ok for me otherwise.
User avatar
lucasart
Posts: 3232
Joined: Mon May 31, 2010 1:29 pm
Full name: lucasart

Re: Phalanx source code

Post by lucasart »

stevenaaus wrote:Jim is right. Moreover, i spent hours looking for win32 polling code on the web, and it doesn't seem to exist
Yes it does. Here's my code from DiscoCheck 3.7.1 (POSIX and Windows)

Code: Select all

#if defined(_WIN32) || defined(_WIN64)
	#include <windows.h>
	#include <conio.h>
#else	// assume POSIX
	#include <errno.h>
	#include <unistd.h>
	#include <sys/time.h>
#endif

...

bool input_available&#40;)
&#123;
#if defined&#40;_WIN32&#41; || defined&#40;_WIN64&#41;

	static bool init = false, is_pipe;
	static HANDLE stdin_h;
	DWORD val;
	
	if (!init&#41; &#123;
		init = true;
		stdin_h = GetStdHandle&#40;STD_INPUT_HANDLE&#41;;
		is_pipe = !GetConsoleMode&#40;stdin_h, &val&#41;;
	&#125;

	if &#40;stdin->_cnt > 0&#41;
		return true;
	
	if &#40;is_pipe&#41;
		return !PeekNamedPipe&#40;stdin_h, NULL, 0, NULL, &val, NULL&#41; ? true &#58; val>0;
	else
		return _kbhit&#40;);
	
#else	// assume POSIX
	
	fd_set readfds;
	FD_ZERO&#40;&readfds&#41;;
	FD_SET&#40;STDIN_FILENO, &readfds&#41;;
	
	struct timeval timeout;	
	timeout.tv_sec = timeout.tv_usec = 0;
	
	select&#40;STDIN_FILENO+1, &readfds, 0, 0, &timeout&#41;;
	return FD_ISSET&#40;STDIN_FILENO, &readfds&#41;;
#endif
&#125;
stevenaaus
Posts: 608
Joined: Wed Oct 13, 2010 9:44 am
Location: Australia

Re: Phalanx source code

Post by stevenaaus »

Thanks Lucas. Yes - Jim had found this code and (a slight variation of) it is in phalanx subversion - but we have related bug somewhere else in the code.

When one makes a move in Scid/Scid vs PC with the "+" sign, the engine does not see the updated line/the IO is not working properly, and Phalanx continues to give PV for the old position. .. This bug is described in this thread somewhere above.

I'm not an engine programmer or win32 coder and i don't have a windows dev environement (i cross compile), so finding it is tough for me.

I just tried applying your slightly different code (patch) and it doesn't make any diff to phalanx.

And i just gave Discocheck 3.6.2 a quick cross compile,
but it works fine, and doesn't evidence our bug.

Diff for Lucas implementation (no change)

Code: Select all

--- evaluate.c  2012-08-30 18&#58;05&#58;44.000000000 +1000
+++ evaluate.c.lucas    2012-08-30 18&#58;05&#58;39.000000000 +1000
@@ -305,9 +305,6 @@
    /* If we're running under XBoard then we can't use _kbhit&#40;) as the input commands
     * are sent to us directly over the internal pipe */
   if &#40;Flag.xboard&#41; &#123;
-#if defined&#40;FILE_CNT&#41;
-    if &#40;stdin->_cnt > 0&#41; return stdin->_cnt;
-#endif
     if (!init&#41; &#123;
       init = 1;
       inh = GetStdHandle&#40;STD_INPUT_HANDLE&#41;;
@@ -317,13 +314,17 @@
         FlushConsoleInputBuffer&#40;inh&#41;;
       &#125;
     &#125;
+
+    if &#40;stdin->_cnt > 0&#41; return stdin->_cnt;
+
     if &#40;pipe&#41; &#123;
       if (!PeekNamedPipe&#40;inh, NULL, 0, NULL, &dw, NULL&#41;) return 1;
       return dw;
     &#125;
     else &#123;
-      GetNumberOfConsoleInputEvents&#40;inh, &dw&#41;;
-      return dw <= 1 ? 0 &#58; dw;
+      return _kbhit&#40;);
+      // GetNumberOfConsoleInputEvents&#40;inh, &dw&#41;;
+      // return dw <= 1 ? 0 &#58; dw;
     &#125;
   &#125;
   else return _kbhit&#40;);
Existing phalanx win32-only bug:

Code: Select all

These four commands don't reset the analysis under windows, though they are fine under Linux

Engine&#58; 8 -1 91 384451 Pf5xe4 Pd2-d4 Ng8-f6
Engine&#58; 9 1 233 919440 Pf5xe4 Pd2-d3 Ng8-f6 Pd3xe4 Pe7-e6 Bc1-g5 Ph7-h6 Bg5xf6 Qd8xf6 Nb1-c3 Bf8-a3
Engine&#58; 9 1 350 1357705 Pf5xe4 Pd2-d3 Ng8-f6 Pd3xe4 Pe7-e6 Bc1-g5 Ph7-h6 Bg5xf6 Qd8xf6 Nb1-c3 Bf8-a3
Scid &#58; exit
Scid &#58; force
Scid &#58; setboard rnbqkbnr/ppppp1pp/8/8/4p3/7P/PPPP1PP1/RNBQKBNR w KQkq - 0 3
Scid &#58; analyze
Engine&#58; 10 10 712 3127860 Pf5xe4 Pd2-d3 Pe4xd3 Bf1xd3 Ng8-f6 Ng1-f3 Nb8-c6 O-O Pd7-d5 Bc1-f4 Pe7-e6
Engine&#58; 10 10 937 3885625 Pf5xe4 Pd2-d3 Pe4xd3 Bf1xd3 Ng8-f6 Ng1-f3 Nb8-c6 O-O Pd7-d5 Bc1-f4 Pe7-e6
stevenaaus
Posts: 608
Joined: Wed Oct 13, 2010 9:44 am
Location: Australia

Re: Phalanx source code

Post by stevenaaus »

Ok - the cause of the bug is some issue with the "interrupt" proc.

Code: Select all

void interrupt&#40;int x&#41;
&#123;
        int c;
        signal&#40;SIGINT,SIG_IGN&#41;;
        
        if&#40; Flag.polling )
        &#123;
        /* ignore lines that begin with '.' */
        c=getc&#40;stdin&#41;; ungetc&#40;c,stdin&#41;;
        if&#40; c=='.' ) &#123; fgets&#40;Inp,255,stdin&#41;; goto go_on; &#125;
        &#125;

        if&#40; Flag.ponder < 2 )
        &#123;
                puts&#40;"interrupted");
                Abort = 1;
                goto go_on;
        &#125;
        while&#40; command&#40;) ) &#123;&#125;

        go_on&#58;;
        if&#40; !Abort && !Flag.polling )
#if defined&#40;_WIN32&#41;
        signal&#40;SIGINT, handleSigint&#41;;
#else
        signal&#40;SIGINT,interrupt&#41;;
#endif
&#125;
This proc is getting called in Linux, but not in WIN32.
I tried changing all Jim's "signal(SIGINT, handleSigint);" to "signal(SIGINT,interrupt);" but it didn't work, so i'm assuming that on WIN32, io.c::interrupt() is getting replaced by a system call.

Sorry, but i'm unfamiliar with the signal command. Any idea about fixing this. :?
UncombedCoconut
Posts: 319
Joined: Fri Dec 18, 2009 11:40 am
Location: Naperville, IL

Re: Phalanx source code

Post by UncombedCoconut »

The signal function just installs a signal handler. I was under the impression that this wasn't necessary for Windows engines.
stevenaaus
Posts: 608
Joined: Wed Oct 13, 2010 9:44 am
Location: Australia

Re: Phalanx source code

Post by stevenaaus »

UncombedCoconut wrote:The signal function just installs a signal handler. I was under the impression that this wasn't necessary for Windows engines.
Hmmm -
There are two reasons why WinBoard does not send the Win32 equivalent of SIGINT (which is called CTRL_C_EVENT) to local engines. First, the Win32 GNU Chess 4 port does not need it. Second, I could not find a way to get it to work. Win32 seems to be designed under the assumption that only console applications, not windowed applications, would ever want to send a CTRL_C_EVENT.
Sounds like this is applicable.

Anyway, Something in this patch of Jims (i think) makes the engine crash on windows 7, and i might revert it.
http://phalanx.svn.sourceforge.net/view ... evision=12

Also - i've updated the svn/webpage with some doco.
http://phalanx.sourceforge.net/