Page 1 of 1

UCI Question

Posted: Mon Oct 21, 2013 9:13 pm
by arijit91
Hi

I've been trying to make a simple UCI compliant chess engine. I have written a simple UCI loop to print "bestmove e2e4" when it receives the command "go" from the GUI. However, this does not seem to work (I tried on both Arena and PyChess). Is there something wrong I am doing?

Below is the code for my UCI Loop: (I've just modified the Vice engine's code a bit)

Code: Select all

	setbuf(stdin, NULL);
  setbuf(stdout, NULL);

	char line[INPUTBUFFER];
    printf("id name %s\n",NAME);
    printf("uciok\n");
	
	int MB = 64;

	while (1) {
		memset(&line[0], 0, sizeof(line));
        fflush(stdout);
        if (!fgets(line, INPUTBUFFER, stdin))
        continue;

        if (line[0] == '\n')
        continue;

        if (!strncmp(line, "isready", 7)) {
            printf("readyok\n");
            continue;
        } else if (!strncmp(line, "position", 8)) {
        } else if (!strncmp(line, "ucinewgame", 10)) {
        } else if (!strncmp(line, "go", 2)) {
          printf("bestmove e2e4\n");
        } else if (!strncmp(line, "quit", 4)) {
            break;
        } else if (!strncmp(line, "uci", 3)) {
            printf("id name %s\n",NAME);
            printf("uciok\n");
        }
		}
Could someone please tell me what I'm doing wrong?

Thanks

Re: UCI Question

Posted: Tue Oct 22, 2013 4:40 pm
by H.G.Muller
Just let the GUI make a log of all communication with the engine, and it should be easy enough to see what it does and what it doesn't. Staring at code is not a very efficient method of debugging.

Re: UCI Question

Posted: Wed Oct 23, 2013 3:40 am
by arijit91
Thanks for your reply. I did look at the logs for Pychess, and it seems to be ignoring my move. I am not sure why this is happening or if I am doing anything stupid (the basic UCI loop looks simple enough, but I'm not sure why it's going wrong).

Below is the relevant log from Pychess, in case someone has some experience with this and can help out.

Code: Select all

12:31:30 ('Balrog', '12:10:28.447') Log: position fen rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1
12:31:30 ('Balrog', '12:10:28.447') Log: go wtime 300000 btime 300000 winc 0 binc 0
12:31:30 Default Debug: GameModel.run: id=157030876, players=[TempName, ***], self.ply=0: got move=ready from TempName
12:31:30 Default Debug: GameModel.run: id=157030876, players=[TempName, ***], self.ply=0: acquiring self.applyingMoveLock
12:31:30 stdout Debug:   File "/usr/lib/python2.7/threading.py", line 525, in __bootstrap
    self.__bootstrap_inner()
  File "/usr/lib/python2.7/threading.py", line 552, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/dist-packages/pychess/System/GtkWorker.py", line 171, in run
    self.result = self.func(self)
  File "/usr/lib/python2.7/dist-packages/pychess/widgets/ionest.py", line 35, in <lambda>
    workfunc(w, gamemodel, player0tup, player1tup, loaddata))
  File "/usr/lib/python2.7/dist-packages/pychess/widgets/ionest.py", line 143, in workfunc
    gamemodel.start()
  File "/usr/lib/python2.7/dist-packages/pychess/System/ThreadPool.py", line 140, in start
    pool.start(self.run)
  File "/usr/lib/python2.7/dist-packages/pychess/Utils/GameModel.py", line 490, in run
    assert isinstance(move, Move), "%s" % repr(move)
12:31:30 stdout Debug: <type 'exceptions.AssertionError'> 'ready'
12:31:30 ('Balrog', '12:10:28.447') Debug: bestmove e2e4
12:31:30 ('Balrog', '12:10:28.447') Warning: __parseLine: self.waitingForMove==False, ignoring move=e2e4
12:31:30 stdout Debug: 12:31:30 ('Balrog', '12:10:28.447') Warning: __parseLine: self.waitingForMove==False, ignoring move=e2e4
12:31:30 stdout Debug: 
12:31:30 ('Python', '12:10:28.520') Debug: 3	-201	0.82	713	d5 d4 Nc6
Thanks again!