- void update_stats(const Position& pos, Stack* ss, Move move, Move* quiets, int quietsCnt, int bonus);
+ void update_quiet_stats(const Position& pos, Stack* ss, Move move, Move* quiets, int quietCount, int bonus);
+ void update_capture_stats(const Position& pos, Move move, Move* captures, int captureCount, int bonus);
+
+ inline bool gives_check(const Position& pos, Move move) {
+ Color us = pos.side_to_move();
+ return type_of(move) == NORMAL && !(pos.blockers_for_king(~us) & pos.pieces(us))
+ ? pos.check_squares(type_of(pos.moved_piece(move))) & to_sq(move)
+ : pos.gives_check(move);
+ }
+
+ // perft() is our utility to verify move generation. All the leaf nodes up
+ // to the given depth are generated and counted, and the sum is returned.
+ template<bool Root>
+ uint64_t perft(Position& pos, Depth depth) {
+
+ StateInfo st;
+ uint64_t cnt, nodes = 0;
+ const bool leaf = (depth == 2 * ONE_PLY);
+
+ for (const auto& m : MoveList<LEGAL>(pos))
+ {
+ if (Root && depth <= ONE_PLY)
+ cnt = 1, nodes++;
+ else
+ {
+ pos.do_move(m, st);
+ cnt = leaf ? MoveList<LEGAL>(pos).size() : perft<false>(pos, depth - ONE_PLY);
+ nodes += cnt;
+ pos.undo_move(m);
+ }
+ if (Root)
+ sync_cout << UCI::move(m, pos.is_chess960()) << ": " << cnt << sync_endl;
+ }
+ return nodes;
+ }