No functional change.
uint8_t PopCnt16[1 << 16];
uint8_t SquareDistance[SQUARE_NB][SQUARE_NB];
+ Bitboard SquareBB[SQUARE_NB];
Bitboard LineBB[SQUARE_NB][SQUARE_NB];
-Bitboard PseudoAttacks[PIECE_TYPE_NB][SQUARE_NB];
-Bitboard PawnAttacks[COLOR_NB][SQUARE_NB];
+Bitboard PseudoAttacks[COLOR_NB][PIECE_TYPE_NB][SQUARE_NB];
+Bitboard PseudoMoves[COLOR_NB][PIECE_TYPE_NB][SQUARE_NB];
+Bitboard LeaperAttacks[COLOR_NB][PIECE_TYPE_NB][SQUARE_NB];
+Bitboard LeaperMoves[COLOR_NB][PIECE_TYPE_NB][SQUARE_NB];
- Bitboard SquareBB[SQUARE_NB];
+Bitboard BoardSizeBB[FILE_NB][RANK_NB];
- Bitboard KingFlank[FILE_NB] = {
- QueenSide ^ FileDBB, QueenSide, QueenSide,
- CenterFiles, CenterFiles,
- KingSide, KingSide, KingSide ^ FileEBB
- };
-
Magic RookMagics[SQUARE_NB];
Magic BishopMagics[SQUARE_NB];
extern uint8_t PopCnt16[1 << 16];
extern uint8_t SquareDistance[SQUARE_NB][SQUARE_NB];
+ extern Bitboard SquareBB[SQUARE_NB];
extern Bitboard LineBB[SQUARE_NB][SQUARE_NB];
-extern Bitboard PseudoAttacks[PIECE_TYPE_NB][SQUARE_NB];
-extern Bitboard PawnAttacks[COLOR_NB][SQUARE_NB];
+extern Bitboard PseudoAttacks[COLOR_NB][PIECE_TYPE_NB][SQUARE_NB];
+extern Bitboard PseudoMoves[COLOR_NB][PIECE_TYPE_NB][SQUARE_NB];
+extern Bitboard LeaperAttacks[COLOR_NB][PIECE_TYPE_NB][SQUARE_NB];
+extern Bitboard LeaperMoves[COLOR_NB][PIECE_TYPE_NB][SQUARE_NB];
- extern Bitboard KingFlank[FILE_NB];
+extern Bitboard SquareBB[SQUARE_NB];
+extern Bitboard BoardSizeBB[FILE_NB][RANK_NB];
+#ifdef LARGEBOARDS
+int popcount(Bitboard b); // required for 128 bit pext
+#endif
/// Magic holds all magic bitboards relevant data for a single square
struct Magic {
template<Direction D>
constexpr Bitboard shift(Bitboard b) {
- return D == NORTH ? b << 8 : D == SOUTH ? b >> 8
- : D == NORTH+NORTH? b <<16 : D == SOUTH+SOUTH? b >>16
- : D == EAST ? (b & ~FileHBB) << 1 : D == WEST ? (b & ~FileABB) >> 1
- : D == NORTH_EAST ? (b & ~FileHBB) << 9 : D == NORTH_WEST ? (b & ~FileABB) << 7
- : D == SOUTH_EAST ? (b & ~FileHBB) >> 7 : D == SOUTH_WEST ? (b & ~FileABB) >> 9
- : 0;
+ return D == NORTH ? b << NORTH : D == SOUTH ? b >> NORTH
++ : D == NORTH+NORTH? b <<(2 * NORTH) : D == SOUTH+SOUTH? b >> (2 * NORTH)
+ : D == EAST ? (b & ~file_bb(FILE_MAX)) << EAST : D == WEST ? (b & ~FileABB) >> EAST
+ : D == NORTH_EAST ? (b & ~file_bb(FILE_MAX)) << NORTH_EAST : D == NORTH_WEST ? (b & ~FileABB) << NORTH_WEST
+ : D == SOUTH_EAST ? (b & ~file_bb(FILE_MAX)) >> NORTH_WEST : D == SOUTH_WEST ? (b & ~FileABB) >> NORTH_EAST
+ : Bitboard(0);
+}
+
+
+/// shift() moves a bitboard one step along direction D (mainly for pawns)
+
+constexpr Bitboard shift(Direction D, Bitboard b) {
+ return D == NORTH ? b << NORTH : D == SOUTH ? b >> NORTH
++ : D == NORTH+NORTH? b <<(2 * NORTH) : D == SOUTH+SOUTH? b >> (2 * NORTH)
+ : D == EAST ? (b & ~file_bb(FILE_MAX)) << EAST : D == WEST ? (b & ~FileABB) >> EAST
+ : D == NORTH_EAST ? (b & ~file_bb(FILE_MAX)) << NORTH_EAST : D == NORTH_WEST ? (b & ~FileABB) << NORTH_WEST
+ : D == SOUTH_EAST ? (b & ~file_bb(FILE_MAX)) >> NORTH_WEST : D == SOUTH_WEST ? (b & ~FileABB) >> NORTH_EAST
+ : Bitboard(0);
}
if (Pt == ROOK)
{
// Bonus for aligning rook with enemy pawns on the same rank/file
- if (relative_rank(Us, s) >= RANK_5)
- score += RookOnPawn * popcount(pos.pieces(Them, PAWN) & PseudoAttacks[ROOK][s]);
+ if (relative_rank(Us, s, pos.max_rank()) >= RANK_5)
+ score += RookOnPawn * popcount(pos.pieces(Them, PAWN) & PseudoAttacks[Us][ROOK][s]);
// Bonus for rook on an open or semi-open file
- if (pos.semiopen_file(Us, file_of(s)))
- score += RookOnFile[bool(pos.semiopen_file(Them, file_of(s)))];
+ if (pos.is_semiopen_file(Us, file_of(s)))
+ score += RookOnFile[bool(pos.is_semiopen_file(Them, file_of(s)))];
// Penalty when trapped by the king, even more if the king cannot castle
- else if (mob <= 3)
+ else if (mob <= 3 && pos.count<KING>(Us))
{
File kf = file_of(pos.square<KING>(Us));
if ((kf < FILE_E) == (file_of(s) < kf))
// Find the available squares for our pieces inside the area defined by SpaceMask
Bitboard safe = SpaceMask
- & ~pos.pieces(Us, PAWN)
- & ~attackedBy[Them][PAWN];
+ & ~pos.pieces(Us, PAWN, SHOGI_PAWN)
+ & ~attackedBy[Them][PAWN]
+ & ~attackedBy[Them][SHOGI_PAWN];
// Find all squares which are at most three squares behind some friendly pawn
- Bitboard behind = pos.pieces(Us, PAWN);
+ Bitboard behind = pos.pieces(Us, PAWN, SHOGI_PAWN);
behind |= shift<Down>(behind);
- behind |= shift<Down>(shift<Down>(behind));
+ behind |= shift<Down+Down>(behind);
+ if (pawnsOnly)
+ {
+ safe = behind & ~attackedBy[Them][ALL_PIECES];
+ behind = 0;
+ }
+
int bonus = popcount(safe) + popcount(behind & safe);
int weight = pos.count<ALL_PIECES>(Us)
- (16 - pos.count<PAWN>()) / 4;
int sf = me->scale_factor(pos, strongSide);
// If scale is not already specific, scale down the endgame via general heuristics
- if (sf == SCALE_FACTOR_NORMAL)
+ if (sf == SCALE_FACTOR_NORMAL && !pos.captures_to_hand())
{
if ( pos.opposite_bishops()
- && pos.non_pawn_material(WHITE) == BishopValueMg
- && pos.non_pawn_material(BLACK) == BishopValueMg)
+ && pos.non_pawn_material() == 2 * BishopValueMg)
sf = 16 + 4 * pe->passed_count();
else
sf = std::min(40 + (pos.opposite_bishops() ? 2 : 7) * pos.count<PAWN>(strongSide), sf);
constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
constexpr Direction Down = (Us == WHITE ? SOUTH : NORTH);
- Bitboard BlockRanks = rank_bb(relative_rank(Us, RANK_1, pos.max_rank())) | rank_bb(relative_rank(Us, RANK_2, pos.max_rank()));
- constexpr Bitboard BlockSquares = (Rank1BB | Rank2BB | Rank7BB | Rank8BB)
- & (FileABB | FileHBB);
++ Bitboard BlockSquares = (rank_bb(relative_rank(Us, RANK_1, pos.max_rank())) | rank_bb(relative_rank(Us, RANK_2, pos.max_rank())))
++ & (FileABB | file_bb(pos.max_file()));
- 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);
- Value safety = (shift<Down>(theirPawns) & (FileABB | FileHBB) & BlockRanks & ksq) ?
- Value(374) : Value(5);
+ Value safety = (shift<Down>(theirPawns) & BlockSquares & ksq) ? Value(374) : Value(5);
- File center = clamp(file_of(ksq), FILE_B, FILE_G);
+ File center = clamp(file_of(ksq), FILE_B, File(pos.max_file() - 1));
for (File f = File(center - 1); f <= File(center + 1); ++f)
{
b = ourPawns & file_bb(f);
castlingRightsMask[rfrom] |= cr;
castlingRookSquare[cr] = rfrom;
- Square kto = relative_square(c, cs == KING_SIDE ? SQ_G1 : SQ_C1);
- Square rto = relative_square(c, cs == KING_SIDE ? SQ_F1 : SQ_D1);
+ Square kto = make_square(cs == KING_SIDE ? castling_kingside_file() : castling_queenside_file(),
+ relative_rank(c, RANK_1, max_rank()));
+ Square rto = kto + (cs == KING_SIDE ? WEST : EAST);
- castlingPath[cr] = (between_bb(rfrom, rto) | between_bb(kfrom, kto) | rto | kto)
- & ~(square_bb(kfrom) | rfrom);
+ castlingPath[cr] = (between_bb(rfrom, rto) | between_bb(kfrom, kto) | rto | kto)
+ & ~(square_bb(kfrom) | rfrom);
}
}
// Update pawn hash key and prefetch access to pawnsTable
- st->pawnKey ^= Zobrist::psq[pc][from] ^ Zobrist::psq[pc][to];
+ if (type_of(m) == DROP)
+ st->pawnKey ^= Zobrist::psq[pc][to];
+ else
+ st->pawnKey ^= Zobrist::psq[pc][from] ^ Zobrist::psq[pc][to];
- prefetch2(thisThread->pawnsTable[st->pawnKey]);
// Reset rule 50 draw counter
st->rule50 = 0;
template<PieceType Pt> int count(Color c) const;
template<PieceType Pt> int count() const;
template<PieceType Pt> const Square* squares(Color c) const;
+ const Square* squares(Color c, PieceType pt) const;
template<PieceType Pt> Square square(Color c) const;
- int semiopen_file(Color c, File f) const;
+ bool is_semiopen_file(Color c, File f) const;
// Castling
int castling_rights(Color c) const;
return st->epSquare;
}
- inline int Position::semiopen_file(Color c, File f) const {
+ inline bool Position::is_semiopen_file(Color c, File f) const {
- return !(pieces(c, PAWN) & file_bb(f));
+ return !(pieces(c, PAWN, SHOGI_PAWN) & file_bb(f));
}
inline bool Position::can_castle(CastlingRight cr) const {
inline bool Position::advanced_pawn_push(Move m) const {
return type_of(moved_piece(m)) == PAWN
- && relative_rank(sideToMove, from_sq(m), max_rank()) > (max_rank() + 1) / 2 - 1;
- && relative_rank(sideToMove, to_sq(m)) > RANK_5;
++ && relative_rank(sideToMove, to_sq(m), max_rank()) > (max_rank() + 1) / 2;
}
inline int Position::pawns_on_same_color_squares(Color c, Square s) const {