Skip to content

Commit

Permalink
Bench: 2942225
Browse files Browse the repository at this point in the history
  • Loading branch information
jhonnold committed Mar 3, 2024
1 parent 043a7ca commit c2921df
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 27 deletions.
44 changes: 30 additions & 14 deletions src/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,35 +276,51 @@ inline void SetThreats(Board* board) {

BitBoard pawnAttacks = stm == WHITE ? ShiftNW(PieceBB(PAWN, WHITE)) | ShiftNE(PieceBB(PAWN, WHITE)) :
ShiftSW(PieceBB(PAWN, BLACK)) | ShiftSE(PieceBB(PAWN, BLACK));
board->doubleThreatened = stm == WHITE ? ShiftNW(PieceBB(PAWN, WHITE)) & ShiftNE(PieceBB(PAWN, WHITE)) :
ShiftSW(PieceBB(PAWN, BLACK)) & ShiftSE(PieceBB(PAWN, BLACK));
board->threatenedBy[PAWN] = pawnAttacks;
board->threatened = board->threatenedBy[PAWN];

board->threatenedBy[KNIGHT] = 0;
BitBoard knights = PieceBB(KNIGHT, stm);
while (knights)
board->threatenedBy[KNIGHT] |= GetKnightAttacks(PopLSB(&knights));
board->threatened |= board->threatenedBy[KNIGHT];
while (knights) {
const BitBoard knightAttacks = GetKnightAttacks(PopLSB(&knights));
board->doubleThreatened |= (knightAttacks & board->threatened);
board->threatened |= knightAttacks;
board->threatenedBy[KNIGHT] |= knightAttacks;
}

board->threatenedBy[BISHOP] = 0;
BitBoard bishops = PieceBB(BISHOP, stm);
while (bishops)
board->threatenedBy[BISHOP] |= GetBishopAttacks(PopLSB(&bishops), occ);
board->threatened |= board->threatenedBy[BISHOP];
while (bishops) {
const BitBoard bishopAttacks = GetBishopAttacks(PopLSB(&bishops), occ);
board->doubleThreatened |= (bishopAttacks & board->threatened);
board->threatened |= bishopAttacks;
board->threatenedBy[BISHOP] |= bishopAttacks;
}

board->threatenedBy[ROOK] = 0;
BitBoard rooks = PieceBB(ROOK, stm);
while (rooks)
board->threatenedBy[ROOK] |= GetRookAttacks(PopLSB(&rooks), occ);
board->threatened |= board->threatenedBy[ROOK];
while (rooks) {
const BitBoard rookAttacks = GetRookAttacks(PopLSB(&rooks), occ);
board->doubleThreatened |= (rookAttacks & board->threatened);
board->threatened |= rookAttacks;
board->threatenedBy[ROOK] |= rookAttacks;
}

board->threatenedBy[QUEEN] = 0;
BitBoard queens = PieceBB(QUEEN, stm);
while (queens)
board->threatenedBy[QUEEN] |= GetQueenAttacks(PopLSB(&queens), occ);
board->threatened |= board->threatenedBy[QUEEN];
while (queens) {
const BitBoard queenAttacks = GetQueenAttacks(PopLSB(&queens), occ);
board->doubleThreatened |= (queenAttacks & board->threatened);
board->threatened |= queenAttacks;
board->threatenedBy[QUEEN] |= queenAttacks;
}

board->threatenedBy[KING] = GetKingAttacks(LSB(PieceBB(KING, stm)));
board->threatened |= board->threatenedBy[KING];
const BitBoard kingAttacks = GetKingAttacks(LSB(PieceBB(KING, stm)));
board->doubleThreatened |= (kingAttacks & board->threatened);
board->threatened |= kingAttacks;
board->threatenedBy[KING] = kingAttacks;
}

void MakeMove(Move move, Board* board) {
Expand Down
4 changes: 2 additions & 2 deletions src/history.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void UpdateHistories(SearchStack* ss,
// wasn't trivial. This idea was first thought of
// by Alayan in Ethereal
if (nQ > 1 || depth > 3) {
AddHistoryHeuristic(&HH(stm, bestMove, board->threatened), inc);
AddHistoryHeuristic(&HH(stm, bestMove, board->threatened, board->doubleThreatened), inc);
UpdateCH(ss, bestMove, inc);
}
} else {
Expand All @@ -67,7 +67,7 @@ void UpdateHistories(SearchStack* ss,
if (m == bestMove)
continue;

AddHistoryHeuristic(&HH(stm, m, board->threatened), -inc);
AddHistoryHeuristic(&HH(stm, m, board->threatened, board->doubleThreatened), -inc);
UpdateCH(ss, m, -inc);
}
}
Expand Down
11 changes: 6 additions & 5 deletions src/history.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@
#include "types.h"
#include "util.h"

#define HH(stm, m, threats) (thread->hh[stm][!GetBit(threats, From(m))][!GetBit(threats, To(m))][FromTo(m)])
#define TH(p, e, d, c) (thread->caph[p][e][d][c])
#define HH(stm, m, t1, t2) \
(thread->hh[stm][!!GetBit(t1, From(m)) + !!GetBit(t2, From(m))][!!GetBit(t1, To(m)) + !!GetBit(t2, To(m))][FromTo(m)])
#define TH(p, e, d, c) (thread->caph[p][e][d][c])

INLINE int GetQuietHistory(SearchStack* ss, ThreadData* thread, Move move) {
return (int) HH(thread->board.stm, move, thread->board.threatened) + //
(int) (*(ss - 1)->ch)[Moving(move)][To(move)] + //
(int) (*(ss - 2)->ch)[Moving(move)][To(move)] + //
return (int) HH(thread->board.stm, move, thread->board.threatened, thread->board.doubleThreatened) + //
(int) (*(ss - 1)->ch)[Moving(move)][To(move)] + //
(int) (*(ss - 2)->ch)[Moving(move)][To(move)] + //
(int) (*(ss - 4)->ch)[Moving(move)][To(move)];
}

Expand Down
8 changes: 4 additions & 4 deletions src/movepick.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ INLINE void ScoreMoves(MovePicker* picker, Board* board, const int type) {
const int captured = IsEP(move) ? PAWN : PieceType(board->squares[to]);

if (type == ST_QUIET || type == ST_EVASION_QT) {
current->score = (int) HH(board->stm, move, board->threatened) * 2 + //
(int) (*(ss - 1)->ch)[pc][to] * 2 + //
(int) (*(ss - 2)->ch)[pc][to] * 2 + //
(int) (*(ss - 4)->ch)[pc][to] + //
current->score = (int) HH(board->stm, move, board->threatened, board->doubleThreatened) * 2 + //
(int) (*(ss - 1)->ch)[pc][to] * 2 + //
(int) (*(ss - 2)->ch)[pc][to] * 2 + //
(int) (*(ss - 4)->ch)[pc][to] + //
(int) (*(ss - 6)->ch)[pc][to];

if (pt != PAWN && pt != KING) {
Expand Down
6 changes: 4 additions & 2 deletions src/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ typedef struct {
BitBoard checkers;
BitBoard pinned;
BitBoard threatened;
BitBoard doubleThreatened;
BitBoard threatenedBy[6];
int capture;
} BoardHistory;
Expand All @@ -93,7 +94,8 @@ typedef struct {
BitBoard checkers; // checking piece squares
BitBoard pinned; // pinned pieces

BitBoard threatened; // opponent "threatening" these squares
BitBoard threatened; // opponent "threatening" these squares
BitBoard doubleThreatened;
BitBoard threatenedBy[6];

int stm; // side to move
Expand Down Expand Up @@ -193,7 +195,7 @@ struct ThreadData {
RootMove rootMoves[MAX_MOVES];

Move counters[12][64]; // counter move butterfly table
int16_t hh[2][2][2][64 * 64]; // history heuristic butterfly table (stm / threatened)
int16_t hh[2][3][3][64 * 64]; // history heuristic butterfly table (stm / threatened)
int16_t ch[2][12][64][12][64]; // continuation move history table
int16_t caph[12][64][2][7]; // capture history (piece - to - defeneded - captured_type)

Expand Down

0 comments on commit c2921df

Please sign in to comment.