Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

This is a nice problem, one which can give you many hours of enjoyment, depending of course on how you define enjoyment.

I've been throught this exercise a number of time in different languages, so let me give you my thoughts on where the complexity lies.

First, as you say, it is not enough to simply derive the algebraic form of the from and to squares. If it was then something as simple as this would suffice for each1

sub sqToAlg { my $sq = shift; # Assumes squares are numbered 0 to 63, # from right to left, bottom to top substr('abcdefgh',7 - $sq % 8,1) . ($sq / 8); }

But that is far from enough. You need to know the following as well:

  • Was the toSq a capture?
  • Did the move result in simple check
  • Did the move result in simple stalemate
  • ...or stalemate by the 50-move rule
  • ...or stalemate by repetition (must be claimed)
  • If the piece moved was a pawn, did it promote to something?
  • Of course, checking legality can be assumed, right?
  • Has the flag fallen (if the game is timed)
  • Was this an en passant capture eg e2xf3ep.

Well, you get the idea. And some of these can combine to make wonderful moves like e7xf8=Q++

Best of luck with it, and I for one would very much like to see your code when you finish!

Update: I recommend that to start with you deal with the simple form a1a2 and worry about the more complex notation later. There is so much more to consider (much more interesting too) that this should be passed over quickly. For instance, think about move generation first, perhaps some bit twiddling for efficiency, or bitmaps to help you with simultaneous generation of (in particular) pawn moves. Minimax, or more specifically AlphaBeta pruning thereof still keeps me amused for hours whenever I revisit. Ahh...and I must finish the version in C#, one day, perhaps when the Delphi version rises above 1500...

 

1 converted from C# without testing

 


In reply to Re: Parsing Chess Algebra Notation by EdwardG
in thread Parsing Chess Algebra Notation by cyocum

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-03-28 13:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found