Skip to content

Commit

Permalink
Don't calculate X-ray attackers if not neccessary. Can this be faster?
Browse files Browse the repository at this point in the history
Fixed logic.
bench: 1241996
  • Loading branch information
pb00068 committed Oct 24, 2023
1 parent 13fd696 commit 02a5e3d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/position.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,7 @@ bool Position::see_ge(Move m, Value threshold) const {
sliders[-2 + sliderOnTo]--;
occupied ^= least_significant_square_bb(bb);
sliderOnTo = BISHOP;
if (sliders[1] + sliders[3] > 0)
if (sliders[1] + sliders[3] - 1 - more_than_one(bb) > 0)
attackers |= attacks_bb<BISHOP>(to, occupied) & pieces(BISHOP, QUEEN);
}

Expand All @@ -1152,7 +1152,7 @@ bool Position::see_ge(Move m, Value threshold) const {
sliderOnTo = ROOK;
occupied ^= least_significant_square_bb(bb);

if (sliders[2] + sliders[3] > 0)
if (sliders[2] + sliders[3] - 1 - more_than_one(bb) > 0)
attackers |= attacks_bb<ROOK>(to, occupied) & pieces(ROOK, QUEEN);
}

Expand All @@ -1165,9 +1165,9 @@ bool Position::see_ge(Move m, Value threshold) const {
sliderOnTo = QUEEN;
occupied ^= least_significant_square_bb(bb);

if (sliders[1] + sliders[3] > 0)
if (sliders[1] + sliders[3] - 1 - more_than_one(bb) > 0)
attackers |= (attacks_bb<BISHOP>(to, occupied) & pieces(BISHOP, QUEEN));
if (sliders[2] + sliders[3] > 0)
if (sliders[2] + sliders[3] - 1 - more_than_one(bb) > 0)
attackers |= (attacks_bb<ROOK>(to, occupied) & pieces(ROOK, QUEEN));
}

Expand Down

1 comment on commit 02a5e3d

@pb00067
Copy link

@pb00067 pb00067 commented on 02a5e3d Oct 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hit# 1: Total 71816 Hits 4761 Hit Rate (%) 6.62944      sliders[BISHOP] + sliders[QUEEN]  <= 0 after PAWN recapture
Hit# 2: Total 74060 Hits 5718 Hit Rate (%) 7.72077      sliders[BISHOP] + sliders[QUEEN] - 1 - more_than_one(bb)  <= 0  after BISHOP recapture
Hit# 3: Total 111965 Hits 17374 Hit Rate (%) 15.5173  sliders[ROOK] + sliders[QUEEN] - 1 - more_than_one(bb)  <= 0  after ROOK recapture
Hit# 4: Total 150292 Hits 14468 Hit Rate (%) 9.62659   sliders[BISHOP] + sliders[QUEEN] - 1 - more_than_one(bb)  <= 0  after QUEEN recapture
Hit# 5: Total 150292 Hits 14238 Hit Rate (%) 9.47356   sliders[ROOK] + sliders[QUEEN] - 1 - more_than_one(bb)  <= 0  after QUEEN recapture

Total around ~10% of x-ray attack calculations can be avoided witout having a functional change.

Please sign in to comment.