Need help to make Crafty work

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
phhnguyen
Posts: 1434
Joined: Wed Apr 21, 2010 4:58 am
Location: Australia
Full name: Nguyen Hong Pham

Need help to make Crafty work

Post by phhnguyen »

I am working to support Winboard protocol for my chess tool (Banksia - a chess tournament manager) and testing with Crafty (version 23.6, compiled by XCode for MacOS). However, that engine runs so weirdly with my chess tool and losing many test games because of making illegal moves or timeout. I guess my app did something wrong when controlling Crafty.

Bellow is a typical (and sort) log file. Can someone check if there is any wrong on controlling? Why Crafty refused command "cores" and "memory" (it made a warning of disabling)? Why did it produce 2 moves in which an illegal move "move e4" first before the right one "move h3"? (note that my app has sent redundant commands "force" to Crafty to avoid it starts computing unattended).

Any similar experience and/or solution?
Thanks

Code: Select all

12:49:00 banksia> 
1. scorpio vs crafty

12:49:00 scorpio< xboard
protover 2
12:49:00 crafty< xboard
protover 2
12:49:00 scorpio> feature done=0
12:49:00 scorpio> Scorpio.ini not found!
12:49:00 scorpio> feature name=1 myname="Scorpio_2.7.7"
12:49:00 scorpio< accepted name
12:49:00 scorpio< accepted myname
12:49:00 scorpio> feature sigint=0 sigterm=0
12:49:00 scorpio< accepted sigint
12:49:00 scorpio> feature setboard=1 draw=0 colors=0
12:49:00 scorpio< accepted setboard
12:49:00 scorpio< accepted draw
12:49:00 scorpio> feature smp=0 memory=0
12:49:00 scorpio< accepted smp
12:49:00 scorpio> feature option="log -check 0"
12:49:00 scorpio> feature option="clear_hash -button"
12:49:00 scorpio> feature option="resign -spin 600 100 30000"
12:49:00 scorpio> feature option="cores -spin 1 1 32"
12:49:00 scorpio> feature option="ht -spin 64 1 32768"
12:49:00 scorpio> feature option="eht -spin 8 1 16384"
12:49:00 scorpio> feature option="pht -spin 1 1 256"
12:49:00 scorpio> feature option="egbb_path -path egbb/"
12:49:00 scorpio> feature option="egbb_cache_size -spin 16 1 16384"
12:49:00 scorpio> feature option="egbb_load_type -spin 1 0 3"
12:49:00 scorpio> feature option="egbb_depth_limit -spin 3 0 64"
12:49:00 scorpio> feature option="egbb_ply_limit_percent -spin 75 0 100"
12:49:00 scorpio> feature option="smp_type -combo *YBW /// ABDADA /// SHT "
12:49:00 scorpio> feature option="smp_depth -spin 4 1 10"
12:49:00 scorpio> feature option="use_singular -check 0"
12:49:00 scorpio> feature option="singular_margin -spin 30 0 1000"
12:49:00 scorpio> feature option="futility_margin -spin 100 0 1000"
12:49:00 scorpio> feature option="contempt -spin 2 -100 100"
12:49:00 scorpio> feature done=1
12:49:00 crafty> EPD Kit revision date: 1996.04.21
12:49:00 crafty> unable to open book file [./book.bin].
12:49:00 crafty> book is disabled
12:49:00 crafty> unable to open book file [./books.bin].
12:49:00 crafty> Crafty v23.6 (1 cpus)
12:49:00 crafty> White(1):
12:49:00 crafty> tellicsnoalias set 1 Crafty v23.6 (1 cpus)
12:49:00 crafty> tellicsnoalias kibitz Hello from Crafty v23.6! (1 cpus)
12:49:00 crafty> feature ping=1 setboard=1 san=1 time=1 draw=1
12:49:00 crafty< accepted ping
12:49:00 crafty< accepted setboard
12:49:00 crafty< accepted san
12:49:00 crafty< accepted time
12:49:00 crafty> feature sigint=0 sigterm=0 reuse=1 analyze=1
12:49:00 crafty< accepted sigint
12:49:00 crafty< accepted sigterm
12:49:00 crafty< accepted reuse
12:49:00 crafty> feature myname="Crafty-23.6" name=1
12:49:00 crafty< accepted myname
12:49:00 crafty> feature playother=1 colors=0 memory=1
12:49:00 crafty< accepted playother
12:49:00 crafty< accepted colors
12:49:00 crafty> feature smp=1
12:49:00 crafty> feature variants="normal,nocastle"
12:49:00 crafty< accepted variants
12:49:00 crafty> feature done=1
12:49:02 crafty< force
12:49:02 crafty< cores 1
memory 1
12:49:02 crafty> Warning--  xboard 'cores' option disabled
12:49:02 crafty< easy
12:49:02 crafty> Warning--  xboard 'memory' option disabled
12:49:02 crafty< post
12:49:02 crafty< new
12:49:02 crafty< variant normal
12:49:02 crafty< force
12:49:02 crafty< setboard rnb1kb1r/1p3p2/p3pP1p/8/3N3p/q1N5/P1PQB1PP/1R2K2R b Kkq - 0 1
12:49:02 scorpio< force
12:49:02 scorpio< easy
12:49:02 scorpio< post
12:49:02 scorpio< new
12:49:02 scorpio< force
12:49:02 scorpio< setboard rnb1kb1r/1p3p2/p3pP1p/8/3N3p/q1N5/P1PQB1PP/1R2K2R b Kkq - 0 1
12:49:02 crafty> tellicsnoalias set 1 Crafty v23.6 (1 cpus)
12:49:02 crafty< level 40 0:20 0
12:49:02 crafty> command=[variant normal]
12:49:02 crafty< go
12:49:02 crafty> 12     10       7 253095  1. Nf3
12:49:02 crafty> 13     26      10 336316  1. Nf3!
12:49:02 crafty> 13     24      11 364343  1. Nf3 Nf6 2. Nc3 e6 3. e4 Nc6 4. e5 Ng4 5. d4 Bb4 6. Ng5 f5 7. Bb5
12:49:02 crafty> 13     25      11 547120  1. e4!
12:49:02 crafty> 13     25      17 590979  1. e4
12:49:02 crafty> 14     16      24 818816  1. e4 Nc6 2. Nf3 Nf6 3. Nc3 e5 4. d4 exd4 5. Nxd4 Bc5 6. Nxc6 bxc6 7. e5 Qe7
12:49:02 crafty> 14     16      31 1020505  1. e4 Nc6 2. Nf3 Nf6 3. Nc3 e5 4. d4 exd4 5. Nxd4 Bc5 6. Nxc6 bxc6 7. e5 Qe7
12:49:02 crafty> move e4
12:49:02 banksia> Illegal move e4 from crafty
12:49:02 crafty< force
12:49:02 scorpio< force
12:49:02 crafty> 9    -48       4 279862  1. ... Rg8!
12:49:02 crafty> 9    -50       7 310178  1. ... Rg8 2. O-O Bc5 3. Bf3 e5 4. Rfe1 Nd7 5. Bd5 h3
12:49:02 crafty> 9    -51       7 340645  1. ... Bc5!
12:49:02 crafty> 9    -52       7 426910  1. ... h3!
12:49:02 crafty> move h3
12:49:02 banksia> 1) scorpio vs crafty: 1-0 (illegal move)
12:49:03 crafty< quit
12:49:03 scorpio< quit

https://banksiagui.com
The most features chess GUI, based on opensource Banksia - the chess tournament manager
User avatar
hgm
Posts: 27788
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Need help to make Crafty work

Post by hgm »

I see several irregularities in the log:

* The 'variant' command is usually only sent for variants != normal, as the 'new' command already switches the variant to 'normal'. Not all engines might therefore recognize 'normal' as argument of the 'variant' command.
* Banksia sends a 'cores' command, but Crafty did not specify 'feature cores=1', and default is 'cores=0'.
* Banksia did not send a 'memory' command, even though Crafty did send 'feature memory=1'. It is a bit dangerous to rely on an engine's default setting for the hash side; it might be very small.
* Crafty seems to have ignored the setboard command completely.

A possible explanation is that Crafty sloppily implements the 'variant' command as a switch to 'nocastle' without looking at the argument (as it is the only variant it supports beside 'normal'), and has a pedantic FEN reader that chockes on a FEN with castling rights in that case, ignoring the FEN altogether and replacing it by the default initial position. This is not very likely, though; probably the support of 'nocastle' is mentioned only because it is not really a variant, and is automatically supported by any engine that allows setting up arbitrary positions. I don't expect any extra code would have been added to support it, and that the 'variant' command is completely ignored.
Ras
Posts: 2487
Joined: Tue Aug 30, 2016 8:19 pm
Full name: Rasmus Althoff

Re: Need help to make Crafty work

Post by Ras »

hgm wrote: Mon Jul 08, 2019 9:30 am* Banksia sends a 'cores' command, but Crafty did not specify 'feature cores=1'
Does it have to? From http://hgm.nubati.net/CECP.html :
cores N
Specifies the engine can use at most N search threads in is parallel search. Only sent when the engine requested it through feature smp=1.
And from the log:

Code: Select all

12:49:00 crafty> feature smp=1
From the Crafty code, the only match for that warning:

Code: Select all

 else if (OptionMatch("smpmt", *args) || OptionMatch("mt", *args)
      || OptionMatch("cores", *args)) {
    int proc;

    if (nargs < 2) {
      printf("usage:  smpmt=<threads>\n");
      return (1);
    }
    if (thinking || pondering)
      return (3);
    allow_cores = 0;
    Print(4095, "Warning--  xboard 'cores' option disabled\n");
    smp_max_threads = atoi(args[1]);
    if (smp_max_threads > CPUS) {
      Print(4095, "ERROR - Crafty was compiled with CPUS=%d.", CPUS);
      Print(4095, "  mt can not exceed this value.\n");
      smp_max_threads = CPUS;
    }
    if (smp_max_threads)
      Print(128, "max threads set to %d.\n", smp_max_threads);
    else
      Print(128, "parallel threads disabled.\n");
    for (proc = 1; proc < CPUS; proc++)
      if (proc >= smp_max_threads)
        thread[proc] = (TREE *) - 1;
  } 
So the cores option will be evaluated, and the warning will always appear. Instead, the paramater will be interpreted as threads. This is probably what Banksia intended anyway. There is no "max threads set to X" message because the verbosity parameter is 128, and it seems that unlike 4095, this is not active at this point.

It looks like the observed warning will always appear if you set any multithreading, but doesn't really indicate a problem.
* Banksia did not send a 'memory' command
It did:

Code: Select all

12:49:02 crafty< cores 1
memory 1
And this is the reason for the warning, which is also spurious. Crafty usually issues the memory warning if you set the main hash table or the pawn hash table directly with 'hash' / 'hashp', see options.c. Now if you issue 'memory', then this will be remapped to 'hash' / 'hashp' so that you always will see two (!) memory warnings. Except if the memory is an exact power of two, in which case no memory will be allocated for the pawn hash table at all, that's why you see only one warning:

Code: Select all

    size = atoi(args[1]) * 1024 * 1024;
    hmemory = (1ull) << MSB(size);
    size &= ~hmemory;
    pmemory = (1ull) << MSB(size);
    if (pmemory < 1024 * 1024)
      pmemory = 0;
The variant isn't really evaluated in Crafty:

Code: Select all

  else if (OptionMatch("variant", *args)) {
    if (thinking || pondering)
      return (2);
    printf("command=[%s]\n", buffer);
    return (-1);
  }
I think a promising trace is Crafty's answer

Code: Select all

12:49:02 crafty> command=[variant normal]
12:49:02 crafty< go
That refers to a command from before the setboard command. I think there is a race condition happening here. Crafty gets the "go" before it has processed "setboard", and then Crafty is still in the initial position, that's why it comes up with e4 as move. Later, when it has processed "setboard", it answers with proper moves.

That's a synchronisation issue, and CECP has a way to solve that which Crafty supports:

Code: Select all

12:49:00 crafty> feature ping=1 setboard=1 san=1 time=1 draw=1
12:49:00 crafty< accepted ping
Conclusion: Banksia should use the ping/pong mechanism before issueing the "go" command.
Rasmus Althoff
https://www.ct800.net
User avatar
MikeB
Posts: 4889
Joined: Thu Mar 09, 2006 6:34 am
Location: Pen Argyl, Pennsylvania

Re: Need help to make Crafty work

Post by MikeB »

phhnguyen wrote: Mon Jul 08, 2019 5:27 am I am working to support Winboard protocol for my chess tool (Banksia - a chess tournament manager) and testing with Crafty (version 23.6, compiled by XCode for MacOS). However, that engine runs so weirdly with my chess tool and losing many test games because of making illegal moves or timeout. I guess my app did something wrong when controlling Crafty.

Bellow is a typical (and sort) log file. Can someone check if there is any wrong on controlling? Why Crafty refused command "cores" and "memory" (it made a warning of disabling)? Why did it produce 2 moves in which an illegal move "move e4" first before the right one "move h3"? (note that my app has sent redundant commands "force" to Crafty to avoid it starts computing unattended).

Any similar experience and/or solution?
Thanks

Code: Select all

12:49:00 banksia> 
1. scorpio vs crafty

12:49:00 scorpio< xboard
protover 2
12:49:00 crafty< xboard
protover 2
12:49:00 scorpio> feature done=0
12:49:00 scorpio> Scorpio.ini not found!
12:49:00 scorpio> feature name=1 myname="Scorpio_2.7.7"
12:49:00 scorpio< accepted name
12:49:00 scorpio< accepted myname
12:49:00 scorpio> feature sigint=0 sigterm=0
12:49:00 scorpio< accepted sigint
12:49:00 scorpio> feature setboard=1 draw=0 colors=0
12:49:00 scorpio< accepted setboard
12:49:00 scorpio< accepted draw
12:49:00 scorpio> feature smp=0 memory=0
12:49:00 scorpio< accepted smp
12:49:00 scorpio> feature option="log -check 0"
12:49:00 scorpio> feature option="clear_hash -button"
12:49:00 scorpio> feature option="resign -spin 600 100 30000"
12:49:00 scorpio> feature option="cores -spin 1 1 32"
12:49:00 scorpio> feature option="ht -spin 64 1 32768"
12:49:00 scorpio> feature option="eht -spin 8 1 16384"
12:49:00 scorpio> feature option="pht -spin 1 1 256"
12:49:00 scorpio> feature option="egbb_path -path egbb/"
12:49:00 scorpio> feature option="egbb_cache_size -spin 16 1 16384"
12:49:00 scorpio> feature option="egbb_load_type -spin 1 0 3"
12:49:00 scorpio> feature option="egbb_depth_limit -spin 3 0 64"
12:49:00 scorpio> feature option="egbb_ply_limit_percent -spin 75 0 100"
12:49:00 scorpio> feature option="smp_type -combo *YBW /// ABDADA /// SHT "
12:49:00 scorpio> feature option="smp_depth -spin 4 1 10"
12:49:00 scorpio> feature option="use_singular -check 0"
12:49:00 scorpio> feature option="singular_margin -spin 30 0 1000"
12:49:00 scorpio> feature option="futility_margin -spin 100 0 1000"
12:49:00 scorpio> feature option="contempt -spin 2 -100 100"
12:49:00 scorpio> feature done=1
12:49:00 crafty> EPD Kit revision date: 1996.04.21
12:49:00 crafty> unable to open book file [./book.bin].
12:49:00 crafty> book is disabled
12:49:00 crafty> unable to open book file [./books.bin].
12:49:00 crafty> Crafty v23.6 (1 cpus)
12:49:00 crafty> White(1):
12:49:00 crafty> tellicsnoalias set 1 Crafty v23.6 (1 cpus)
12:49:00 crafty> tellicsnoalias kibitz Hello from Crafty v23.6! (1 cpus)
12:49:00 crafty> feature ping=1 setboard=1 san=1 time=1 draw=1
12:49:00 crafty< accepted ping
12:49:00 crafty< accepted setboard
12:49:00 crafty< accepted san
12:49:00 crafty< accepted time
12:49:00 crafty> feature sigint=0 sigterm=0 reuse=1 analyze=1
12:49:00 crafty< accepted sigint
12:49:00 crafty< accepted sigterm
12:49:00 crafty< accepted reuse
12:49:00 crafty> feature myname="Crafty-23.6" name=1
12:49:00 crafty< accepted myname
12:49:00 crafty> feature playother=1 colors=0 memory=1
12:49:00 crafty< accepted playother
12:49:00 crafty< accepted colors
12:49:00 crafty> feature smp=1
12:49:00 crafty> feature variants="normal,nocastle"
12:49:00 crafty< accepted variants
12:49:00 crafty> feature done=1
12:49:02 crafty< force
12:49:02 crafty< cores 1
memory 1
12:49:02 crafty> Warning--  xboard 'cores' option disabled
12:49:02 crafty< easy
12:49:02 crafty> Warning--  xboard 'memory' option disabled
12:49:02 crafty< post
12:49:02 crafty< new
12:49:02 crafty< variant normal
12:49:02 crafty< force
12:49:02 crafty< setboard rnb1kb1r/1p3p2/p3pP1p/8/3N3p/q1N5/P1PQB1PP/1R2K2R b Kkq - 0 1
12:49:02 scorpio< force
12:49:02 scorpio< easy
12:49:02 scorpio< post
12:49:02 scorpio< new
12:49:02 scorpio< force
12:49:02 scorpio< setboard rnb1kb1r/1p3p2/p3pP1p/8/3N3p/q1N5/P1PQB1PP/1R2K2R b Kkq - 0 1
12:49:02 crafty> tellicsnoalias set 1 Crafty v23.6 (1 cpus)
12:49:02 crafty< level 40 0:20 0
12:49:02 crafty> command=[variant normal]
12:49:02 crafty< go
12:49:02 crafty> 12     10       7 253095  1. Nf3
12:49:02 crafty> 13     26      10 336316  1. Nf3!
12:49:02 crafty> 13     24      11 364343  1. Nf3 Nf6 2. Nc3 e6 3. e4 Nc6 4. e5 Ng4 5. d4 Bb4 6. Ng5 f5 7. Bb5
12:49:02 crafty> 13     25      11 547120  1. e4!
12:49:02 crafty> 13     25      17 590979  1. e4
12:49:02 crafty> 14     16      24 818816  1. e4 Nc6 2. Nf3 Nf6 3. Nc3 e5 4. d4 exd4 5. Nxd4 Bc5 6. Nxc6 bxc6 7. e5 Qe7
12:49:02 crafty> 14     16      31 1020505  1. e4 Nc6 2. Nf3 Nf6 3. Nc3 e5 4. d4 exd4 5. Nxd4 Bc5 6. Nxc6 bxc6 7. e5 Qe7
12:49:02 crafty> move e4
12:49:02 banksia> Illegal move e4 from crafty
12:49:02 crafty< force
12:49:02 scorpio< force
12:49:02 crafty> 9    -48       4 279862  1. ... Rg8!
12:49:02 crafty> 9    -50       7 310178  1. ... Rg8 2. O-O Bc5 3. Bf3 e5 4. Rfe1 Nd7 5. Bd5 h3
12:49:02 crafty> 9    -51       7 340645  1. ... Bc5!
12:49:02 crafty> 9    -52       7 426910  1. ... h3!
12:49:02 crafty> move h3
12:49:02 banksia> 1) scorpio vs crafty: 1-0 (illegal move)
12:49:03 crafty< quit
12:49:03 scorpio< quit

I would grab the latest "official" crafty 25.2. If you don't have one, I can send you you one, does your CPU support bmi2 , if not I will send you a popcnt version/

If you prefer to compile your self, here's the last official source. 25.3 only added a rudimentary play by Elo option and is not official.

https://github.com/MichaelB7/Crafty/com ... fa1c13875f

There is a macOS binary here - may or may not work.

https://github.com/MichaelB7/Crafty/com ... 33e43a5fd6

Good luck!

PS, FWIW Crafty 25.2 works fine under xBoard for me.
Image
User avatar
phhnguyen
Posts: 1434
Joined: Wed Apr 21, 2010 4:58 am
Location: Australia
Full name: Nguyen Hong Pham

Re: Need help to make Crafty work

Post by phhnguyen »

hgm wrote: Mon Jul 08, 2019 9:30 am I see several irregularities in the log:

* The 'variant' command is usually only sent for variants != normal, as the 'new' command already switches the variant to 'normal'. Not all engines might therefore recognize 'normal' as argument of the 'variant' command.
* Banksia sends a 'cores' command, but Crafty did not specify 'feature cores=1', and default is 'cores=0'.
* Banksia did not send a 'memory' command, even though Crafty did send 'feature memory=1'. It is a bit dangerous to rely on an engine's default setting for the hash side; it might be very small.
* Crafty seems to have ignored the setboard command completely.

A possible explanation is that Crafty sloppily implements the 'variant' command as a switch to 'nocastle' without looking at the argument (as it is the only variant it supports beside 'normal'), and has a pedantic FEN reader that chockes on a FEN with castling rights in that case, ignoring the FEN altogether and replacing it by the default initial position. This is not very likely, though; probably the support of 'nocastle' is mentioned only because it is not really a variant, and is automatically supported by any engine that allows setting up arbitrary positions. I don't expect any extra code would have been added to support it, and that the 'variant' command is completely ignored.
Thanks for the reply.

From your info, I suspected the command "variant normal" is the main problem for Crafty. I guess because of that command Crafty does a serious initializing for a while thus it may auto start searching immediately and/or miss commands setboard and force which Banksia sends right after.

I have changed and tested by two ways:
- Send "variant normal" a bit earlier. The previous commands are: force - new - variant - setboard - force (I followed your document "Optionally sent to the engine immediately after 'new'"), now changed into: force - variant - new - setboard - force
- Discard sending variant

I have tested both ways for the whole night and look like they work well: So far none of Crafty games has illegal moves
https://banksiagui.com
The most features chess GUI, based on opensource Banksia - the chess tournament manager
User avatar
phhnguyen
Posts: 1434
Joined: Wed Apr 21, 2010 4:58 am
Location: Australia
Full name: Nguyen Hong Pham

Re: Need help to make Crafty work

Post by phhnguyen »

Ras wrote: Mon Jul 08, 2019 10:09 pm
hgm wrote: Mon Jul 08, 2019 9:30 am* Banksia sends a 'cores' command, but Crafty did not specify 'feature cores=1'
Does it have to? From http://hgm.nubati.net/CECP.html :
cores N
Specifies the engine can use at most N search threads in is parallel search. Only sent when the engine requested it through feature smp=1.
And from the log:

Code: Select all

12:49:00 crafty> feature smp=1
From the Crafty code, the only match for that warning:

Code: Select all

 else if (OptionMatch("smpmt", *args) || OptionMatch("mt", *args)
      || OptionMatch("cores", *args)) {
    int proc;

    if (nargs < 2) {
      printf("usage:  smpmt=<threads>\n");
      return (1);
    }
    if (thinking || pondering)
      return (3);
    allow_cores = 0;
    Print(4095, "Warning--  xboard 'cores' option disabled\n");
    smp_max_threads = atoi(args[1]);
    if (smp_max_threads > CPUS) {
      Print(4095, "ERROR - Crafty was compiled with CPUS=%d.", CPUS);
      Print(4095, "  mt can not exceed this value.\n");
      smp_max_threads = CPUS;
    }
    if (smp_max_threads)
      Print(128, "max threads set to %d.\n", smp_max_threads);
    else
      Print(128, "parallel threads disabled.\n");
    for (proc = 1; proc < CPUS; proc++)
      if (proc >= smp_max_threads)
        thread[proc] = (TREE *) - 1;
  } 
So the cores option will be evaluated, and the warning will always appear. Instead, the paramater will be interpreted as threads. This is probably what Banksia intended anyway. There is no "max threads set to X" message because the verbosity parameter is 128, and it seems that unlike 4095, this is not active at this point.

It looks like the observed warning will always appear if you set any multithreading, but doesn't really indicate a problem.
* Banksia did not send a 'memory' command
It did:

Code: Select all

12:49:02 crafty< cores 1
memory 1
And this is the reason for the warning, which is also spurious. Crafty usually issues the memory warning if you set the main hash table or the pawn hash table directly with 'hash' / 'hashp', see options.c. Now if you issue 'memory', then this will be remapped to 'hash' / 'hashp' so that you always will see two (!) memory warnings. Except if the memory is an exact power of two, in which case no memory will be allocated for the pawn hash table at all, that's why you see only one warning:
Wow, thanks for your explanation. Good for my mind now. Lucky a typical user won't see those warning if he uses a GUI - he can play around and set up Crafty with any values.
Ras wrote: Mon Jul 08, 2019 10:09 pm

Code: Select all

    size = atoi(args[1]) * 1024 * 1024;
    hmemory = (1ull) << MSB(size);
    size &= ~hmemory;
    pmemory = (1ull) << MSB(size);
    if (pmemory < 1024 * 1024)
      pmemory = 0;
The variant isn't really evaluated in Crafty:

Code: Select all

  else if (OptionMatch("variant", *args)) {
    if (thinking || pondering)
      return (2);
    printf("command=[%s]\n", buffer);
    return (-1);
  }
I think a promising trace is Crafty's answer

Code: Select all

12:49:02 crafty> command=[variant normal]
12:49:02 crafty< go
That refers to a command from before the setboard command. I think there is a race condition happening here. Crafty gets the "go" before it has processed "setboard", and then Crafty is still in the initial position, that's why it comes up with e4 as move. Later, when it has processed "setboard", it answers with proper moves.

That's a synchronisation issue, and CECP has a way to solve that which Crafty supports:

Code: Select all

12:49:00 crafty> feature ping=1 setboard=1 san=1 time=1 draw=1
12:49:00 crafty< accepted ping
Conclusion: Banksia should use the ping/pong mechanism before issueing the "go" command.
Thanks again for the info and suggestion. I will try that.
https://banksiagui.com
The most features chess GUI, based on opensource Banksia - the chess tournament manager
User avatar
phhnguyen
Posts: 1434
Joined: Wed Apr 21, 2010 4:58 am
Location: Australia
Full name: Nguyen Hong Pham

Re: Need help to make Crafty work

Post by phhnguyen »

MikeB wrote: Mon Jul 08, 2019 10:45 pm I would grab the latest "official" crafty 25.2. If you don't have one, I can send you you one, does your CPU support bmi2 , if not I will send you a popcnt version/

If you prefer to compile your self, here's the last official source. 25.3 only added a rudimentary play by Elo option and is not official.

https://github.com/MichaelB7/Crafty/com ... fa1c13875f

There is a macOS binary here - may or may not work.

https://github.com/MichaelB7/Crafty/com ... 33e43a5fd6

Good luck!

PS, FWIW Crafty 25.2 works fine under xBoard for me.
Thanks!

I tried to download your macOS binary, but it displays "Binary file not shown."

I have downloaded the source code and try to compile it in my iMac. It is the first time I do that, thus I wish you have some quick help/document (for compiling). After searching a bit, I succeed by using command "make unix-gcc-profile" (I am not sure if it is the good one).

BTW, the binary of Crafty 25.3 runs well on my computer and I start using it for testing :D
https://banksiagui.com
The most features chess GUI, based on opensource Banksia - the chess tournament manager
User avatar
phhnguyen
Posts: 1434
Joined: Wed Apr 21, 2010 4:58 am
Location: Australia
Full name: Nguyen Hong Pham

Re: Need help to make Crafty work

Post by phhnguyen »

Ras wrote: Mon Jul 08, 2019 10:09 pm That refers to a command from before the setboard command. I think there is a race condition happening here. Crafty gets the "go" before it has processed "setboard", and then Crafty is still in the initial position, that's why it comes up with e4 as move. Later, when it has processed "setboard", it answers with proper moves.

That's a synchronisation issue, and CECP has a way to solve that which Crafty supports:

Code: Select all

12:49:00 crafty> feature ping=1 setboard=1 san=1 time=1 draw=1
12:49:00 crafty< accepted ping
Conclusion: Banksia should use the ping/pong mechanism before issueing the "go" command.
I felt interested in the issue and did some more test

Running Crafty (I tried both old version 23.6 and the new one 25.3) from the console, I copied and pasted (to mimic GUI):

Code: Select all

xboard
protocol 2
then:

Code: Select all

new
variant normal
force 
Crafty printed out instantly:

Code: Select all

move e4
Crafty did not obey both command "variant" (not auto start computing) nor "force" (stop computing without giving move).

I have tried to move up command "variant" early, wait for a while, ping/pong many times with Crafty in many places but all do not help: Crafty will sooner or later print out a move as responding for "variant". Look like Crafty has bugs on implementation, not only a race condition.
https://banksiagui.com
The most features chess GUI, based on opensource Banksia - the chess tournament manager
User avatar
phhnguyen
Posts: 1434
Joined: Wed Apr 21, 2010 4:58 am
Location: Australia
Full name: Nguyen Hong Pham

Re: Need help to make Crafty work

Post by phhnguyen »

MikeB wrote: Mon Jul 08, 2019 10:45 pm I would grab the latest "official" crafty 25.2.
Crafty 25 welcomes then "scares" me a bit by a warning when I enter command "new":

Code: Select all

unable to open book file [./book.bin].
book is disabled
unable to open book file [./books.bin].

Crafty v25.3

machine has 8 processors

White(1): new
NOTICE:  new command not implemented, please exit and
restart crafty to re-initialize everything for a new game
:roll:
https://banksiagui.com
The most features chess GUI, based on opensource Banksia - the chess tournament manager
User avatar
hgm
Posts: 27788
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Need help to make Crafty work

Post by hgm »

OK, I missed a few things, sorry about that. For one I only looked at lines that started with 'crafty'., but I see now there sometimes are unmarked lines.

Note that 'setboard' after 'new' without a 'force' first is risky: 'new' sets the engine to play black, and the specs do not say hat 'setboard' should switch back to 'force' mode. So when a FEN with black to move is received they might move immediately. Also, sending 'variant' before 'new' is pointless: 'new' switches the variant to 'normal' (which in the specs is implied by that it should set up the standard chess starting position). Logic then dictates that 'variant' should set up the start position of the selected variant. The mandatory order is thus new - variant - force - setboard - go (where possibly variant and go could be interchanged).

Allowing the 'go' command to be executed before other commands preceding it (notably force and setboard') is really an extremely wrecking non-compliancy. The solution is to fix Crafty. Not making the interface jump through hoops to work around it. Note that 'ping'/'pong' do not necessarily solve it, unless Banksia actually waits for the 'pong' before it sends 'go'. (Which is not a CECP requirement.)

Note that apart from CECP Crafty also has an own protocol, for stand-alone mode. Which it uses if it has not received an 'xboard' command. The message about 'new' might refer to that. Crafty specifies 'feature reuse=1', so it must recognize the 'new' command in order to play multiple games, and that would not work without a 'new' command.