To find out the problem, I have created a super simple chess engine as the following code, then compile by XCode 8.1. I (human) play on the white side and it plays on the black side. For the 1st move, everything good: I play the first move (f2f4), it reply a move (b8c6) - no crash. However, when I played the second one (g1f3), it keeps crashing after receiving my 2nd move.
Can someone help:
- verify if the bellow engine can run well (survive after making over 3 moves) on your systems with your compilers
- find out what wrong with the code and/or my system
Thanks a lot.
Code: Select all
//
// main.cpp
// myengine
//
#include <iostream>
int main(int argc, const char * argv[]) {
std::string line;
while (getline(std::cin, line)) {
if (line.empty()) {
continue;
}
char command[256];
sscanf(line.c_str(), "%s", command);
if (!strcmp(command, "xboard")) {
printf("\nfeature myname=\"MyEngine\"\n");
fflush(stdout);
continue;
}
if (!strcmp(command, "go") || (strlen(command)>=4 && isalpha(command[0]) && isdigit(command[1]) && isalpha(command[2]) && isdigit(command[3]))) {
static const char* moveList[] = { "b8c6", "c6b8" };
static int moveIdx = 0;
const char* move = moveList[moveIdx % 2];
moveIdx ++;
printf("move %s\n", move);
fflush(stdout);
}
}
return 0;
}
Code: Select all
locale = en_AU.UTF-8
recognized 'normal' (-1) as variant normal
recognized 'normal' (-1) as variant normal
recognized 'normal' (-1) as variant normal
shuffleOpenings = 0
shuffleOpenings = 0
Version: xboard 4.9.1 + myengine ()
Reset(1, 0) from gameMode 0
recognized 'normal' (-1) as variant normal
GameEnds(0, (null), 2)
shuffleOpenings = 0
StartChildProcess (dir="/Applications/XBoard.app/Contents/Resources/share/xboard/../../bin/fairymax") /Users/Pham/myengine
888 >first : xboard
protover 2
896 <first :
896 <first : feature myname="MyEngine"
896 >first : accepted myname
10893 >first : new
random
10893 >first : level 40 3 0
10893 >first : post
10893 >first : hard
Impossible move , type = 0
nps: w=-1, b=-1
nps: w=-1, b=-1
15506 >first : time 18000
15506 >first : otim 18000
book hit = (NULL)
15506 >first : f2f4
15516 <first : move b8c6
Interrupting first
19475 >first : time 17997
19475 >first : otim 17604
book hit = (NULL)
19475 >first : g1f3
GameEnds(27, Error: first chess program (/Users/Pham/myengine/myengine) exited unexpectedly, 2)
Interrupting first
22784 >first : result 0-1 {Error: first chess program (/Users/Pham/myengine/myengine) exited unexpectedly}
22787 >first : force
22789 >first : quit