Page 1 of 1

Add rules to parser.l

PostPosted: 07 Apr 2009, 19:04
by Anthony
Hello,
I'm a french student of 22 years old, in Master 1 of Informatic.
Under a project for my studies, I develop with another person a new variant call TwilightChess based on crazyhouse board, and an corresponding engine based on fruit 2.1, and polyglot. I haven't encountered any problem for the development of rules, although I am far from finished. But I have encoutered a big problem when I started watching the loading of a game, especially parser.l and parser.c files.
I think paser.c is generated by the parser.l file, but how I can't find the program that could do that I manually add rule in the parser.c. And unfortunately I have only segfaults after building.
I have search on the forum but I didn't find any subject related to this problem.

That is the line that I've added in parser.l just after the bughouse rules to drop a pawn :

Code: Select all
[a-l][0-9][@*][A-Z] {
    /* Twilight piece warp.  No legality checking for now. */
    currentMoveString[0] = yytext[0];
    currentMoveString[1] = yytext[1];
    currentMoveString[2] = '@';
    currentMoveString[4] = NULLCHAR;

    if (appData.debugMode) {
        fprintf(debugFP, "Warp: %s\n", currentMoveString);
    }
    /* [HGM] do not allow values beyond board size */
    if(currentMoveString[1] - ONE >= BOARD_HEIGHT ||
       currentMoveString[0] - AAA >= BOARD_WIDTH     )
      return 0;

    if (WhiteOnMove(yyboardindex)) {
      currentMoveString[3] = ToUpper(yytext[3]);
      return (int) WhiteWarp;
    }
   else {
      currentMoveString[3] = ToLower(yytext[3]);
      return (int) BlackWarp;
    }
}


I've set this two variables with their new values in parser.c :
Code: Select all
#define YY_NUM_RULES 43
#define YY_END_OF_BUFFER 44


And that is the line that I've added in parser.c just after the bughouse rules to drop a pawn :
Code: Select all
*####################################################################*/
/*Begin TwilightChess change*/
case 11:
YY_RULE_SETUP
{
   fprintf(debugFP, "###############################\n"
                "Dans le parser pour le WARP !\n"
                "###############################\n");

   currentMoveString[0] = yytext[0];
   currentMoveString[1] = yytext[1];
   currentMoveString[2] = '@';
   currentMoveString[3] = NULLCHAR;
   currentMoveString[4] = NULLCHAR;

   fprintf(debugFP, "###############################\n"
                "%s\n"
                "###############################\n",yytext);

   if (appData.debugMode) {
      fprintf(debugFP, "Warp: %s\n", currentMoveString);
   }

   if(currentMoveString[1] - ONE >= BOARD_HEIGHT ||
      currentMoveString[0] - AAA >= BOARD_WIDTH     ) {
      return 0;
   }

   if (WhiteOnMove(yyboardindex)) {
      currentMoveString[3] = ToUpper(yytext[3]);
      return (int) WhiteWarp;
   }
   else {
      currentMoveString[3] = ToLower(yytext[3]);
      return (int) BlackWarp;
   }
}
   YY_BREAK
/*End TwilightChess change*/
/*####################################################################*/


To finish I thank you for your answers, and excuse me if I didn't put my message in the right section, and excuse me for my weak English.

Best regards,
Anthony.

Re: Add rules to parser.l

PostPosted: 08 Apr 2009, 08:09
by H.G.Muller
Parser.c is generated from parser.l by a utility called 'flex' (which generates lexical scanners). I always do this under Windows + Cygwin. (You have to make sure to include the flex package, and some flex versions did give problems (error messages)). Last time in Ubuntu I tried it I had also problems, which I solved by simply doing it in Cygwin in stead, and transferrin the thus obtained parser.c to Ubuntu.

You never should change anything in parser.c, it is generated automtically. (Sometimes you get away with it when you only want to change the code that handles the recognition of a particular syntax rule, but adding new rules always requires generation of a new parser.c by flex: the lexical scanner in parser.c is table-driven, and new rules require larger tables and different table nitialization.)

Is the variant described somewhere? What is the twilight warp move supposed to do?

[edit] Is it this one? I guess the main trick to have a computer play this well is to sufficiently reduce the sarch depth of drops, in LMR fashion (so they lose the reduction when they fail high), in order to largely eliminate the burdon of useless drops. If this is done properly, I doubt if a human would stand better chances against a computer than in orthodox Chess.

Re: Add rules to parser.l

PostPosted: 08 Apr 2009, 14:56
by Anthony
Hello,

Thank you for your reply. The variant that we develop, is that you saw. Actually we think that the combinatorial explosion will limit the engine. But it's true that if we cut the tree high enough the engine could be really strong.
I've more questions.
Witch version of flex are you using ?
Witch command are you using to lunch flex ?
I use flex 2.5.35 with this following command : flex --outfile=parser.c --header-file=parser.h parser.l. But it doesn't work. During the build i've a multitudes of errors. I have the same errors when I try to generate parser.c with the origininal parser.l
The problem may be the compiler I use currently with cygwin gcc-3.4.4, the version 4.3.2 do not support the flag "-mno-cygwin". Here is my script to compile:
Code: Select all
!#/bin/bash
echo "flex -o parser.o -L parser.l"
flex -o parser.o -L parser.l

echo "windres --use-temp-file --include-dir . winboard.rc -O coff -o wbres.o"
windres --use-temp-file --include-dir . winboard.rc -O coff -o wbres.o

echo "gcc -O2 -mno-cygwin -mwindows -c *.c"
gcc -O2 -mno-cygwin -mwindows -c *.c

echo "gcc -mno-cygwin -mwindows *.o -lwsock32 -lwinmm -o winboard.exe"
gcc -mno-cygwin -mwindows *.o -lwsock32 -lwinmm -o winboard.exe

echo "strip winboard.exe"
strip winboard.exe

echo "rm *.o"
rm *.o

If you see a problem can you explain it to me ?

I you are interested by our developement we could send to you, our sources and binaries.

Thank you for your answers.
Best regards,
Anthony.

Re: Add rules to parser.l

PostPosted: 08 Apr 2009, 17:20
by H.G.Muller
I nowadays always use the Cygwin makefile incuded in the WinBoard distribution (cygwin.mak) to compile (make -f cygwin.mak). The rule to make parser.c in there seems to be:

flex -oparser.c -L parser.l

My gcc says this about its version:

Code: Select all
$ gcc -v
Reading specs from /usr/lib/gcc/i686-pc-cygwin/3.4.4/specs
Configured with: /usr/build/package/orig/test.respin/gcc-3.4.4-3/configure --ver
bose --prefix=/usr --exec-prefix=/usr --sysconfdir=/etc --libdir=/usr/lib --libe
xecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --enable-langu
ages=c,ada,c++,d,f77,pascal,java,objc --enable-nls --without-included-gettext --
enable-version-specific-runtime-libs --without-x --enable-libgcj --disable-java-
awt --with-system-zlib --enable-interpreter --disable-libgcj-debug --enable-thre
ads=posix --enable-java-gc=boehm --disable-win32-registry --enable-sjlj-exceptio
ns --enable-hash-synchronization --enable-libstdcxx-debug
Thread model: posix
gcc version 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)


flex says:

Code: Select all
$ flex --version
flex version 2.5.4


When you get it running, I would be interested in having the WinBoard sources. Twilight Chess seems a variant of fundamental interest, as it decouples the problem of drops from the tactics of capturing material. As far as I can see it is this coupling that makes Shogi or Crazyhouse so complicated to evaluate, as it is not clear what are quiet positions. In Twilight Chess, however, a Quiescence search can simply search all captures and (dangerous) drops; this is guaranteed to terminate. So it offers a good possibiltity to study the strategy of drops, and how to search them, in isolation. As it is one of my ambitions to build a Shogi engine, I am very interested in this.

So please tell me when you have the engine running; I might make a drop-capable version of Fairy-Max then, to provide you with an opponent! :D

Re: Add rules to parser.l

PostPosted: 08 Apr 2009, 20:54
by Anthony
Hello,

I found the problem. I'd a wrong version of flex, only the version 2.5.4 works. Thank you for everything. The engine is already running. The rules have been added. But the evaluation function wasn't really functional. Once the engine will working, I'll send you the sources.

Best regards,
Anthony.