Line data Source code
1 : #include "moveGen.hpp"
2 :
3 : #include "dynamicConfig.hpp"
4 : #include "logging.hpp"
5 : #include "material.hpp"
6 : #include "moveApply.hpp"
7 : #include "positionTools.hpp"
8 : #include "searcher.hpp"
9 : #include "tools.hpp"
10 :
11 46 : ScoreType randomMover(const Position& p, PVList& pv, const bool isInCheck) {
12 46 : MoveList moves;
13 46 : MoveGen::generate<MoveGen::GP_all>(p, moves, false);
14 46 : if (moves.empty()) return isInCheck ? matedScore(0) : 0;
15 : ///@todo this is slow because the static here implies a guard variable !!
16 46 : static std::random_device rd;
17 48 : static std::mt19937 g(rd()); // here really random
18 : std::ranges::shuffle(moves, g);
19 46 : for (const auto & it : moves) {
20 46 : Position p2 = p;
21 : #if defined(WITH_NNUE) && defined(DEBUG_NNUE_UPDATE)
22 : NNUEEvaluator evaluator = p.evaluator();
23 : p2.associateEvaluator(evaluator);
24 : #endif
25 46 : if (const MoveInfo moveInfo(p2, it); !applyMove(p2, moveInfo)) continue;
26 46 : pv.emplace_back(it); // updatePV
27 46 : const Square to = Move2To(it);
28 : // king capture (works only for most standard chess variants)
29 46 : if (p.c == Co_White && to == p.king[Co_Black]) return matingScore(0);
30 46 : if (p.c == Co_Black && to == p.king[Co_White]) return matingScore(0);
31 : return 0; // found one valid move
32 46 : }
33 : // no move is valid ...
34 0 : return isInCheck ? matedScore(0) : 0;
35 : }
|