Which chess notation to feed neural network: FEN or PGN?

I am trying to build a chess AI with a neural network. To learn about how neural networks work and refresh my programming experience. I have some experience with classifiers but not yet with neural networks, so feel free to correct wrong assumptions and mistakes I make.

I plan to feed the neural net the current board position and all possible moves to choose from and after the game in the final position the game result.

While coding out the chess game I came across 2 notations, a FEN (board position) and a PGN (move sequence that led to the current board position).

This got me thinking, I initially chose FEN as data format to feed the net because that looked easier and lighter to process. I am now wondering however if there is an added value for the neural net to know the sequence in which a position came to be (or does it know this due to the nature of reinforcement learning?).

Take a checkmate for example. For us humans we can look backward and realize that the previous position was a 'mate in one' move. But will the neural net be able to relate the two positions? (and be able to 'look ahead' because that move led to success when it previously encountered it so it is reinforced in its structure?)

I can imagine that it doesn't matter because the net encountered them in sequence, so it will build up the association to that position (if this makes sense) but I am a bit unsure.

so to summarize, do you think I should use a FEN to feed in the current position or a PGN, or maybe even both?

Since PGN is longer and possible harder to process, you should wonder whether it transports more information than FEN. In this case, the question is: does it matter in which way you reached the current board positions? Does it influence the next move? There are only two situation that come to my mind:

1. Castling: (neither king nor rook may have moved, previously)
2. Threefold repetition

At least the first one could easily be covered by an additional flag.

In general, existing notions might not be best suited for neural networks. If you just want to cover the current board position, I would decide for a fixed-size input, e.g. store for each field, what figure is placed on it. You might then for example encode the figure with one-hot-encoding. that would give you 8x8x(#figures) as input. An approach like this will make live easier for you.

If you aim to store history then PGN (or something similar but in a numeric format) would be a suitable input. But then you might have to deal with input of dynamic length.

• that are some good points you bring up! My inexperience with neural nets shows here I think. That is why I was unsure if the relation between positions translates over from a FEN. What I had in mind is if the net can detect a forced checkmate in the future. As for the three fold repetition: I think I will engineer a feature that just is a counter of how many times that exact position has occurred in this game. That will be relatively cheap to compute, just compare to all stored FEN strings. The advice you mention about a fixed-size input I will definitely follow.
– NG.
Mar 10 at 16:59
• About the forced checkmate: That's exactly what your reinforcement learning aims to learn. Which action will lead to which expected gain. If the network detects a forced checkmate, this should have the maximal gain. Mar 10 at 17:36
• Do not underestimate the task. There are a lot of choices to make that will influence the result, such as the network architecture, the reinforcement algorithm, ... Mar 10 at 17:38
• Thank you for taking the time! I am a bit worried that I may have bitten off more than I can chew, but we'll see.. I don't expect it to work immediately, I partly started the project to learn what works and what doesn't. I'm also gonna aim low at the start, see if I can beat an easy low rating stockfish probably.
– NG.
Mar 10 at 19:55
• About the castling: the beauty of the fen notation is that it keeps track of castling rights and also en passant opportunities!
– NG.
Mar 10 at 20:00