Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Parsing Chess Algebra Notation

by EdwardG (Vicar)
on May 04, 2004 at 13:51 UTC ( [id://350336]=note: print w/replies, xml ) Need Help??


in reply to Parsing Chess Algebra Notation

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

 

Replies are listed 'Best First'.
Re: Re: Parsing Chess Algebra Notation
by cyocum (Curate) on May 04, 2004 at 14:23 UTC

    I think your starting simple and moving up to complex is a better way to do it (in fact, I should have remembered it as a general rule).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://350336]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2024-04-26 01:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found