Play Rather Than Code

Watching The Queen’s Gambit on Netflix nudged me to play chess online. I’ve spent time on chess over the last few years… programming an engine, not actually playing. I’m very rusty. Though my puzzle rating is decent. It’s much higher than my game rating, suggesting I need to work on time management. Thinking fast is not my strength, but everyone online plays blitz or bullet so here goes nothing…

Last night I joined a bullet tournament with a 2+1 clock. Each player has 2 minutes to make all their moves in the game, plus 1 second added to their clock after each move. Many of the games I played were blunder fests. But I managed to play solidly in a few. Here’s a well played game considering I’m making most of my moves in like 2 or 3 seconds. I play white (DamageInkk). Afterwards I had MadChess analyze the game. Converting a “won” game is not inevitable for a patzer like me, especially with the time pressure, so I was glad to do it and glad to see MadChess confirm I played accurately from move 16 on.

I like the checkmate configuration at the end of the game: My opponent chases my pawn, walking right into a discovered check / pawn promotion mate.

Knight Outpost

A knight positioned on an outpost controls opponent territory, restricting movement of the opponent’s pieces on the opponent’s side of the board. An outpost is defined as a square on the fifth or sixth rank, occupied by a minor piece (usually a knight), supported by its own pawn, and positioned such that it cannot ever be attacked by an opposing pawn. In other words, the opponent has no pawns on the neighboring files, or if the opponent has pawns on the neighboring files, they’ve advanced even with or beyond the outpost square.

r4rk1/1qb2ppp/1pN2n2/pP2p3/P3P3/4BP2/3RQ1PP/3R2K1 b - - 0 1

Red highlights in the above position indicate squares in black territory attacked by the white knight on c6. Yellow highlights indicate squares in white territory attacked by the same knight.

Controlling Space

Controlling board space- especially central squares- provides room to maneuver pieces. It cramps the opponent’s position, who will have difficulty bringing pieces out from behind their pawns. And it enables a quick redeployment of pieces from one zone of action (queenside, for example) to another zone of action (kingside) to initiate an attack or muster a defense around the king.

Be careful not to overextend when grabbing space. In the following position, white appears to control more space than black. Black’s counterplay demonstrates, however, that white merely occupies space but does not control it.

r1bq1rk1/ppp1ppbp/n2p1np1/4P3/2PP1P2/2N2N2/PP4PP/R1BQKB1R b KQ - 0 1

Black moves his knight to safety (and attacks the e5 central square) then takes advantage of white’s greediness.

Fortunes have changed. Now black controls more territory.

MadChess 3.0 Beta 4b7963b (Remove Aspiration Windows)

When analyzing a Carlsen versus Vachier-Lagrave game, I noticed MadChess 3.0 Beta struggling to find Magnus Carlsen’s crushing 23rd move, d6, in the following position.

2r2rk1/1ppq2b1/1n6/1N1Ppp2/p7/Pn2BP2/1PQ1BP2/3RK2R w K - 0 23

In the engine output displayed by the Hiarcs Chess GUI, I noticed MadChess kept restarting its search of ply 18. It indicated it was searching the first move (of 47 legal moves), second move, third move, etc… then would restart searching the first move again, still on ply 18. It restarted searching the first move of ply 18 numerous times. I suspected this was due to search instability caused by aspiration windows: searching a window centered around the previous ply’s score (ply 17 for this position) causes a fail high, the window is expanded in the direction of the fail high, sometimes (bizarrely) this causes a fail low, the window is expanded in the direction of the fail low, causing a fail high, low, high, etc… until the window is wide enough in both directions to return a stable score.

For this position, with aspiration windows enabled (by default they are), MadChess took four minutes to find Carlsen’s move. Even though MadChess is single-threaded, it has a non-deterministic search because it generates random Zobrist position keys (for the initial key, piece squares, side-to-move, castling rights, and en passant squares). Due to this non-determinism, in some cases restarting MadChess and searching the position again caused MadChess to recommend sub-optimal moves, unable to find Carlsen’s move even after 18 minutes, when I gave up.

I’ve long suspected aspiration windows are worthless, so I disabled them, produced a new build of MadChess, restarted the Hiracs Chess GUI, and searched the position again. MadChess found Carlsen’s move in 45 seconds. Restarting MadChess and searching the position again reliably found Carlsen’s move at ply 18 within 40 – 50 seconds.

Knowing the performance of a chess engine on one particular position is not indicative of how it performs in games against a variety of opponents, I decided to remove the aspiration window code (not merely disable it), then run a gauntlet tournament against ten opponents. I removed the following code.

The tournament confirmed my suspicions. MadChess performed 9 Elo stronger without aspiration windows.

See my Are Aspiration Windows Worthless? post on the TalkChess forum for a discussion of this blog post.

 

Feature Category Date Commit1 WAC2 Elo Rating3 Improvement
Remove Aspiration Windows Search 2020 Dec 20 4b7963b 290 2530 +9
Time Management Search 2020 Dec 19 d143bb5 286 2521 +8
Crash Bug Search 2020 Aug 29 2d855ec 288 2513 +0
King Safety Evaluation 2020 Aug 16 6794c89 288 2513 +63
Eval Param Tuning Evaluation 2020 Jul 23 bef88d5 283 2450 +30
Late Move Pruning Search 2020 Feb 08 6f3d17a 288 2420 +29
Piece Mobility Evaluation 2020 Feb 01 5c5d4fc 282 2391 +62
Passed Pawns Evaluation 2018 Dec 27 103 279 2329 +119
Staged Move Generation Search 2018 Dec 15 93 275 2210 +39
History Heuristics Search 2018 Dec 03 84 275 2171 +28
Eval Param Tuning Evaluation 2018 Nov 24 75 272 2143 +47
Sophisticated Search
Material and Piece Location
Baseline 2018 Nov 08 58 269 2096 0
  1. GitHub commit (hash) or Subversion source code revision (integer)
  2. Win At Chess position test, 3 seconds per position
  3. Bullet chess, 2 min / game + 1 sec / move

MadChess 3.0 Beta d143bb5 (Time Management)

I improved MadChess 3.0 Beta’s time management. I added code that increases MoveTimeSoftLimit, a TimeSpan variable that controls how long the engine examines a position (in a timed game) before responding with its move. The code increases MoveTimeSoftLimit 25% each ply (depth >= 9) if the score decreases at least one third of a pawn from the prior ply. In some engines this is known as “panic time.” The engine notices the score dropping and- to anthropomorphize it- panics like a human chess player would, spending more time than usual searching for a move that prevents its position from crumbling.

In MadChess 3.0 Beta, when it’s the engine’s turn to move (in a timed game), it allots time to search for a best move. It calculates MoveTimeSoftLimit by examining the game clock and the current position. It then calculates MoveTimeHardLimit simply by multiplying MoveTimeSoftLimit by four. The soft time limit is examined each ply. If the engine already has used 70 / 128ths of the allotted time (55%) or more, it replies with the best move found so far rather than begin searching the next ply (because it anticipates not having enough time to complete the search). Once MadChess begins searching a ply, it will not interrupt the search unless it’s reached or exceeded the MoveTimeHardLimit.

In addition, I improved code that calculates move time limits when playing a game with a traditional clock (non Fischer clock). Previously, MadChess 3.0 Beta mismanaged time in non Fischer clock games and occasionally lost on time. Now its playing strength in non Fischer clock games is on par with its strength in Fischer clock games. Usually I test MadChess in tournaments that use a Fischer clock (my computer opponent rating lists all use a Fischer clock), so playing games at 20 moves / 1 min (repeating) was special testing I did for this feature- but don’t intend to continue- to eliminate an engine deficiency. Considering “taste and comfort are personal,” as my father says, I recognize other people may prefer games with a traditional clock. So I’ve ensured MadChess plays well in those time controls.

I did not test sudden death time controls. Why? Because time scrambles don’t produce quality chess by humans or computer chess engines. In my opinion, MadChess’ performance in sudden death time control is not worth testing.

This “panic time” code increased the playing strength of MadChess 3.0 Beta by 8 Elo.

 

Feature Category Date Commit1 WAC2 Elo Rating3 Improvement
Time Management Search 2020 Dec 19 d143bb5 286 2521 +8
Crash Bug Search 2020 Aug 29 2d855ec 288 2513 +0
King Safety Evaluation 2020 Aug 16 6794c89 288 2513 +63
Eval Param Tuning Evaluation 2020 Jul 23 bef88d5 283 2450 +30
Late Move Pruning Search 2020 Feb 08 6f3d17a 288 2420 +29
Piece Mobility Evaluation 2020 Feb 01 5c5d4fc 282 2391 +62
Passed Pawns Evaluation 2018 Dec 27 103 279 2329 +119
Staged Move Generation Search 2018 Dec 15 93 275 2210 +39
History Heuristics Search 2018 Dec 03 84 275 2171 +28
Eval Param Tuning Evaluation 2018 Nov 24 75 272 2143 +47
Sophisticated Search
Material and Piece Location
Baseline 2018 Nov 08 58 269 2096 0
  1. GitHub commit (hash) or Subversion source code revision (integer)
  2. Win At Chess position test, 3 seconds per position
  3. Bullet chess, 2 min / game + 1 sec / move