I'm working on a chess AI for a school project and I am looking into ways to identify the current phase of a board, meaning the opening, middlegame, and endgame. I have seen an article explaining Tapered Evaluation, however I don't really understand what the point of this is. I want to be able to change my overall board evaluation heuristic depending on what state the game is in. This way, in the middlegame, I can prioritize king protection and development and other strategies.
I think you don't need this. You shift from opening to middle game when your opening book for this line runs out. The middle-end phase is less relevant in AI, and your algorithm will handle those the same. You could define a line, e.g. when your search depth could be increased over some threshold, because the board has only a handful of pieces left, but I don't think it's an important change.
The definition of "the middlegame" is a somewhat gray area.
There's no commonly-accepted, sharply-defined definition for when the middlegame starts/ends.
I suggest you start with one of these definitions, test it, and refine it if it gives poor results:
Middlegame Definition #1:
- Castling has occurred, OR
- 10 moves have been played
Middlegame Definition #2:
- One player's rooks are connected, OR
- 12 moves have been played
Middlegame Definition #3:
- One player has castled AND has moved all minor pieces at least once AND has moved at least 1 pawn, OR
- 12 moves have been played
The endgame is generally defined as being "when the Kings are ready to join the battle", which usually occurs when there are few pieces left on the board. Start with defining the endgame as when there are 12 pieces left on the board and improve it if that definition ever fails.
There is no sharp definition that would say x moves and y moves is where.
The opening is pretty much over when you have exhausted moves that have been played so many times by many players. It could be short if someone makes an unusual move, or, for a very long time, play some extremely old lines especially when GMs want to play safe for a draw.
Endgames would tend to start when there is really not enough material to mount a mating attack by force. Just trading queens is not enough if all the other pieces are still in play.
But none of this should matter to an AI program. They are just arbitrary identifiers to help indicate the stage of the game.
A good AI program would evaluate the position independently of what stage you thought the game was in. Not doing so would lead to a number of places that give weird results. Anyway, isn't AI supposed to determine those weightings for itself based on the position?
The problem is you can't train AI with enough examples to really make AI work the way it normally does.
As a rough estimate, I've once seen the definition that the endgames begins when each side's pieces has a strength of 13 or less (counting 9 for queen, 5 for rook, 3 for bishop/knight and ignoring pawns) Can't remember the source, though.
The opening is often said to end when all of the pieces are developped, but it's not always so clear. You may want to alow one piece to stay on its starting square and call it the middlegame already