@@ -457,7 +457,7 @@ inline int Yaxl(const int sq) {
457457
458458// Nodes Per Second
459459std::uint64_t Nps (const std::uint64_t nodes, const std::uint64_t ms) {
460- return std::uint64_t (1000 * nodes) / std::max<std::uint64_t >(1 , ms);
460+ return static_cast < std::uint64_t > (1000 * nodes) / std::max<std::uint64_t >(1 , ms);
461461}
462462
463463// Is (x, y) on board ? Slow, but only for init
@@ -524,8 +524,8 @@ std::uint64_t Random8x64() { // 8x deterministic random for zobrist
524524
525525// Nondeterministic Rand()
526526int Random (const int min, const int max) {
527- if (min == max) return 0 ;
528- static std::uint64_t seed = 0x202c7ULL + std::uint64_t (std::time (nullptr ));
527+ if (min == max) return min ;
528+ static std::uint64_t seed = 0x202c7ULL + static_cast < std::uint64_t > (std::time (nullptr ));
529529 seed = (seed << 5 ) ^ (seed + 1 ) ^ (seed >> 3 );
530530 return min + static_cast <int >(seed % static_cast <std::uint64_t >(std::max (1 , std::abs (max - min) + 1 )));
531531}
@@ -606,7 +606,7 @@ void SetNNUE(const std::string &eval_file) { // nn.nnue
606606
607607void SetHashtable (int hash_mb) {
608608 hash_mb = std::clamp (hash_mb, 1 , 1048576 ); // Limits 1MB -> 1TB
609- g_hash_entries = std::uint32_t ((1 << 20 ) * hash_mb) / (sizeof (HashEntry)); // Hash(B) / Block(B)
609+ g_hash_entries = static_cast < std::uint32_t > ((1 << 20 ) * hash_mb) / (sizeof (HashEntry)); // Hash(B) / Block(B)
610610 g_hash.reset (new HashEntry[g_hash_entries]); // Claim space
611611}
612612
@@ -627,19 +627,19 @@ inline std::uint64_t Hash(const bool wtm) {
627627template <MoveType type>
628628void HashEntry::update (const std::uint64_t hash, const std::uint8_t index) {
629629 if constexpr (type == MoveType::kKiller ) {
630- this ->killer_hash = std::uint32_t (hash >> 32 );
630+ this ->killer_hash = static_cast < std::uint32_t > (hash >> 32 );
631631 this ->killer = index + 1 ;
632632 } else { // == MoveType::kGood !
633- this ->good_hash = std::uint32_t (hash >> 32 );
633+ this ->good_hash = static_cast < std::uint32_t > (hash >> 32 );
634634 this ->good = index + 1 ;
635635 }
636636}
637637
638638// Best moves put first for maximum cutoffs
639639void HashEntry::put_hash_value_to_moves (const std::uint64_t hash, Board *moves) const {
640- if (this ->killer && (this ->killer_hash == std::uint32_t (hash >> 32 )))
640+ if (this ->killer && (this ->killer_hash == static_cast < std::uint32_t > (hash >> 32 )))
641641 moves[this ->killer - 1 ].score += 10000 ;
642- if (this ->good && (this ->good_hash == std::uint32_t (hash >> 32 )))
642+ if (this ->good && (this ->good_hash == static_cast < std::uint32_t > (hash >> 32 )))
643643 moves[this ->good - 1 ].score += 7000 ;
644644}
645645
@@ -658,16 +658,15 @@ bool Board::is_underpromo() const { // =n / =b / =r
658658}
659659
660660const std::string Board::movename () const {
661- auto from2 = this ->from , to2 = this ->to ;
662661 switch (this ->type ) {
663- case 1 : from2 = g_king_w; to2 = g_chess960 ? g_rook_w[0 ] : 6 ; break ;
664- case 2 : from2 = g_king_w; to2 = g_chess960 ? g_rook_w[1 ] : 2 ; break ;
665- case 3 : from2 = g_king_b; to2 = g_chess960 ? g_rook_b[0 ] : 56 + 6 ; break ;
666- case 4 : from2 = g_king_b; to2 = g_chess960 ? g_rook_b[1 ] : 56 + 2 ; break ;
662+ case 1 : return Move2Str ( g_king_w, g_chess960 ? g_rook_w[0 ] : 6 ) ;
663+ case 2 : return Move2Str ( g_king_w, g_chess960 ? g_rook_w[1 ] : 2 ) ;
664+ case 3 : return Move2Str ( g_king_b, g_chess960 ? g_rook_b[0 ] : 56 + 6 ) ;
665+ case 4 : return Move2Str ( g_king_b, g_chess960 ? g_rook_b[1 ] : 56 + 2 ) ;
667666 case 5 : case 6 : case 7 : case 8 :
668- return Move2Str (from2, to2 ) + PromoLetter (this ->pieces [to2 ]);
667+ return Move2Str (this -> from , this -> to ) + PromoLetter (this ->pieces [this -> to ]);
669668 }
670- return Move2Str (from2, to2 );
669+ return Move2Str (this -> from , this -> to );
671670}
672671
673672// Board presentation in FEN ( Forsyth–Edwards Notation )
@@ -863,15 +862,18 @@ void FenKQkq(const std::string &KQkq) {
863862}
864863
865864void FenEp (const std::string &ep) {
866- if (ep.length () == 2 ) g_board->epsq = 8 * Rank2Num (ep[1 ]) + File2Num (ep[0 ]);
865+ if (ep.length () != 2 ) return ;
866+ g_board->epsq = 8 * Rank2Num (ep[1 ]) + File2Num (ep[0 ]);
867867}
868868
869869void FenRule50 (const std::string &fifty) {
870- if (fifty.length () != 0 && fifty[0 ] != ' -' ) g_board->fifty = std::clamp (std::stoi (fifty), 0 , 100 );
870+ if (fifty.length () == 0 || fifty[0 ] == ' -' ) return ;
871+ g_board->fifty = std::clamp (std::stoi (fifty), 0 , 100 );
871872}
872873
873874void FenFullMoves (const std::string &fullmoves) {
874- if (fullmoves.length () != 0 ) g_fullmoves = std::max (std::stoi (fullmoves), 1 );
875+ if (fullmoves.length () == 0 ) return ;
876+ g_fullmoves = std::max (std::stoi (fullmoves), 1 );
875877}
876878
877879// Fully legal FEN expected
@@ -971,9 +973,9 @@ inline void LazySort(const int ply, const int nth, const int total_moves) {
971973void EvalRootMoves () {
972974 for (auto i = 0 ; i < g_root_n; ++i) {
973975 g_board = g_boards[0 ] + i; // Pointer to this board
974- g_board->score += (g_board->is_queen_promo () ? 1000 : 0 ) + // =q
975- (g_board->is_castling () ? 100 : 0 ) + // ( OO, OOO )
976- (g_board->is_underpromo () ? -5000 : 0 ) + // ( =r, =b, =n )
976+ g_board->score += (g_board->is_queen_promo () ? 1000 : 0 ) +
977+ (g_board->is_castling () ? 100 : 0 ) +
978+ (g_board->is_underpromo () ? -5000 : 0 ) +
977979 (Random (-g_noise, +g_noise)) + // Add noise -> Make unpredictable
978980 (g_wtm ? +1 : -1 ) * Evaluate (g_wtm); // Full eval
979981 }
@@ -1049,7 +1051,8 @@ void AddCastleOOW() {
10491051 g_board->white [3 ] = (g_board->white [3 ] ^ Bit (g_rook_w[0 ])) | Bit (5 );
10501052 g_board->white [5 ] = (g_board->white [5 ] ^ Bit (g_king_w)) | Bit (6 );
10511053
1052- if (!ChecksB ()) g_board->index = g_moves_n++;
1054+ if (ChecksB ()) return ;
1055+ g_board->index = g_moves_n++;
10531056}
10541057
10551058void AddCastleOOB () {
@@ -1063,7 +1066,8 @@ void AddCastleOOB() {
10631066 g_board->black [3 ] = (g_board->black [3 ] ^ Bit (g_rook_b[0 ])) | Bit (56 + 5 );
10641067 g_board->black [5 ] = (g_board->black [5 ] ^ Bit (g_king_b)) | Bit (56 + 6 );
10651068
1066- if (!ChecksW ()) g_board->index = g_moves_n++;
1069+ if (ChecksW ()) return ;
1070+ g_board->index = g_moves_n++;
10671071}
10681072
10691073void AddCastleOOOW () {
@@ -1077,7 +1081,8 @@ void AddCastleOOOW() {
10771081 g_board->white [3 ] = (g_board->white [3 ] ^ Bit (g_rook_w[1 ])) | Bit (3 );
10781082 g_board->white [5 ] = (g_board->white [5 ] ^ Bit (g_king_w)) | Bit (2 );
10791083
1080- if (!ChecksB ()) g_board->index = g_moves_n++;
1084+ if (ChecksB ()) return ;
1085+ g_board->index = g_moves_n++;
10811086}
10821087
10831088void AddCastleOOOB () {
@@ -1091,7 +1096,8 @@ void AddCastleOOOB() {
10911096 g_board->black [3 ] = (g_board->black [3 ] ^ Bit (g_rook_b[1 ])) | Bit (56 + 3 );
10921097 g_board->black [5 ] = (g_board->black [5 ] ^ Bit (g_king_b)) | Bit (56 + 2 );
10931098
1094- if (!ChecksW ()) g_board->index = g_moves_n++;
1099+ if (ChecksW ()) return ;
1100+ g_board->index = g_moves_n++;
10951101}
10961102
10971103void AddOOW () {
@@ -1900,7 +1906,7 @@ int SearchMovesW(int alpha, const int beta, int depth, const int ply) {
19001906 if (moves_n == 1 || (depth == 1 && (checks || g_board->type == 8 ))) ++depth; // Extend interesting path (SRE / CE / PPE)
19011907
19021908 const auto ok_lmr = moves_n >= 5 && depth >= 2 && !checks;
1903- auto *entry = &g_hash[std::uint32_t (hash % g_hash_entries)];
1909+ auto *entry = &g_hash[static_cast < std::uint32_t > (hash % g_hash_entries)];
19041910 entry->put_hash_value_to_moves (hash, g_boards[ply]);
19051911
19061912 // Tiny speedup since not all moves are scored (lots of pointless shuffling ...)
@@ -1937,7 +1943,7 @@ int SearchMovesB(const int alpha, int beta, int depth, const int ply) {
19371943 if (moves_n == 1 || (depth == 1 && (checks || g_board->type == 8 ))) ++depth;
19381944
19391945 const auto ok_lmr = moves_n >= 5 && depth >= 2 && !checks;
1940- auto *entry = &g_hash[std::uint32_t (hash % g_hash_entries)];
1946+ auto *entry = &g_hash[static_cast < std::uint32_t > (hash % g_hash_entries)];
19411947 entry->put_hash_value_to_moves (hash, g_boards[ply]);
19421948
19431949 auto sort = true ;
@@ -2227,7 +2233,7 @@ void ThinkReset() { // Reset search status
22272233}
22282234
22292235void Think (const int ms) {
2230- g_stop_search_time = Now () + std::uint64_t (ms); // Start clock early
2236+ g_stop_search_time = Now () + static_cast < std::uint64_t > (ms); // Start clock early
22312237 ThinkReset ();
22322238 MgenRoot ();
22332239 if (!g_analyzing && FastMove (ms)) return ;
@@ -2422,8 +2428,8 @@ void UciPerft(const std::string &depth2, const std::string &fen) {
24222428// > bench
24232429// Result: 60 / 60
24242430// Nodes: 241185678
2425- // Time(ms): 17132
2426- // NPS: 14078080
2431+ // Time(ms): 16977
2432+ // NPS: 14206613
24272433// > bench inf 10000
24282434// Result: 60 / 60
24292435// Nodes: 7030957202
0 commit comments