| View previous topic :: View next topic |
| Author |
Message |
Dann Corbit
Joined: 08 Mar 2006 Posts: 5125 Location: Redmond, WA USA
|
Post subject: Re: fen to fen functions Posted: Tue May 22, 2007 6:33 pm |
|
|
| Uri Blass wrote: |
| 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 |
The xor trick relies upon the ASCII character set where 'A' is 0x41 and 'a' is 0x61 up to 'Z' is 0x5A and 'z' is 0x7A.
You can make reversing case more plain with:
foo = isupper(foo) ? tolower(foo) : toupper(foo);
Note that the toupper() and tolower() macros/functions do nothing if the input integer is not an alphabetic letter. |
|
| Back to top |
|
 |
|
| 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 |
|
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
|
|