Skip to content

Commit fa93bc3

Browse files
committed
Simplify king square
1 parent b8ddb24 commit fa93bc3

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

src/position.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,6 @@ Position& Position::set(const string& fenStr, StateInfo* si) {
147147
else if ((idx = PieceToChar.find(token)) != string::npos)
148148
{
149149
put_piece(Piece(idx), sq);
150-
if (type_of(Piece(idx)) == KING)
151-
kingSquare[color_of(Piece(idx))] = sq;
152150
++sq;
153151
}
154152
}

src/position.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ class Position {
192192
std::array<Bitboard, PIECE_TYPE_NB> byTypeBB;
193193
std::array<Bitboard, COLOR_NB> byColorBB;
194194

195-
Square kingSquare[COLOR_NB];
196195
int pieceCount[PIECE_NB];
197196
uint64_t midEncoding[COLOR_NB];
198197
StateInfo* st;
@@ -248,7 +247,10 @@ inline int Position::count() const {
248247
return count<Pt>(WHITE) + count<Pt>(BLACK);
249248
}
250249

251-
inline Square Position::king_square(Color c) const { return kingSquare[c]; }
250+
inline Square Position::king_square(Color c) const {
251+
return c == WHITE ? lsb(uint64_t(pieces(KING)))
252+
: Square(64 + lsb(uint64_t(pieces(KING) >> 64)));
253+
}
252254

253255
inline uint64_t Position::mid_encoding(Color c) const { return midEncoding[c]; }
254256

@@ -351,8 +353,6 @@ inline void Position::move_piece(Square from, Square to, DirtyThreats* const dts
351353
byColorBB[color_of(pc)] ^= fromTo;
352354
board[from] = NO_PIECE;
353355
board[to] = pc;
354-
if (type_of(pc) == KING)
355-
kingSquare[color_of(pc)] = to;
356356
midEncoding[color_of(pc)] -= Eval::NNUE::Features::HalfKAv2_hm::MidMirrorEncoding[pc][from];
357357
midEncoding[color_of(pc)] += Eval::NNUE::Features::HalfKAv2_hm::MidMirrorEncoding[pc][to];
358358

@@ -369,8 +369,6 @@ inline void Position::swap_piece(Square s, Piece pc, DirtyThreats* const dts) {
369369
update_piece_threats<false, false>(old, s, dts);
370370

371371
put_piece(pc, s);
372-
if (type_of(pc) == KING)
373-
kingSquare[color_of(pc)] = s;
374372

375373
if (dts)
376374
update_piece_threats<true, false>(pc, s, dts);

0 commit comments

Comments
 (0)