TalkChess.com
Hosted by Your Move Chess & Games

Author Message
Uri Blass

Joined: 08 Mar 2006
Posts: 5958
Location: Tel-Aviv Israel

Post subject: Re: fen to fen functions    Posted: Thu May 24, 2007 12:52 pm

 Alessandro Scotti wrote: Hi Uri, yes my code only tries to address the easiest scenario and it simply copies anything that follows the board representation. After all I'm not H. G. and there is a limit to what I can do in four lines of code! I think we could run an informal contest for the: 1) shortest code (but clean and elegant); 2) shortest and trickiest code (anything goes). Anyone interested?

No chance in competition
I simply tries to write code that works and I am not a good programmer like you but here is my code.

Note that it does not translate move to make in epd files but only the string of the position

Note that I used your trick of xoring with 0x20 to go from small letters to big letters and the opposite otherwise my code could be longer.

I have a different function to check if the string is legal fen so this certainly can crash on illegal fen.

 Code: char fen1[1024]; char shortfen[10]; char * opp_line(char *rankfen) {    strcpy(shortfen,rankfen);    unsigned int i;    for (i=0;i='a'&&shortfen[i]<='z') //      shortfen[i]+='A'-'a'; //   else //      if (shortfen[i]>='A'&&shortfen[i]<='Z') //      shortfen[i]+='a'-'A'; if (isalpha(shortfen[i]))    shortfen[i]^=0x20;    return shortfen; } char *tranpose_line(char *rankfen) {    memset(shortfen,0,10);    for( char * e = rankfen+strlen(rankfen) - 1; e >= rankfen; e-- )         shortfen[strlen(shortfen)]=*e;    return shortfen; } enum {shortcastlewhite=1,longcastlewhite=2,shortcastleblack=4,longcastleblack=8}; char * translate_fen_1(char *fen) {    memset(fen1,0,1024);    char tempfen[10];    char tempfen2[10][10];    unsigned int l=strlen(fen);    unsigned int i=0;    int i0;    int j=0;    int cast=0;    while ((i0)    {       j--;       strncat(fen1,tempfen2[j],strlen(tempfen2[j]));    }    fen1[strlen(fen1)-1]=' ';    i++;    while (fen[i]==' ')       i++;    if ((fen[i]=='w')||(fen[i]=='W'))    fen1[strlen(fen1)]='b';    else       fen1[strlen(fen1)]='w';    fen1[strlen(fen1)]=' ';    i++;    while (fen[i]==' ')       i++;    if (fen[i]=='-')    {       fen1[strlen(fen1)]='-';       i++;    }    else    {       while (fen[i]!=' ')       {          if (fen[i]=='k')             cast|=shortcastlewhite;          if (fen[i]=='q')             cast|=longcastlewhite;          if (fen[i]=='K')             cast|=shortcastleblack;          if (fen[i]=='Q')             cast|=longcastleblack;          i++;       }       if (cast&shortcastlewhite)          fen1[strlen(fen1)]='K';       if (cast&longcastlewhite)          fen1[strlen(fen1)]='Q';       if (cast&shortcastleblack)          fen1[strlen(fen1)]='k';       if (cast&longcastleblack)          fen1[strlen(fen1)]='q';    }    fen1[strlen(fen1)]=' ';    while (fen[i]==' ')       i++;    if (fen[i]=='-')       fen1[strlen(fen1)]='-';    else    {       fen1[strlen(fen1)]=fen[i];       i++;       fen1[strlen(fen1)]=9-fen[i];    }    i++;    while (i!=l)    {       fen1[strlen(fen1)]=fen[i];       i++;    }    return fen1; } char *translate_fen_2(char *fen) {    unsigned int l=strlen(fen);    unsigned int i=0;    char tempfen[10];    int i0;    int cast=0;    memset(fen1,0,1024);    while ((i
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First
Subject Author Date/Time
Uri Blass Mon May 21, 2007 10:17 am
Alessandro Scotti Mon May 21, 2007 3:20 pm
Reinhard Scharnagl Mon May 21, 2007 5:10 pm
Uri Blass Tue May 22, 2007 1:21 pm
Alessandro Scotti Tue May 22, 2007 3:46 pm
Uri Blass Tue May 22, 2007 4:24 pm
Alessandro Scotti Tue May 22, 2007 4:46 pm
Re: fen to fen functions Uri Blass Thu May 24, 2007 12:52 pm
Uri Blass Thu May 24, 2007 4:51 pm
Uri Blass Thu May 24, 2007 8:13 pm
Steffan Westcott Sat Jun 02, 2007 5:05 pm
Dann Corbit Tue May 22, 2007 6:33 pm
Dann Corbit Mon May 21, 2007 5:48 pm

 Jump to: Select a forum Computer Chess Club Forums----------------Computer Chess Club: General TopicsComputer Chess Club: Tournaments and MatchesComputer Chess Club: Programming and Technical DiscussionsComputer Chess Club: Engine Origins Other Forums----------------Chess Thinkers ForumForum Help and Suggestions
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum