3

What is the best or alternative ways to detect game phase by a chess AI? What is a good algorithm to use? Chess programming wiki says to count material or pieces? What would be the expected piece or material counts to use?

I have an idea to use average pieces on a file and its standard deviation but that’s intensive math to use? And I’m unsure of its applicability?

2
  • 2
    What do you mean with "best", it's completely subjective for humans too. What do you want to use the information for? Dec 2 '17 at 22:03
  • Your right. I’m not exactly looking for best but alternative methods to use. I basically want to benchmark different ideas and pick something that is relatively accurate and light weight. My purpose is to add modified terms in the evaluation that depend on game phase. Something like stockfishes tapered eval. Taper evaal for me is too heavy in performance. You basically triple the fuction calls. Dec 3 '17 at 0:45
3

This is a tricky question, and I'm sure there's no definitive solution.

Lichess uses this definition (https://lichess.org/qa/102/how-are-the-mid-game-and-end-game-dividers-determined)

Opening is obvious, starts on move 1.

Mid-game is less obvious, and is still in testing. The long-and-short of the current heuristics are that the mid-game occurs when either:
- The position is adequately complex and enough pieces are developed.
- 2 sets of minor or major pieces have been taken off the board. (This is mainly useful for when the position is quite open)

End-game is slightly more straight forward, when there are less than 7 minor and major pieces on the board the end-game has begun (so, perhaps 2 rooks and a bishop Vs 2 bishops and a knight). This is not technically where everyone would draw the line, but it's a good indicator that either 1. The end-game has begun 2. The end-game will begin soon.

Stockfish uses interpolation between the middlegame and endgame. This is done by counting non-pawn materials (https://github.com/official-stockfish/Stockfish/blob/03a9b3bd8d79e1677f1c74cf7d8f8036795675c6/src/material.cpp)

// Map total non-pawn material into [PHASE_ENDGAME, PHASE_MIDGAME]
e->gamePhase = Phase(((npm - EndgameLimit) * PHASE_MIDGAME) / (MidgameLimit - EndgameLimit));

You will need to make a decision on what material counts you want to use.

Suggestions:

  • If your engine supports opening book, you might want to use that
  • You might use the move counts (it's in the FEN string) for opening vs middlgame
  • Endgame is generally defined as number of X pieces and N pawns on the board (you decide what X and N should be). N<=3 is almost always an endgame.
  • Lichess's definitions have worked quite well practically.
7
  • In your third dot, do you rather mean X<=3 ?
    – Evargalo
    Dec 3 '17 at 11:46
  • 1
    @Evargalo No. When the number of pawns is no more than three, we generally think it's an endgame. It's unusual to have no more than three pawns for each side in a "middlegame". But there's no right or wrong here.
    – SmallChess
    Dec 3 '17 at 11:47
  • X<=3 is a pretty good indicator that you're in the endgame as well, though :D
    – Annatar
    Dec 4 '17 at 7:01
  • @Annatar Ok.. I'm wrong. X and N <= 3.
    – SmallChess
    Dec 4 '17 at 7:10
  • @SmallChess You're not wrong. X or N <= 3 is enough.
    – Annatar
    Dec 4 '17 at 8:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.