[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[FWP] Golf: chessboard



Since some of us had fun with a bridge-related golf challenge 
a couple of weeks ago, I thought I'd try to come up with 
something about chess.

The challenge is to write a Perl program with the fewest
characters (the shebang line doesn't count) that takes as a
command-line argument a chess position in Forsythe-Edwards
notation (FEN) and prints out an ASCII representation of a 
chessboard like that produced by the Position->to_text() method 
in Gareth Rees's Games::Chess module.

That is, write the shortest possible program "chessboard" such 
that, for example,

    perl chessboard rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR

produces this output (not indented):

    r n b q k b n r
    p p p p p p p p
      .   .   .   .
    .   .   .   .  
      .   .   .   .
    .   .   .   .  
    P P P P P P P P
    R N B Q K B N R

As another example,

    perl chessboard 8/3p4/p1bk3p/Pp6/1Kp1PpPp/2P2P1P/2P5/5B2

produces

      .   .   .   .
    .   . p .   .  
    p . b k   .   p
    P p .   .   .  
      K p . P p P p
    .   P   . P . P
      . P .   .   .
    .   .   . B .  

In FEN, the digits represent runs of open squares, the 
lowercase letters represent black pieces, and the uppercase 
letters represent white pieces.  In the chessboard drawings, 
periods represent open black squares (that's the tricky bit), 
and spaces represent open white squares; there are spaces 
between the columns and a newline at the end of each row, 
including the last.

My solution is less than 80 characters.  Good luck!

-- 
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe