Skip to content
This repository was archived by the owner on Apr 26, 2025. It is now read-only.

Commit 475e6b5

Browse files
Add files via upload
1 parent 99a8b3c commit 475e6b5

File tree

3 files changed

+49
-40
lines changed

3 files changed

+49
-40
lines changed

Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ help:
4949
@echo ""
5050
@echo "Supported targets:"
5151
@echo ""
52-
@echo "all # Build"
53-
@echo "install # Installation"
54-
@echo "strip # Strip executable"
55-
@echo "clean # Clean up"
56-
@echo "help # This help"
52+
@echo "all # Build"
53+
@echo "install # Installation"
54+
@echo "strip # Strip executable"
55+
@echo "clean # Clean up"
56+
@echo "help # This help"
5757
@echo ""
5858
@echo "Supported flags:"
5959
@echo ""

mayhem.hpp

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ inline int Yaxl(const int sq) {
457457

458458
// Nodes Per Second
459459
std::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()
526526
int 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

607607
void 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) {
627627
template <MoveType type>
628628
void 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
639639
void 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

660660
const 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

865864
void 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

869869
void 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

873874
void 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) {
971973
void 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

10551058
void 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

10691073
void 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

10831088
void 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

10971103
void 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

22292235
void 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

polyglotbook.hpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
33
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
44
Copyright (C) 2008-2014 Marco Costalba, Joona Kiiski, Tord Romstad
5-
Copyright (C) 2020-2022 Toni Helminen (Mayhem author / Modifications)
5+
Copyright (C) 2020-2024 Toni Helminen (Mayhem author / Modifications)
66
77
Stockfish is free software: you can redistribute it and/or modify
88
it under the terms of the GNU General Public License as published by
@@ -80,8 +80,11 @@ class PolyglotBook : private std::ifstream {
8080
std::size_t find_first(const std::uint64_t);
8181
bool is_ep_legal() const;
8282
inline int ctz(const std::uint64_t bb) const { return __builtin_ctzll(bb); }
83-
inline int ctz_pop(std::uint64_t *bb) const { const auto ret = this->ctz(*bb);
84-
*bb = *bb & (*bb - 0x1ULL); return ret; }
83+
inline int ctz_pop(std::uint64_t *bb) const {
84+
const auto ret = this->ctz(*bb);
85+
*bb = *bb & (*bb - 0x1ULL);
86+
return ret;
87+
}
8588
bool on_board(const int x) const { return x >= 0 && x <= 7; }
8689
};
8790

@@ -363,7 +366,7 @@ constexpr union {
363366
// polyglotbook.cpp start
364367

365368
PolyglotBook::PolyglotBook() : polyboard{} {
366-
std::srand((unsigned int)(std::time(nullptr)));
369+
std::srand(static_cast<unsigned int>(std::time(nullptr)));
367370
}
368371

369372
PolyglotBook::~PolyglotBook() {
@@ -521,7 +524,7 @@ int PolyglotBook::probe(const bool pick_best) {
521524
std::size_t PolyglotBook::find_first(const std::uint64_t key) {
522525
this->seekg(0, std::ios::end); // Move pointer to end, so tellg() gets file's size
523526

524-
std::size_t low = 0, high = std::size_t(this->tellg()) / sizeof(Entry) - 1;
527+
std::size_t low = 0, high = static_cast<std::size_t>(this->tellg()) / sizeof(Entry) - 1;
525528
Entry e{};
526529

527530
while (low < high && this->good()) {

0 commit comments

Comments
 (0)