user1105: I'm writing a small chess engine in LISP. I was trying to read some PGN file, at first it seemed like a piece of cake. But then I realized something.
Most of the PGN files, don't tell which is white and which is black. I mean if white plays e4 an later d5, how does the engine knows if he has to take or not? I could name the black pieces bN for example but by doing so i won't be able to import PGN easily.
Should i increment by 2? is that how PGN parsers do it?  Say the first three moves in a match are e4 e6 f4, should i create a recursive function to read x + 2? to skip whites move?

user1824: In a standard PGN you have an initial position, it's the chess starting position or it has a FEN to setup the position. After that you can follow the move sequence one after another.
If it's the starting position then white has to move, otherwise it has a FEN and a standard FEN contains who must move.
Another way is looking at moves, if the first written move is like N. Kg2 then it's white's turn. If the first written move is line N. ... Rh5 then it's black's turn.
Also, it's popular (I'm not sure) to write the first move by number 1 such as 1. Kg2 or 1. ... Rh5. So, the numbers can help to follow the sequences.

user1887: Chess engines normally don't read PGN. When they "start" they read a position that is encoded in a FEN notation. FEN is a powerful way to describe a chess position. From this position a sequence of moves can be given in a string.
The most common way of communicating with a chess engine is via the UCI protocol:
http://wbec-ridderkerk.nl/html/UCIProtocol.html
More on FEN:
http://en.wikipedia.org/wiki/Forsyth%E2%80%93Edwards_Notation
However, if you are really interested in implementing an engine that can read PGN you should read the specs:
http://web.archive.org/web/20100528142843/http://www.very-best.de/pgn-spec.htm
Especially the section about the moves is probably interesting for you:
http://web.archive.org/web/20100528142843/http://www.very-best.de/pgn-spec.htm#8.2

user924: There is a detailed standard of PGN available, for instance here: PGN standard at the Wayback Machine.
You will never see "e4 e6 f4" in a PGN file, since it is mandatory to mention the move number before white's move: "1.e4 e6 2.f4".

1105: <p>I'm writing a small chess engine in LISP. I was trying to read some PGN file, at first it seemed like a piece of cake. But then I realized something.</p>

<p>Most of the PGN files, don't tell which is white and which is black. I mean if white plays e4 an later d5, how does the engine knows if he has to take or not? I could name the black pieces <code>bN</code> for example but by doing so i won't be able to import PGN easily.</p>

<p>Should i increment by 2? is that how PGN parsers do it?  Say the first three moves in a match are e4 e6 f4, should i create a recursive function to read x + 2? to skip whites move?</p>
 1824: <p>In a standard PGN you have an initial position, it's the chess starting position or it has a FEN to setup the position. After that you can follow the move sequence one after another.</p>

<p>If it's the starting position then white has to move, otherwise it has a FEN and a standard FEN contains who must move.</p>

<p>Another way is looking at moves, if the first written move is like <code>N. Kg2</code> then it's white's turn. If the first written move is line <code>N. ... Rh5</code> then it's black's turn.</p>

<p>Also, it's popular (I'm not sure) to write the first move by number <code>1</code> such as <code>1. Kg2</code> or <code>1. ... Rh5</code>. So, the numbers can help to follow the sequences.</p>
 1887: <p>Chess engines normally don't read PGN. When they "start" they read a position that is encoded in a FEN notation. FEN is a powerful way to describe a chess position. From this position a sequence of moves can be given in a string.</p>

<p>The most common way of communicating with a chess engine is via the UCI protocol:
<a href="http://wbec-ridderkerk.nl/html/UCIProtocol.html" rel="noreferrer">http://wbec-ridderkerk.nl/html/UCIProtocol.html</a></p>

<p>More on FEN:
<a href="http://en.wikipedia.org/wiki/Forsyth%E2%80%93Edwards_Notation" rel="noreferrer">http://en.wikipedia.org/wiki/Forsyth%E2%80%93Edwards_Notation</a></p>

<p>However, if you are really interested in implementing an engine that can read PGN you should read the specs:
<a href="http://web.archive.org/web/20100528142843/http://www.very-best.de/pgn-spec.htm" rel="noreferrer">http://web.archive.org/web/20100528142843/http://www.very-best.de/pgn-spec.htm</a></p>

<p>Especially the section about the moves is probably interesting for you:
<a href="http://web.archive.org/web/20100528142843/http://www.very-best.de/pgn-spec.htm#8.2" rel="noreferrer">http://web.archive.org/web/20100528142843/http://www.very-best.de/pgn-spec.htm#8.2</a></p>
 924: <p>There is a detailed standard of PGN available, for instance here: <a href="https://web.archive.org/web/20100407090858/http://www.very-best.de/pgn-spec.htm">PGN standard at the Wayback Machine</a>.</p>

<p>You will never see "e4 e6 f4" in a PGN file, since it is mandatory to mention the move number before white's move: "1.e4 e6 2.f4".</p>
