3

I'm using Stockfish to analyze my blunder filled games for blunders.

Let's say you send stockfish a FEN for a position and then calculate to a given depth ...

position fen the-starting-position
go depth 15

Now let's say a move has been made. I can either send stockfish the move...

position move the-move

or send it the fen that results from the new move.

position fen the-postition-after-the-move

Is Stockfish more efficient when you send it to the former? That is, does it remember the evaluation from the starting position and use it as a starting point for analyzing the new position after you give it a 'position move ...' command? And does it not remember the prior calculations if you just send it the next FEN in the sequences?


And a similar question. If you tell Stockfish to analyze to a depth on a position, and then tell it to analyze to a deeper depth, does it start that second analysis from where the prior analysis stopped?

position fen the-starting-position
go depth 15
go depth 20   
2
  • Not an expert so I'm not going to post this as an answer, but I'm pretty certain the answer is yes: that's exactly what hash tables do. Stockfish uses the previous move's principal variation to guide its move ordering (i.e. which move to search first) for this move as well. – Allure Jan 27 at 0:21
  • Yeah, I'm thinking this is true, both for the subsequent move and for going deeper on the same move. I also think that it doesn't matter if you just send a "position fen fen-after-next-move" vs "position move next-move" but I'd like to be sure. – honkskillet Jan 27 at 0:32
4

UCI protocol

Based on your answer, it looks like there is a typo and a misunderstanding.

The typo: It should be position ... moves, not position ... move.

The misunderstanding: The UCI protocol is stateless in the sense that you need to give the entire list of moves leading to the intended position every time, or the position itself.

Examples:

  • position startpos moves d1b1 is invalid, because d1b1 is not a legal move in the starting position.

  • position fen 3rr1k1/1b3p1p/6p1/pp1p3B/3N1P2/P3P2P/1p4P1/1R3RK1 b - - 1 28 is valid

  • position startpos moves e2e3 d7d6 d1f3 b8d7 f1c4 e7e6 d2d4 d6d5 c4d3 g8f6 c2c4 f8b4 c1d2 b4d2 b1d2 d5c4 d2c4 e8g8 c4e5 d7e5 d4e5 f6d5 f3e4 g7g6 g1f3 c7c6 e1g1 b7b5 a1d1 a7a5 a2a3 c8a6 f3d4 c6c5 d4c6 d8c7 e4d5 e6d5 c6d4 c7e5 d4f3 e5h5 h2h3 a6b7 d3e2 c5c4 f3d4 a8d8 e2f3 f8e8 f3h5 c4c3 f2f4 c3b2 d1b1 is valid and sets up the same position

  • position startpos moves e2e3 followed by position startpos moves d7d6 is invalid, because d7d6 is not a legal move in the starting position.

Differences between fen and moves

It's up to the engine if it can do something useful with the list of moves. For Stockfish, it's almost the same as not having the list, with no difference in efficiency. But having the list of moves informs Stockfish about possible repetitions, so it can avoid or aim for repeating an earlier position three times.

3
  • But Stockfish is stateful and it doesn't matter if you send it a (properly formatted) 'position moves ...' or 'position fen ...', right? – honkskillet Jan 27 at 18:01
  • should that be 'position startpos moves ....' ? – honkskillet Jan 30 at 5:03
  • @honkskillet Yes, fixed. – Niklas Jan 31 at 2:12
1

EDIT

I will leave the below incorrect answer in case others make the same mistake I did. When using position moves (not position move), you have to provide the entire move list, not just the most recent move.


To try to answer the first part of my question, I analyze a game where first time through I used position move the-move and the second time through I used 'position fen the-fen-after-the-move'.

Here is what I got, through depth of 4...

||Move #55 : 1. e3 d6 2. Qf3 Nd7 3. Bc4 e6 4. d4 d5 5. Bd3 Ngf6 6. c4 Bb4+ 7. Bd2 Bxd2+ 8. Nxd2 dxc4 9. Nxc4 O-O 10. Ne5 Nxe5 11. dxe5 Nd5 12. Qe4 g6 13. Nf3 c6 14. O-O b5 15. Rad1 a5 16. a3 Ba6 17. Nd4 c5 18. Nc6 Qc7 19. Qxd5 exd5 20. Nd4 Qxe5 21. Nf3 Qh5 22. h3 Bb7 23. Be2 c4 24. Nd4 Rad8 25. Bf3 Rfe8 26. Bxh5 c3 27. f4 cxb2 28. Rb1
Sending to Stockfish: position move d1b1
Sending to Stockfish: go depth 12
info depth 1 seldepth 1 multipv 1 score cp 56 nodes 63 nps 63000 time 1 pv g1f3
info depth 1 seldepth 1 multipv 2 score cp 44 nodes 63 nps 63000 time 1 pv d2d4
info depth 1 seldepth 1 multipv 3 score cp 36 nodes 63 nps 63000 time 1 pv e2e4
info depth 2 seldepth 2 multipv 1 score cp 56 nodes 130 nps 130000 time 1 pv g1f3 g8f6
info depth 2 seldepth 2 multipv 2 score cp 44 nodes 130 nps 130000 time 1 pv d2d4 d7d5
info depth 2 seldepth 2 multipv 3 score cp 36 nodes 130 nps 130000 time 1 pv e2e4 e7e5
info depth 3 seldepth 3 multipv 1 score cp 56 nodes 205 nps 205000 time 1 pv g1f3 g8f6 e2e3
info depth 3 seldepth 3 multipv 2 score cp 44 nodes 205 nps 205000 time 1 pv d2d4 d7d5 e2e3
info depth 3 seldepth 3 multipv 3 score cp 36 nodes 205 nps 205000 time 1 pv e2e4 e7e5 b1c3
info depth 4 seldepth 4 multipv 1 score cp 56 nodes 291 nps 291000 time 1 pv g1f3 g8f6 e2e3 e7e6
info depth 4 seldepth 4 multipv 2 score cp 44 nodes 291 nps 291000 time 1 pv d2d4 d7d5 e2e3 e7e6
info depth 4 seldepth 4 multipv 3 score cp 36 nodes 291 nps 291000 time 1 pv e2e4 e7e5 b1c3 b8c6


||Move #55 : 1. e3 d6 2. Qf3 Nd7 3. Bc4 e6 4. d4 d5 5. Bd3 Ngf6 6. c4 Bb4+ 7. Bd2 Bxd2+ 8. Nxd2 dxc4 9. Nxc4 O-O 10. Ne5 Nxe5 11. dxe5 Nd5 12. Qe4 g6 13. Nf3 c6 14. O-O b5 15. Rad1 a5 16. a3 Ba6 17. Nd4 c5 18. Nc6 Qc7 19. Qxd5 exd5 20. Nd4 Qxe5 21. Nf3 Qh5 22. h3 Bb7 23. Be2 c4 24. Nd4 Rad8 25. Bf3 Rfe8 26. Bxh5 c3 27. f4 cxb2 28. Rb1
Sending to Stockfish: position fen 3rr1k1/1b3p1p/6p1/pp1p3B/3N1P2/P3P2P/1p4P1/1R3RK1 b - - 1 28
Sending to Stockfish: go depth 12
info depth 1 seldepth 1 multipv 1 score cp 44 nodes 122 nps 122000 time 1 pv g6h5 b1b2
info depth 1 seldepth 1 multipv 2 score cp 40 nodes 122 nps 122000 time 1 pv e8e3 b1b2 g6h5 b2b5 b7a6
info depth 1 seldepth 1 multipv 3 score cp 9 nodes 122 nps 122000 time 1 pv b7a6
info depth 2 seldepth 2 multipv 1 score cp 44 nodes 234 nps 234000 time 1 pv g6h5 b1b2
info depth 2 seldepth 2 multipv 2 score cp 40 nodes 234 nps 234000 time 1 pv e8e3 b1b2 g6h5
info depth 2 seldepth 2 multipv 3 score cp 13 nodes 234 nps 234000 time 1 pv b7a6 d4c6
info depth 3 seldepth 3 multipv 1 score cp 48 nodes 444 nps 444000 time 1 pv g6h5 b1b2 b7a6
info depth 3 seldepth 3 multipv 2 score cp 40 nodes 444 nps 444000 time 1 pv e8e3 b1b2 g6h5
info depth 3 seldepth 3 multipv 3 score cp -56 nodes 444 nps 444000 time 1 pv b5b4 b1b2 g6h5
info depth 4 seldepth 4 multipv 1 score cp 44 nodes 691 nps 345500 time 2 pv g6h5 b1b2 b7a6 d4c6
info depth 4 seldepth 4 multipv 2 score cp 5 nodes 691 nps 345500 time 2 pv e8e3 h5f3 e3d3 b1b2
info depth 4 seldepth 4 multipv 3 score cp -56 nodes 691 nps 345500 time 2 pv b5b4 b1b2 g6h5 g1f2

Somewhat surprising to me it looks like when you send stockfish a move, the engine examines fewer nodes and the nps (nodes per second?) is less as well. The centipawn eval is different too indicating that (probably) 'position move ...' already has some knowledge of the position. BTW, I'm using this javascript WASM implementation of stockfish https://github.com/niklasf/stockfish.wasm

1
  • Take a hard look at the moves it's suggesting in that first batch. g1f3, d2d4, e2e4. Looks like it's looking at the starting position, and not the position you set. – D M Jan 27 at 11:13
0

OK. Been playing with stockfish on the command line (and also learned from comments and other answers here).

  1. Does stockfish use calculation from the previously position when you send it a move list? YES The engine visits more nodes if you haven't done previous calculation.
ucinewgame
position startpos moves e2e3 d7d6  
go depth 12
info depth 1 seldepth 1 multipv 1 score cp 275 nodes 31 nps 10333 time 3 pv d1h5 bmc 3
info depth 2 seldepth 2 multipv 1 score cp 88 nodes 100 nps 25000 time 4 pv d2d4 c7c6 bmc 4.551
...
position startpos moves e2e3 d7d6 d1f3   //make 1 additional move
go depth 12
info depth 1 seldepth 1 multipv 1 score cp 31 nodes 31 nps 10333 time 3 pv b8c6 bmc 2
info depth 2 seldepth 2 multipv 1 score cp -22 nodes 88 nps 17600 time 5 pv g8h6 d2d4 bmc 2.034
...
ucinewgame  //reset the engine 
position startpos moves e2e3 d7d6 d1f3  
go depth 12
info depth 1 seldepth 1 multipv 1 score cp 79 nodes 38 nps 12666 time 3 pv g8f6 bmc 5
info depth 2 seldepth 2 multipv 1 score cp 63 nodes 73 nps 18250 time 4 pv g8f6 b2b3 bmc 2.585
  1. Does it have the same behavior if you send a FEN instead of a move list. YES (exception being if repetitions are being evaluated)
ucinewgame
position fen rnbqkbnr/ppp1pppp/3p4/8/8/4P3/PPPP1PPP/RNBQKBNR w KQkq - 0 2
go depth 12
info depth 1 seldepth 1 multipv 1 score cp 275 nodes 31 nps 10333 time 3 pv d1h5 bmc 3
info depth 2 seldepth 2 multipv 1 score cp 88 nodes 100 nps 20000 time 5 pv d2d4 c7c6 bmc 4.551
...
position fen rnbqkbnr/ppp1pppp/3p4/8/8/4PQ2/PPPP1PPP/RNB1KBNR b KQkq - 1 2
go depth 12
info depth 1 seldepth 1 multipv 1 score cp 31 nodes 31 nps 10333 time 3 pv b8c6 bmc 2
info depth 2 seldepth 2 multipv 1 score cp -22 nodes 88 nps 17600 time 5 pv g8h6 d2d4 bmc 2.034
...
ucinewgame
position fen rnbqkbnr/ppp1pppp/3p4/8/8/4PQ2/PPPP1PPP/RNB1KBNR b KQkq - 1 2
go depth 12
info depth 1 seldepth 1 multipv 1 score cp 79 nodes 38 nps 19000 time 2 pv g8f6 bmc 5
info depth 2 seldepth 2 multipv 1 score cp 63 nodes 73 nps 18250 time 4 pv g8f6 b2b3 bmc 2.585
  1. If you tell stock to analyze a shallower then a deeper depth, does it remember the calculations? YES
ucinewgame
position fen rnbqkbnr/ppp1pppp/3p4/8/8/4PQ2/PPPP1PPP/RNB1KBNR b KQkq - 1 2
go depth 8
info depth 1 seldepth 1 multipv 1 score cp 79 nodes 38 nps 12666 time 3 pv g8f6 bmc 5
info depth 2 seldepth 2 multipv 1 score cp 63 nodes 73 nps 14600 time 5 pv g8f6 b2b3 bmc 2.585
info depth 3 seldepth 3 multipv 1 score cp 93 nodes 298 nps 42571 time 7 pv e7e5 d2d4 g8f6 bmc 4.33645
info depth 4 seldepth 4 multipv 1 score cp 41 nodes 503 nps 55888 time 9 pv e7e5 b1c3 g8f6 d2d4 bmc 2.24194
info depth 5 seldepth 5 multipv 1 score cp 78 nodes 754 nps 75400 time 10 pv g8f6 b1c3 c7c6 bmc 2.15908
info depth 6 seldepth 6 multipv 1 score cp 105 nodes 894 nps 74500 time 12 pv g8f6 b1c3 c7c6 b2b3 bmc 1.11625
info depth 7 seldepth 7 multipv 1 score cp 121 nodes 1670 nps 111333 time 15 pv g8f6 d2d4 e7e5 d4e5 d6e5 b1c3 bmc 0.577099
info depth 8 seldepth 8 multipv 1 score cp 166 nodes 2607 nps 144833 time 18 pv g8f6 b1c3 b8c6 d2d4 e7e5 bmc 0.29836
bestmove g8f6 ponder b1c3

go depth 12
info depth 1 seldepth 1 multipv 1 score cp 166 nodes 33 nps 11000 time 3 pv g8f6 bmc 1
info depth 2 seldepth 2 multipv 1 score cp 166 nodes 62 nps 15500 time 4 pv g8f6 b1c3 bmc 0.517
info depth 3 seldepth 3 multipv 1 score cp 166 nodes 92 nps 15333 time 6 pv g8f6 b1c3 b8c6 bmc 0.267289
info depth 4 seldepth 4 multipv 1 score cp 166 nodes 124 nps 17714 time 7 pv g8f6 b1c3 b8c6 d2d4 bmc 0.138188
info depth 5 seldepth 5 multipv 1 score cp 166 nodes 159 nps 17666 time 9 pv g8f6 b1c3 b8c6 d2d4 e7e5 bmc 0.0714434
info depth 6 seldepth 6 multipv 1 score cp 179 nodes 344 nps 31272 time 11 pv g8f6 d2d4 e7e5 d4e5 d6e5 bmc 0.0369362
...
info depth 11 seldepth 14 multipv 1 score cp 130 nodes 40317 nps 356787 time 113 pv e7e5 d2d4 g8f6 b1c3 f8e7 c1d2 b8c6 d4e5 c6e5 bmc 1.51836
info depth 12 seldepth 17 multipv 1 score cp 88 nodes 110722 nps 435913 time 254 pv b8c6 d2d4 g8f6 b1d2 c6b4 f1d3 e7e5 g1e2 b4d3 c2d3 f8e7 e1g1 e8g8 f3g3 e5d4 e2d4 c7c6 bmc 1.78499
bestmove b8c6 ponder d2d4

ucinewgame
position fen rnbqkbnr/ppp1pppp/3p4/8/8/4PQ2/PPPP1PPP/RNB1KBNR b KQkq - 1 2
go depth 12
info depth 1 seldepth 1 multipv 1 score cp 79 nodes 38 nps 19000 time 2 pv g8f6 bmc 5
info depth 2 seldepth 2 multipv 1 score cp 63 nodes 73 nps 24333 time 3 pv g8f6 b2b3 bmc 2.585
info depth 3 seldepth 3 multipv 1 score cp 93 nodes 298 nps 59600 time 5 pv e7e5 d2d4 g8f6 bmc 4.33645
info depth 4 seldepth 4 multipv 1 score cp 41 nodes 503 nps 71857 time 7 pv e7e5 b1c3 g8f6 d2d4 bmc 2.24194
info depth 5 seldepth 5 multipv 1 score cp 78 nodes 754 nps 83777 time 9 pv g8f6 b1c3 c7c6 bmc 2.15908
info depth 6 seldepth 6 multipv 1 score cp 105 nodes 894 nps 89400 time 10 pv g8f6 b1c3 c7c6 b2b3 bmc 1.11625
...
info depth 11 seldepth 14 multipv 1 score cp 111 nodes 58685 nps 413274 time 142 pv e7e5 d2d4 g8f6 b1c3 b8c6 c3d5 f8e7 f1b5 f6d5 f3d5 e8g8 b5c6 bmc 0.55823
info depth 12 seldepth 17 multipv 1 score cp 111 nodes 104872 nps 448170 time 234 pv g8f6 d2d4 e7e5 b1c3 b8c6 c3d5 f6d5 f3d5 d8e7 g1f3 e5e4 f3g5 f7f5 bmc 1.2886
bestmove g8f6 ponder d2d4

Interestingly by depth 12 the calculate all-in-one-go is actually testing fewer nodes. The inflection point for this particular position is between move 8 and , which makes sense because the shallow calculation only went up to depth 8. Beyond that depth it would seem stockfish is having to backtrack to broaden the tree.

This is what I had expected and seems like a logical way for stockfish to operate. But for a stockfish nube like myself it is nice to have it confirmed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.