- if (!expectedPosKey || pv3[0] != RMpv[0] || pv3[1] != RMpv[1])
- {
- pv3[0] = RMpv[0], pv3[1] = RMpv[1];
- StateInfo st[2];
- pos.do_move(RMpv[0], st[0], pos.gives_check(RMpv[0], CheckInfo(pos)));
- pos.do_move(RMpv[1], st[1], pos.gives_check(RMpv[1], CheckInfo(pos)));
- expectedPosKey = pos.key();
- pos.undo_move(RMpv[1]);
- pos.undo_move(RMpv[0]);
- }
+ void update(Position& pos, const std::vector<Move>& newPv) {
+
+ assert(newPv.size() >= 3);
+
+ // Keep track of how many times in a row 3rd ply remains stable
+ stableCnt = (newPv[2] == pv[2]) ? stableCnt + 1 : 0;
+
+ if (!std::equal(newPv.begin(), newPv.begin() + 3, pv))
+ {
+ std::copy(newPv.begin(), newPv.begin() + 3, pv);
+
+ StateInfo st[2];
+ pos.do_move(newPv[0], st[0], pos.gives_check(newPv[0], CheckInfo(pos)));
+ pos.do_move(newPv[1], st[1], pos.gives_check(newPv[1], CheckInfo(pos)));
+ expectedPosKey = pos.key();
+ pos.undo_move(newPv[1]);
+ pos.undo_move(newPv[0]);