ChessUSA.com TalkChess.com
Hosted by Your Move Chess & Games
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

fen to fen functions
Post new topic    TalkChess.com Forum Index -> Computer Chess Club: Programming and Technical Discussions Flat
View previous topic :: View next topic  
Author Message
Uri Blass



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

PostPost subject: Re: fen to fen functions    Posted: Tue May 22, 2007 4:24 pm Reply to topic Reply with quote

Alessandro Scotti wrote:
Just a wild shot:

Code:

void fen2fen( char * fen, char * buf )
{
    for( char * e = strchr(fen,' ') - 1; e >= fen; e-- ) {
        *buf++ = *e ^ (isalpha(*e) ? 0x20 : 0x00);
    }
    strcpy( buf, strchr(fen,' ') );
}


If I understand correctly you try both to replace the side to move and replace the files of the pieces so a1 goes to h8 in this code.

This code also does not replace the side to move that is part of the fen
and it also is not correct for castling because there are order rules
and you need to write KQkq in this order and kqKQ is not correct fen.

This code is clearly shorter than my code.
I did not know the trick of xoring with 0x20 to make big letters small letters and the opposite.

I wrote so far code only for the case of changing side that is always possible and not for the case of left-right symmetry that may be impossible in case of castling rights(unless you use FRC and not normal chess and in that case left-right symmetry is always possible)

I did not go from the end to the beginning of the string and simply saved an array of strings for every rank of the board when later I used strncat to make from them one string(I have a special function to change one line when I do not need to change the order but only change big letters to small letters and the opposite).

I did not check that your code works but
thanks for sharing your code

I can make my code shorter based on the idea that you gave here but I do not think that it is important.

Uri
Back to top
View user's profile Send private message
Display posts from previous:   
Subject Author Date/Time
fen to fen functions Uri Blass Mon May 21, 2007 10:17 am
      Re: fen to fen functions Alessandro Scotti Mon May 21, 2007 3:20 pm
      Re: fen to fen functions Reinhard Scharnagl Mon May 21, 2007 5:10 pm
            Re: fen to fen functions Uri Blass Tue May 22, 2007 1:21 pm
                  Re: fen to fen functions Alessandro Scotti Tue May 22, 2007 3:46 pm
                        Re: fen to fen functions Uri Blass Tue May 22, 2007 4:24 pm
                              Re: fen to fen functions Alessandro Scotti Tue May 22, 2007 4:46 pm
                                    Re: fen to fen functions Uri Blass Thu May 24, 2007 12:52 pm
                                          Re: fen to fen functions Uri Blass Thu May 24, 2007 4:51 pm
                                                Re: fen to fen functions Uri Blass Thu May 24, 2007 8:13 pm
                                    Re: fen to fen functions Steffan Westcott Sat Jun 02, 2007 5:05 pm
                              Re: fen to fen functions Dann Corbit Tue May 22, 2007 6:33 pm
      Re: fen to fen functions Dann Corbit Mon May 21, 2007 5:48 pm
Post new topic    TalkChess.com Forum Index -> Computer Chess Club: Programming and Technical Discussions

 
Jump to:  
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




Powered by phpBB © 2001, 2005 phpBB Group
Enhanced with Moby Threads