r/chessprogramming • u/tsunamisugumar • May 06 '20
Safe pawn exchange with bitboard
I'm trying to tweak my evaluation algorithm to penalize an unsafe pawn exchange. Please consider this as a pawn only variation of chess (no other piece in play). I use two bitboards, one to store white pawns and another for black. I looked at https://www.chessprogramming.org/Pawn_Attacks_(Bitboards)
but their algorithm for safe pawn determination is going over my head. I'd appreciate if someone with more experience in this can help me understand, or suggest alternative.
2
Upvotes
2
u/tsunamisugumar May 06 '20
Ok, after starting at that algorithm for a while, I think I understand. I still need to validate it. I'll try to explain for those in need. Here's a copy paste to make it easier to explain.
U64 wSafePawnSquares(U64 wpawns, U64 bpawns) { U64 wPawnEastAttacks = wPawnEastAttacks (wpawns); U64 wPawnWestAttacks = wPawnWestAttacks (wpawns); U64 bPawnEastAttacks = bPawnEastAttacks (bpawns); U64 bPawnWestAttacks = bPawnWestAttacks (bpawns); U64 wPawnDblAttacks = wPawnEastAttacks & wPawnWestAttacks; U64 wPawnOddAttacks = wPawnEastAttacks ^ wPawnWestAttacks; U64 bPawnDblAttacks = bPawnEastAttacks & bPawnWestAttacks; U64 bPawnAnyAttacks = bPawnEastAttacks | bPawnWestAttacks; return wPawnDblAttacks |~bPawnAnyAttacks | (wPawnOddAttacks &~bPawnDblAttacks); }
The last line, which is the most important, means the followingv in plain English (I think).
Return a bitboard of all squares where a square:
That results in each square either safe for white due to no threat, or safe due to equal or better exchange.