{
Square s = pop_lsb(&b);
score += ThreatByMinor[type_of(pos.piece_on(s))];
- if (type_of(pos.piece_on(s)) != PAWN)
- score += ThreatByRank * (int)relative_rank(Them, s);
++
+ if (type_of(pos.piece_on(s)) != PAWN && type_of(pos.piece_on(s)) != SHOGI_PAWN)
+ score += ThreatByRank * (int)relative_rank(Them, s, pos.max_rank());
+
+ else if (pos.blockers_for_king(Them) & s)
- score += ThreatByRank * (int)relative_rank(Them, s) / 2;
++ score += ThreatByRank * (int)relative_rank(Them, s, pos.max_rank()) / 2;
}
- b = (pos.pieces(Them, QUEEN) | weak) & attackedBy[Us][ROOK];
+ b = weak & attackedBy[Us][ROOK];
while (b)
{
Square s = pop_lsb(&b);
score += ThreatByRook[type_of(pos.piece_on(s))];
- if (type_of(pos.piece_on(s)) != PAWN)
- score += ThreatByRank * (int)relative_rank(Them, s);
+ if (type_of(pos.piece_on(s)) != PAWN && type_of(pos.piece_on(s)) != SHOGI_PAWN)
+ score += ThreatByRank * (int)relative_rank(Them, s, pos.max_rank());
+
+ else if (pos.blockers_for_king(Them) & s)
- score += ThreatByRank * (int)relative_rank(Them, s) / 2;
++ score += ThreatByRank * (int)relative_rank(Them, s, pos.max_rank()) / 2;
}
- // Bonus for king attacks on pawns or pieces which are not pawn-defended
if (weak & attackedBy[Us][KING])
score += ThreatByKing;
/// unsuccessful during the current search, and is used for reduction and move
/// ordering decisions. It uses 2 tables (one for each color) indexed by
/// the move's from and to squares, see chessprogramming.wikispaces.com/Butterfly+Boards
- typedef Stats<int16_t, 10368, COLOR_NB, int(SQUARE_NB + 1) * int(SQUARE_NB)> ButterflyHistory;
-typedef Stats<int16_t, 10692, COLOR_NB, int(SQUARE_NB) * int(SQUARE_NB)> ButterflyHistory;
++typedef Stats<int16_t, 10692, COLOR_NB, int(SQUARE_NB + 1) * int(SQUARE_NB)> ButterflyHistory;
/// CounterMoveHistory stores counter moves indexed by [piece][to] of the previous
/// move, see chessprogramming.wikispaces.com/Countermove+Heuristic
constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
constexpr Direction Down = (Us == WHITE ? SOUTH : NORTH);
- constexpr Bitboard BlockRanks = (Us == WHITE ? Rank1BB | Rank2BB : Rank8BB | Rank7BB);
+ Bitboard BlockRanks = rank_bb(relative_rank(Us, RANK_1, pos.max_rank())) | rank_bb(relative_rank(Us, RANK_2, pos.max_rank()));
- Bitboard b = pos.pieces(PAWN, SHOGI_PAWN) & (forward_ranks_bb(Us, ksq) | rank_bb(ksq));
- Bitboard b = pos.pieces(PAWN) & ~forward_ranks_bb(Them, ksq);
++ Bitboard b = pos.pieces(PAWN, SHOGI_PAWN) & ~forward_ranks_bb(Them, ksq);
Bitboard ourPawns = b & pos.pieces(Us);
Bitboard theirPawns = b & pos.pieces(Them);