From eb0f59c06ebb9741897e77f832c6a9628290b1f1 Mon Sep 17 00:00:00 2001 From: disservin Date: Wed, 19 Jul 2023 18:05:58 +0200 Subject: [PATCH] readme: thank people Bench: 3873201 --- README.md | 31 ++++++++++++++ src/see.h | 119 +++++++++++++++++++++++++++--------------------------- 2 files changed, 91 insertions(+), 59 deletions(-) diff --git a/README.md b/README.md index 598a3934..e87386a5 100644 --- a/README.md +++ b/README.md @@ -190,3 +190,34 @@ If you want maximum performance you should compile Smallbrain yourself. .\smallbrain.exe -generate threads=30 depth=9 tb=H:/Chess/345 .\smallbrain.exe -generate threads=30 nodes=5000 tb=H:/Chess/345 ``` + +## Acknowledgements + +I'd also like to thank the following people for their help and support: + +- A big thanks to Luecx for his amazing CudAd trainer and his help with the NNUE implementation. +- Andrew Grant for the OpenBench platform https://github.com/AndyGrant/OpenBench +- Morgan Houppin, author of Stash https://github.com/mhouppin/stash-bot for his debug sessions. +- Various other people from Stockfish discord for their help. +- [Chess.com](https://www.chess.com/computer-chess-championship) for their Smallbrain inclusion in the Computer Chess Championship (CCC) +- [TCEC](https://tcec-chess.com/) for their Smallbrain invitation. + +### Engines + +The following engines have tought me a lot about chess programming and I'd like to thank their authors for their work: + +- [Stockfish](https://github.com/official-stockfish/Stockfish) +- [Koivisto](https://github.com/Luecx/Koivisto) +- [Weiss](https://github.com/TerjeKir/weiss) + +### Tools + +Included: +The following parts of the code are from other projects, I'd like to thank their authors for their work and their respective licenses remain the same: + +- [Fathom](https://github.com/jdart1/Fathom) [MIT](https://github.com/jdart1/Fathom/blob/master/LICENSE) +- [Incbin](https://github.com/graphitemaster/incbin) [UNLICENSE](https://github.com/graphitemaster/incbin/blob/main/UNLICENSE) + +External: + +- [OpenBench](https://github.com/AndyGrant/OpenBench) [GPL-3.0](https://github.com/AndyGrant/OpenBench/blob/master/LICENSE) diff --git a/src/see.h b/src/see.h index 8549eea5..ce346d32 100644 --- a/src/see.h +++ b/src/see.h @@ -4,79 +4,80 @@ namespace see { - [[nodiscard]] inline Bitboard attackersForSide(const Board &board, Color attacker_color, Square sq, - Bitboard occupied_bb) { - const Bitboard attacking_bishops = board.pieces(BISHOP, attacker_color); - const Bitboard attacking_rooks = board.pieces(ROOK, attacker_color); - const Bitboard attacking_queens = board.pieces(QUEEN, attacker_color); - const Bitboard attacking_knights = board.pieces(KNIGHT, attacker_color); - const Bitboard attacking_king = board.pieces(KING, attacker_color); - const Bitboard attacking_pawns = board.pieces(PAWN, attacker_color); +[[nodiscard]] inline Bitboard attackersForSide(const Board &board, Color attacker_color, Square sq, + Bitboard occupied_bb) { + const Bitboard attacking_bishops = board.pieces(BISHOP, attacker_color); + const Bitboard attacking_rooks = board.pieces(ROOK, attacker_color); + const Bitboard attacking_queens = board.pieces(QUEEN, attacker_color); + const Bitboard attacking_knights = board.pieces(KNIGHT, attacker_color); + const Bitboard attacking_king = board.pieces(KING, attacker_color); + const Bitboard attacking_pawns = board.pieces(PAWN, attacker_color); - const Bitboard inter_cardinal_rays = attacks::bishop(sq, occupied_bb); - const Bitboard cardinal_rays_rays = attacks::rook(sq, occupied_bb); + const Bitboard inter_cardinal_rays = attacks::bishop(sq, occupied_bb); + const Bitboard cardinal_rays_rays = attacks::rook(sq, occupied_bb); - Bitboard attackers = inter_cardinal_rays & (attacking_bishops | attacking_queens); - attackers |= cardinal_rays_rays & (attacking_rooks | attacking_queens); - attackers |= attacks::knight(sq) & attacking_knights; - attackers |= attacks::king(sq) & attacking_king; - attackers |= attacks::pawn(sq, ~attacker_color) & attacking_pawns; - return attackers; - } + Bitboard attackers = inter_cardinal_rays & (attacking_bishops | attacking_queens); + attackers |= cardinal_rays_rays & (attacking_rooks | attacking_queens); + attackers |= attacks::knight(sq) & attacking_knights; + attackers |= attacks::king(sq) & attacking_king; + attackers |= attacks::pawn(sq, ~attacker_color) & attacking_pawns; + return attackers; +} - [[nodiscard]] inline Bitboard allAttackers(const Board &board, Square sq, Bitboard occupied_bb) { - return attackersForSide(board, WHITE, sq, occupied_bb) | - attackersForSide(board, BLACK, sq, occupied_bb); - } +[[nodiscard]] inline Bitboard allAttackers(const Board &board, Square sq, Bitboard occupied_bb) { + return attackersForSide(board, WHITE, sq, occupied_bb) | + attackersForSide(board, BLACK, sq, occupied_bb); +} /******************** - * Static Exchange Evaluation, logical based on Weiss (https://github.com/TerjeKir/weiss) - *licensed under GPL-3.0 + * Static Exchange Evaluation, logical based on Weiss + * (https://github.com/TerjeKir/weiss/blob/6772250059e82310c913a0d77a4c94b05d1e18e6/src/board.c#L310) + * licensed under GPL-3.0 *******************/ - [[nodiscard]] inline bool see(const Board &board, Move move, int threshold) { - Square from_sq = from(move); - Square to_sq = to(move); - auto attacker = board.at(from_sq); - auto victim = board.at(to_sq); - int swap = PIECE_VALUES_CLASSICAL[victim] - threshold; - if (swap < 0) return false; - swap -= PIECE_VALUES_CLASSICAL[attacker]; - if (swap >= 0) return true; - Bitboard occ = (board.all() ^ (1ULL << from_sq)) | (1ULL << to_sq); - Bitboard attackers = allAttackers(board, to_sq, occ) & occ; +[[nodiscard]] inline bool see(const Board &board, Move move, int threshold) { + Square from_sq = from(move); + Square to_sq = to(move); + auto attacker = board.at(from_sq); + auto victim = board.at(to_sq); + int swap = PIECE_VALUES_CLASSICAL[victim] - threshold; + if (swap < 0) return false; + swap -= PIECE_VALUES_CLASSICAL[attacker]; + if (swap >= 0) return true; + Bitboard occ = (board.all() ^ (1ULL << from_sq)) | (1ULL << to_sq); + Bitboard attackers = allAttackers(board, to_sq, occ) & occ; - Bitboard queens = board.pieces(WHITEQUEEN) | board.pieces(BLACKQUEEN); + Bitboard queens = board.pieces(WHITEQUEEN) | board.pieces(BLACKQUEEN); - Bitboard bishops = board.pieces(WHITEBISHOP) | board.pieces(BLACKBISHOP) | queens; - Bitboard rooks = board.pieces(WHITEROOK) | board.pieces(BLACKROOK) | queens; + Bitboard bishops = board.pieces(WHITEBISHOP) | board.pieces(BLACKBISHOP) | queens; + Bitboard rooks = board.pieces(WHITEROOK) | board.pieces(BLACKROOK) | queens; - Color sT = ~board.colorOf(from_sq); + Color sT = ~board.colorOf(from_sq); - while (true) { - attackers &= occ; - Bitboard my_attackers = attackers & board.us(sT); - if (!my_attackers) break; + while (true) { + attackers &= occ; + Bitboard my_attackers = attackers & board.us(sT); + if (!my_attackers) break; - int pt; - for (pt = 0; pt <= 5; pt++) { - if (my_attackers & - (board.pieces(static_cast(pt)) | board.pieces(static_cast(pt + 6)))) - break; - } - sT = ~sT; - if ((swap = -swap - 1 - PIECE_VALUES_TUNED[0][pt]) >= 0) { - if (pt == KING && (attackers & board.us(sT))) sT = ~sT; + int pt; + for (pt = 0; pt <= 5; pt++) { + if (my_attackers & + (board.pieces(static_cast(pt)) | board.pieces(static_cast(pt + 6)))) break; - } + } + sT = ~sT; + if ((swap = -swap - 1 - PIECE_VALUES_TUNED[0][pt]) >= 0) { + if (pt == KING && (attackers & board.us(sT))) sT = ~sT; + break; + } - occ ^= (1ULL << (builtin::lsb(my_attackers & (board.pieces(static_cast(pt)) | - board.pieces(static_cast(pt + 6)))))); + occ ^= (1ULL << (builtin::lsb(my_attackers & (board.pieces(static_cast(pt)) | + board.pieces(static_cast(pt + 6)))))); - if (pt == PAWN || pt == BISHOP || pt == QUEEN) - attackers |= attacks::bishop(to_sq, occ) & bishops; - if (pt == ROOK || pt == QUEEN) attackers |= attacks::rook(to_sq, occ) & rooks; - } - return sT != board.colorOf(from_sq); + if (pt == PAWN || pt == BISHOP || pt == QUEEN) + attackers |= attacks::bishop(to_sq, occ) & bishops; + if (pt == ROOK || pt == QUEEN) attackers |= attacks::rook(to_sq, occ) & rooks; } + return sT != board.colorOf(from_sq); +} } // namespace see \ No newline at end of file