+ const TTEntry* tte;
+ StateInfo st;
+ Position p(pos, pos.thread());
+ int ply = 0;
+
+ assert(bestMove != MOVE_NONE);
+
+ pv[ply] = bestMove;
+ p.do_move(pv[ply++], st);
+
+ // Extract moves from TT when possible. We try hard to always
+ // get a ponder move, that's the reason of ply < 2 conditions.
+ while ( (tte = retrieve(p.get_key())) != NULL
+ && tte->move() != MOVE_NONE
+ && (tte->type() == VALUE_TYPE_EXACT || ply < 2)
+ && move_is_legal(p, tte->move())
+ && (!p.is_draw() || ply < 2)
+ && ply < PLY_MAX)
+ {
+ pv[ply] = tte->move();
+ p.do_move(pv[ply++], st);
+ }
+ pv[ply] = MOVE_NONE;