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
Steffan Westcott



Joined: 11 Mar 2006
Posts: 28
Location: Midlands, England

PostPost subject: Re: fen to fen functions    Posted: Sat Jun 02, 2007 5:05 pm Reply to topic Reply with quote

Alessandro Scotti wrote:
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?

Here's my effort for your entertainment, 2 Perl programs for mirror and flip operations. They both handle all FEN fields, including side-to-move, en passant square and castling rights:
Code:
# mirror.pl : Prints FEN string of horizontally mirrored input position, castling rights clobbered
@_ = @ARGV;
$_[0] = reverse join '/', reverse split /\//, $_[0];
$_[2] = "-";
$_[3] =~ tr/a-h/hgfedcba/;
print join ' ', @_;

Code:
# flip.pl : Prints FEN string of vertically flipped input position, colour swapped
@_ = @ARGV;
$_[0] = join '/', reverse split /\//, $_[0];
$_[0] =~ tr/a-zA-Z/A-Za-z/;
$_[1] =~ tr/wb/bw/;
$_[2] =~ tr/KQkq/kqKQ/;
$_[2] = join '', sort split //, $_[2];
$_[3] =~ tr/36/63/;
print join ' ', @_;
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