Mirror the board instead of rotating when transitioning to black. #118
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The engine uses piece square tables to evaluate positions. These piece square tables are not symmetric, which means that rotating the board and viewing black as "white" effectively changes the incentives of black, since black has its king to the left of the queen rather than the right. As such, where the white king starts on the king pst space with value 6, the black king starts on -14 and is incentivized to move one space left or right, because the king pst models it as having already castled. This cannot be right.
Another example is that if you evaluate the value of the starting position of black and white, it comes out to a difference of (6-13) - (-14-31) = 38 in favour of white because of the reversed position of the king and queen according to the piece square tables. This is true even if black starts and is just an artifact of the non-symmetry of the piece square tables. But chess is equivalent if black starts, so it does not make sense that white should have an advantage in this case.
These are two quite simple, illustrative examples, but this influences the engine's positional play all the way down the search tree.
The starting positions of white and black are identical when mirrored horizontally. Thus if the board is instead mirrored horizontally, then piece square tables will be correctly applied to both black and white. This is the only thing this pull request changes. I have implemented two static methods in the Position object to make the change very clear, but you are welcome to change it as you see fit.
Thank you for this nice chess engine.