Author: Andy Serpa
Date: 20:58:25 11/23/01
Hello,
As part of a project I'm working on for my website, I would like to create a PGN
parser written in PHP that can take your standard PGN file with "short"
algebraic notation and turn it into "long" algebraic coordinate notation (e.g.
e4 = e2e4).
Although I'm sure I could write such a program, since it is going to be in PHP
running on a web server, I need to make sure it is as lean / fast /
low-resource-using as possible.
What do you suppose is the "optimal" way to do it to minimize the amount of
looping, etc.? Strict legal move checking is not neccessary (we are going to
assume valid PGN files), but I guess there is no getting around the fact that
I've got to keep track of where all the pieces are as only pawn moves can be
deciphered strictly from the notation (and not even all pawn moves). I was
thinking along the following lines:
-- Put the position in a standard array
-- Write a move generator with sections for each kind of piece
(pawn move generator, knight move generator, bishop/diagonal-queen move
generator, etc.)
-- For each move, use the notation to identify the kind of piece moved &
its destination square
-- Pawn moves are easy -- simply move the pawn. For attacking moves we check
for enpassant by seeing if the destination square is occupied.
-- This is the tricky part:
For other pieces, use the destination square as starting point and use the
move generator for that piece looping through possible "from squares" until
I stumble across the appropriate piece.
Or: locate the appropriate piece(s), and loop through possible moves until
I find one that hits the right destination square.
(Note I've still got to check for obstructions with the sliding pieces
to make sure I move the right one, or maybe do some sort of color checking
for diagonal pieces.)
That last part is obviously the part that needs the most optimizing -- what is
the best way?
Could I do all this faster with a bitboard representation?
Andy Serpa
chessmad@chessopolis.com
http://www.chessopolis.com
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.