Improving positional play

Discussion of chess software programming and technical issues.

Moderator: Ras

User avatar
algerbrex
Posts: 608
Joined: Sun May 30, 2021 5:03 am
Location: United States
Full name: Christian Dean

Improving positional play

Post by algerbrex »

This afternoon I reached out to the chess community on Reddit and asked if any strong, or even titled players would be willing to play against Blunder on lichess.com. A FIDE national master was kind enough to play against Blunder and share some advice after the game. One area he touched on was that Blunder had no idea how to create an initiative once the position was closed. And from there he built up an attack around the king, and slowly crushed Blunder. He played as white:

[pgn]
[Event "Casual Blitz game"]
[Site "https://lichess.org/EIWHyQ5d"]
[Date "2021.11.23"]
[White "teoeo"]
[Black "blunder_engine"]
[Result "1-0"]
[UTCDate "2021.11.23"]
[UTCTime "21:04:07"]
[WhiteElo "2408"]
[BlackElo "2268"]
[WhiteTitle "NM"]
[BlackTitle "BOT"]
[Variant "Standard"]
[TimeControl "300+0"]
[ECO "D00"]
[Opening "Queen's Pawn Game: Mason Variation"]
[Termination "Normal"]
[Annotator "lichess.org"]

1. d4 d5 2. Bf4 { D00 Queen's Pawn Game: Mason Variation } Nf6 3. e3 e6 4. Nf3 Be7 5. Nbd2 c5 6. c3 Nc6 7. Bd3 O-O 8. Ne5 Qb6 9. Rb1 c4 10. Bc2 Qa5?! { (0.87 → 1.55) Inaccuracy. Nxe5 was best. } (10... Nxe5 11. dxe5) 11. a3 Bd7?! { (1.33 → 2.18) Inaccuracy. Qd8 was best. } (11... Qd8 12. O-O) 12. Qf3? { (2.18 → 1.03) Mistake. g4 was best. } (12. g4 Rad8) 12... Qb6?! { (1.03 → 1.91) Inaccuracy. Nxe5 was best. } (12... Nxe5 13. dxe5 Ne8 14. Qd1 Qd8 15. Qh5 f5 16. Nf3 Rf7 17. h4 g6 18. Qh6 Bf8 19. Qg5) 13. Qh3 h6? { (2.42 → 4.64) Mistake. g6 was best. } (13... g6 14. Bh6) 14. Bxh6 gxh6?! { (5.00 → 6.94) Inaccuracy. Qd8 was best. } (14... Qd8 15. Bf4) 15. Qxh6 Nxe5 16. dxe5 Ne4 17. Nxe4 dxe4 18. Bxe4 f5 19. exf6 Rxf6 20. Qh7+ Kf8 21. Qh8+ Kf7 22. Qxa8 Bc6 23. Bxc6 Qxc6 24. O-O? { (5.99 → 3.49) Mistake. Qh8 was best. } (24. Qh8) 24... Rg6 25. g3 a6?? { (3.31 → 8.27) Blunder. Rg8 was best. } (25... Rg8 26. Qxa7) 26. Qb8 Rg5 27. Rbd1 Rd5 28. Rxd5 Qxd5 29. Qf4+ Bf6 30. e4 Qe5 31. Qxe5 Bxe5 32. f4 Bd6 33. e5 Be7 34. Kg2 Bc5 35. Kf3 Ke7 36. Ke4 a5 37. g4 a4 38. f5 Kf7 39. Rd1 exf5+ 40. gxf5 b6 41. Rd7+ Ke8 42. Rb7 Kd8 43. h4 Kc8 44. Rf7 Kd8 45. h5 Ke8 46. e6 Bf8 47. f6 b5 48. Rg7 b4 49. h6 Bxg7 50. hxg7 Kd8 51. g8=Q+ Kc7 52. Qf7+ Kb6 53. Qd7 bxc3 54. Qd6+ Kb7 55. e7 cxb2 56. Qb4+ Ka7 57. e8=Q b1=B+ 58. Kd4 Bc2 59. Qeb8+ Ka6 60. Qa8# { White wins by checkmate. } 1-0
[/pgn]

I'm currently going to run through the game myself and have Blunder do some analysis to try to identify some key points where it blundered badly.

Of course, I'm aware of PSQTs to help improve positional play, and I've already turned a pretty decent set for Blunder. But does anyone have some recommendations on how to further improve engine play in closed positions? It's already hard enough to get Blunder to play sound quiet moves in normal positions, let alone closed ones. That seems to be the usual trend. A blunder can spot mid-level tactics pretty well, but it will still "blunder" when it's forced to play a careful positional game.

I'm also aware that Blunder's king safety was exploited here too, so that's something I'll need to work on...since it's currently non-existent :lol:

Also, here was a fun game it played against another user on lichess, rated 2200, again with Blunder as black:

[pgn]
[Event "Casual Blitz game"]
[Site "https://lichess.org/Hbmj3ems"]
[Date "2021.11.23"]
[White "CrazyMerlyn"]
[Black "blunder_engine"]
[Result "0-1"]
[UTCDate "2021.11.23"]
[UTCTime "20:57:46"]
[WhiteElo "2207"]
[BlackElo "2268"]
[BlackTitle "BOT"]
[Variant "Standard"]
[TimeControl "300+2"]
[ECO "C56"]
[Opening "Italian Game: Scotch Gambit, Nakhmanson Gambit"]
[Termination "Normal"]
[Annotator "lichess.org"]

1. e4 e5 2. Nf3 Nc6 3. d4 exd4 4. Bc4 Nf6 5. O-O Nxe4 6. Nc3 { C56 Italian Game: Scotch Gambit, Nakhmanson Gambit } dxc3 7. Bxf7+ Kxf7 8. Qd5+ Ke8 9. Re1 Qf6 10. Rxe4+ Be7 11. Bg5 Qf7 12. Qc5 d5 13. Rxe7+ Nxe7 14. Re1 Be6 15. Nd4 cxb2 16. Nxe6 Qxe6 { White resigns. } 0-1
[/pgn]
Madeleine Birchfield
Posts: 512
Joined: Tue Sep 29, 2020 4:29 pm
Location: Dublin, Ireland
Full name: Madeleine Birchfield

Re: Improving positional play

Post by Madeleine Birchfield »

The biggest way to improve the positional play of your engine is to use a neural network for the opening and middlegame. Engines using only handcrafted evaluation have a lot of trouble with positional play, and this was still evident even in Stockfish 11 and Stockfish 12 dev (before it adopted neural networks), while engines using neural networks are able to handle closed positions much better (and this is evident in weaker engines such as Seer).
User avatar
algerbrex
Posts: 608
Joined: Sun May 30, 2021 5:03 am
Location: United States
Full name: Christian Dean

Re: Improving positional play

Post by algerbrex »

Madeleine Birchfield wrote: Wed Nov 24, 2021 12:29 am The biggest way to improve the positional play of your engine is to use a neural network for the opening and middlegame. Engines using only handcrafted evaluation have a lot of trouble with positional play, and this was still evident even in Stockfish 11 and Stockfish 12 dev (before it adopted neural networks), while engines using neural networks are able to handle closed positions much better (and this is evident in weaker engines such as Seer).
Well eventually Blunder will have simple NN in a future version, and then something more advanced later. But for now, I think I'd like to stick to HCE. But I have heard and seen some how positionally sound engines that use NN are. It's pretty neat to see.
User avatar
algerbrex
Posts: 608
Joined: Sun May 30, 2021 5:03 am
Location: United States
Full name: Christian Dean

Re: Improving positional play

Post by algerbrex »

After doing a little analysis on the game Blunder played against the NM, something funny seems to be going on. In this position,

[fen]r4rk1/pp1bbppp/1qn1pn2/3pN3/2pP1B2/P1P1P2Q/1PBN1PPP/1R2K2R b K - 4 13[/fen]

Blunder played h7h6, a pretty big blunder. Blunder played that move with 3:45 left on the clock and if I recall correctly, there was no increment. According to Blunder's time management, it should've spent 2.5% of the time left, so about 5.5 seconds. So I input the above position and the time left into Blunder and let it think, and it instead chooses to play Rd8 first.

Code: Select all

position fen r4rk1/pp1bbppp/1qn1pn2/3pN3/2pP1B2/P1P1P2Q/1PBN1PPP/1R2K2R b K - 4 13
go btime 225000
info depth 1 score cp 33 nodes 116 nps 22277 time 5 pv h7h6 e5d7 f6d7
info depth 2 score cp 13 nodes 450 nps 29453 time 15 pv c6e5 f4e5
info depth 3 score cp -14 nodes 2100 nps 267535 time 7 pv h7h6 e1g1 a7a6
info depth 4 score cp -25 nodes 4471 nps 660963 time 6 pv h7h6 e5d7 f6d7 e1g1
info depth 5 score cp -11 nodes 5093 nps 710861 time 7 pv h7h6 e5d7 f6d7 e1g1 a7a6
info depth 6 score cp -25 nodes 16511 nps 856897 time 19 pv h7h6 e5d7 f6d7 e1g1 a7a6 h3g4
info depth 7 score cp -16 nodes 37297 nps 681241 time 54 pv h7h6 e5d7 f6d7 e1g1 a7a6 d2f3 e7f6
info depth 8 score cp -36 nodes 176138 nps 1083876 time 162 pv a8d8 e1g1 h7h6 b2b3 c4b3 b1b3 b6a6 c2d3
info depth 9 score cp -30 nodes 161469 nps 1055744 time 152 pv h7h6 e5d7 f6d7 h3g3 h6h5 e1g1 a7a5 f4c7 h5h4
info depth 10 score cp -25 nodes 291503 nps 1108558 time 262 pv a8d8 e1g1 h7h6 e5d7 d8d7 f1e1 a7a6 e3e4 d5e4 d2e4
info depth 11 score cp -32 nodes 238786 nps 1036857 time 230 pv a8d8 e1g1 h7h6 e5d7 d8d7 f1e1 a7a6 e3e4 f6e4 d2e4 d5e4 c2e4
info depth 12 score cp -26 nodes 432542 nps 1079738 time 400 pv a8d8 e1g1 h7h6 e5d7 d8d7 e3e4 f6e4 d2e4 d5e4 c2e4 f7f5 e4f3
info depth 13 score cp -25 nodes 623629 nps 1107829 time 562 pv a8d8 e1g1 h7h6 e5d7 d8d7 f4h6 g7h6 h3h6 a7a6 h6g5 g8h8 g5h6 h8g8
info depth 14 score cp -32 nodes 1829079 nps 1092579 time 1674 pv a8d8 e1g1 h7h6 e5d7 d8d7 f1e1 a7a6 e3e4 f6e4 d2e4 d5e4 c2e4 e7f6 h3g4
bestmove a8d8
So there seems to be some discrepancy here. Now of course it still looks like it was going to blunder later by playing h7h6, but the point remains that it shouldn't have chosen that given the circumstances. It had plenty of time to push the blunder back.

Actually, having written this whole post out, I just realized that I'm sure whether or not I had removed the depth restriction from lichess config file before or after Blunder played the NM, so I'm thinking that was just the issue :roll: not sure, I'll probably do some more investigating.
gaard
Posts: 463
Joined: Mon Jun 07, 2010 3:13 am
Location: Holland, MI
Full name: Martin W

Re: Improving positional play

Post by gaard »

algerbrex wrote: Wed Nov 24, 2021 1:54 am After doing a little analysis on the game Blunder played against the NM, something funny seems to be going on. In this position,

[fen]r4rk1/pp1bbppp/1qn1pn2/3pN3/2pP1B2/P1P1P2Q/1PBN1PPP/1R2K2R b K - 4 13[/fen]

Blunder played h7h6, a pretty big blunder. Blunder played that move with 3:45 left on the clock and if I recall correctly, there was no increment. According to Blunder's time management, it should've spent 2.5% of the time left, so about 5.5 seconds. So I input the above position and the time left into Blunder and let it think, and it instead chooses to play Rd8 first.

Code: Select all

position fen r4rk1/pp1bbppp/1qn1pn2/3pN3/2pP1B2/P1P1P2Q/1PBN1PPP/1R2K2R b K - 4 13
go btime 225000
info depth 1 score cp 33 nodes 116 nps 22277 time 5 pv h7h6 e5d7 f6d7
info depth 2 score cp 13 nodes 450 nps 29453 time 15 pv c6e5 f4e5
info depth 3 score cp -14 nodes 2100 nps 267535 time 7 pv h7h6 e1g1 a7a6
info depth 4 score cp -25 nodes 4471 nps 660963 time 6 pv h7h6 e5d7 f6d7 e1g1
info depth 5 score cp -11 nodes 5093 nps 710861 time 7 pv h7h6 e5d7 f6d7 e1g1 a7a6
info depth 6 score cp -25 nodes 16511 nps 856897 time 19 pv h7h6 e5d7 f6d7 e1g1 a7a6 h3g4
info depth 7 score cp -16 nodes 37297 nps 681241 time 54 pv h7h6 e5d7 f6d7 e1g1 a7a6 d2f3 e7f6
info depth 8 score cp -36 nodes 176138 nps 1083876 time 162 pv a8d8 e1g1 h7h6 b2b3 c4b3 b1b3 b6a6 c2d3
info depth 9 score cp -30 nodes 161469 nps 1055744 time 152 pv h7h6 e5d7 f6d7 h3g3 h6h5 e1g1 a7a5 f4c7 h5h4
info depth 10 score cp -25 nodes 291503 nps 1108558 time 262 pv a8d8 e1g1 h7h6 e5d7 d8d7 f1e1 a7a6 e3e4 d5e4 d2e4
info depth 11 score cp -32 nodes 238786 nps 1036857 time 230 pv a8d8 e1g1 h7h6 e5d7 d8d7 f1e1 a7a6 e3e4 f6e4 d2e4 d5e4 c2e4
info depth 12 score cp -26 nodes 432542 nps 1079738 time 400 pv a8d8 e1g1 h7h6 e5d7 d8d7 e3e4 f6e4 d2e4 d5e4 c2e4 f7f5 e4f3
info depth 13 score cp -25 nodes 623629 nps 1107829 time 562 pv a8d8 e1g1 h7h6 e5d7 d8d7 f4h6 g7h6 h3h6 a7a6 h6g5 g8h8 g5h6 h8g8
info depth 14 score cp -32 nodes 1829079 nps 1092579 time 1674 pv a8d8 e1g1 h7h6 e5d7 d8d7 f1e1 a7a6 e3e4 f6e4 d2e4 d5e4 c2e4 e7f6 h3g4
bestmove a8d8
So there seems to be some discrepancy here. Now of course it still looks like it was going to blunder later by playing h7h6, but the point remains that it shouldn't have chosen that given the circumstances. It had plenty of time to push the blunder back.

Actually, having written this whole post out, I just realized that I'm sure whether or not I had removed the depth restriction from lichess config file before or after Blunder played the NM, so I'm thinking that was just the issue :roll: not sure, I'll probably do some more investigating.
Looks more like a king safety/pawn shelter related evaluation issue, given it's still played after a8d8 e1g1. What does your king safety evaluation look like? Also, it's not clear to me if it's really a positional error if it can be capitalized on in the next move tactically. Maybe too many reductions?
User avatar
algerbrex
Posts: 608
Joined: Sun May 30, 2021 5:03 am
Location: United States
Full name: Christian Dean

Re: Improving positional play

Post by algerbrex »

gaard wrote: Wed Nov 24, 2021 2:51 am Looks more like a king safety/pawn shelter related evaluation issue, given it's still played after a8d8 e1g1.
Oh, definitely. In this case, it's definitely a search issue/king safety issue.
gaard wrote: Wed Nov 24, 2021 2:51 am What does your king safety evaluation look like?
King safety is non-existent. I just haven't been able to get it to work well these past two weeks or so. This is annoying since I know it would improve Blunder pretty well. In many of the games, Blunder plays, against humans and engines, a consistent theme is it'll happily let enemy pieces build up around its king and only realize the danger when it's too late, much like in the position above.
gaard wrote: Wed Nov 24, 2021 2:51 am Also, it's not clear to me if it's really a positional error if it can be capitalized on in the next move tactically. Maybe too many reductions?
Right not positional. And perhaps so, I'll look into that. I'm thinking about removing all pruning and reductions from Blunder and testing the gain king safety gets me, since I've heard changes in the evaluation can greatly affect certain pruning and reductions that happen in the search.
Uri Blass
Posts: 10794
Joined: Thu Mar 09, 2006 12:37 am
Location: Tel-Aviv Israel

Re: Improving positional play

Post by Uri Blass »

I do not know how you tried to evaluate king safety but basically the idea of king safety evaluation is mainly that it is bad if the opponent attack squares near your king when you do not defend them so you give a bonus for undefended squares near the king that the opponent attack when there are no good defendors of it(good defendors are bishop,knight and rook but no king and queen).

Of course not having pawns near the king is also not very good but it is no big problem if the opponent does not attack the squares.
Uri Blass
Posts: 10794
Joined: Thu Mar 09, 2006 12:37 am
Location: Tel-Aviv Israel

Re: Improving positional play

Post by Uri Blass »

Madeleine Birchfield wrote: Wed Nov 24, 2021 12:29 am The biggest way to improve the positional play of your engine is to use a neural network for the opening and middlegame. Engines using only handcrafted evaluation have a lot of trouble with positional play, and this was still evident even in Stockfish 11 and Stockfish 12 dev (before it adopted neural networks), while engines using neural networks are able to handle closed positions much better (and this is evident in weaker engines such as Seer).
I disagree and for me it is not understanding.
For me understanding is something that you can explain why and not hide behind the words:"neural network"

If your engine have a static evaluation of +3 for white and you have no idea why because from your point of view the position is equal then it is not a positional understanding from my point of view.

I hate seeing a huge score without understanding the reason for it and I believe that this huge score is not good from practical point of view because in a game there is a big probablity that the opponent will have no idea how to translate the huge score to victory so from my point of view old engines are better for analysis in many positions because they can give a move that they do not understand that it is losing so there is a good chance that the human opponent is not going to understand how to win and not the new engine that believe I am playing against super players and if everything lose can suggest me a move that gives no practical chances.
User avatar
algerbrex
Posts: 608
Joined: Sun May 30, 2021 5:03 am
Location: United States
Full name: Christian Dean

Re: Improving positional play

Post by algerbrex »

Uri Blass wrote: Wed Nov 24, 2021 6:58 am I do not know how you tried to evaluate king safety but basically the idea of king safety evaluation is mainly that it is bad if the opponent attack squares near your king when you do not defend them so you give a bonus for undefended squares near the king that the opponent attack when there are no good defendors of it(good defendors are bishop,knight and rook but no king and queen).

Of course not having pawns near the king is also not very good but it is no big problem if the opponent does not attack the squares.
Yup I'm trying something similar, with not very good results. I'm using the approach of adding up 'points', based on what kind of piece is attacking the king "zone" (all the squares the king can move to, plus the squares surrounding those), and the king zone level (outside squares is level 2, inside squares are level 1). For example, if I knight is attacking an inner square, I'll add a bonus of 2 to the points count.

Then of course, as you likely know, the value of the points I collect indexes a non-linear king safety table, which gives the final score.

Unfortunately, this hasn't really worked very well, and I've only gotten about 14 Elo from it, which is nice, but not the 50-60+ Elo I know king-safety is worth. So I need to figure out where things are going wrong, the game with the NM should help with that since he pretty easily exploited Blunder's lack of king safety.
jdart
Posts: 4398
Joined: Fri Mar 10, 2006 5:23 am
Location: http://www.arasanchess.org

Re: Improving positional play

Post by jdart »

King safety is somewhat difficult. If you tune it up too high, the program will sacrifice pieces for an attack, and the attack may be unsound. Another problem is blocked positions. If there is what looks to the program like an attack, but the opposing side can't actually penetrate the pawn shield, then the score shouldn't be too high. Lacking a NN, the next best thing is to employ automated parameter tuning to find the right values for the eval weights.

I will also mention, as I have said here before: a major cause of program weaknesses is bugs. You can add all the program features you like but if there are fundamental bugs, then you may not get the performance you might expect. That is why "perft" and other sanity checks are important. So is making sure every piece of the program does exactly what it's designed to do, and in line with good practice.