I removed 350 lines of code from MadChess and increased its playing strength by 12 Elo. I’m happy with the ratio.
The bulk of changes since my last blog post involve replacing redundant, color-specific code with color-agnostic code, mostly in the Eval
class. I replaced code such as this…
… with code that’s generalized for multiple pieces and colors.
The above is just one example of refactored code. There are many others in PR 22 that adds 2,641 lines of code and removes 3,336 lines of code (net -695 lines of code). This refactoring took a lot of time. I was careful to test often to ensure my (partial) changes did not weaken the engine due a mistake when translating color-specific code to color-agnostic code via array lookups indexed by colorless piece.
The Board.GetSquareFromWhitePerspective
method violates the spirit of my refactoring. However, an exception is warranted because I don’t bother storing white and black piece location values in separate tables. For black, I simply lookup the corresponding square from white’s side of the board.
In addition to color-agnostic refactoring, I made other code quality improvements in a series of Pull Requests.
Combined, the five PRs removed 350 lines of code. This increased the playing strength of MadChess 3.1 Beta by 12 Elo.
- GitHub commit (hash) or Subversion source code revision (integer)
- Win At Chess position test, 3 seconds per position
- Bullet chess, 2 min / game + 1 sec / move