Skip to content

Conversation

@rmarquis
Copy link
Contributor

@rmarquis rmarquis commented Jun 3, 2025

Fix asymetry in the heuristic function for game phase. The mixedness score gives more weight to one side than the other. It is one of three conditions used to define the middlegame.

This bug was first discovered in #162, but the issue was closed without being fixed.

@ornicar
Copy link
Collaborator

ornicar commented Jun 3, 2025

Are you sure that the asymmetry is a mistake and not an intended behaviour? Could it reflect the asymmetry of a game where one side plays first?

@rmarquis
Copy link
Contributor Author

rmarquis commented Jun 4, 2025

I've thought about it, but I really don't believe that's the case, for the following reasons:

  • The middlegame phase is determined by three conditions (only one of which needs to be true to define the middlegame), and only the mixedness score condition is asymmetric.
  • Only some of the mixedness score conditions are asymmetric (specific combinations of piece groups), while others are symmetric.
  • The asymmetry isn't minor, either. For example, a combination of 3 white and 1 black piece can be worth 11 points, while the equivalent 1 white and 3 black pieces is only worth 9 points. Additionally, the middle of the chessboard seems poorly defined (e.g., for 1 white and 1 black pieces, it is located between ranks 3 and 4 instead of ranks 4 and 5).

Here's what I believe happened: The mixedness score is computed using a grid of overlapping 2×2 squares, resulting in a 7×7 grid of "big squares" rather than the standard 8×8 board. It seems some mistakes were introduced in the indexing here, which is particularly evident in the definition of the board's middle.

Since I adjusted the most extreme asymmetric values (11 points for one side, 9 for the other) to 10–10, the change shouldn't drastically affect the expected aggregate threshold of 150 used to determine the middlegame. I wish I could discuss this with the original author of the code, but given the reasoning above, I believe a symmetric score is more correct than the current implementation.

Edit: To add to the above, the various weights given to the piece clusters seem to measure patterns for 3 keys areas: invasion into the opponent's half, fragmentation of piece clusters, and density of opposing pieces in local areas. Given these global patterns, I doubt a side bias as big as currently implemented is voluntary (nor should it be necessary in my opinion).

@ornicar ornicar merged commit 8b3f35a into lichess-org:master Jun 4, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants