- // Orient a square according to perspective (rotates by 180 for black)
- inline Square HalfKAv2_hm::orient(Color perspective, Square s, Square ksq) {
- return Square(int(s) ^ (bool(perspective) * SQ_A8) ^ ((file_of(ksq) < FILE_E) * SQ_H1));
- }
-
- // Index of a feature for a given king position and another piece on some square
- inline IndexType HalfKAv2_hm::make_index(Color perspective, Square s, Piece pc, Square ksq) {
- Square o_ksq = orient(perspective, ksq, ksq);
- return IndexType(orient(perspective, s, ksq) + PieceSquareIndex[perspective][pc] + PS_NB * KingBuckets[o_ksq]);
- }
-
- // Get a list of indices for active features
- void HalfKAv2_hm::append_active_indices(
- const Position& pos,
- Color perspective,
- ValueListInserter<IndexType> active
- ) {
- Square ksq = pos.square<KING>(perspective);
- Bitboard bb = pos.pieces();
+// Index of a feature for a given king position and another piece on some square
+template<Color Perspective>
+inline IndexType HalfKAv2_hm::make_index(Square s, Piece pc, Square ksq) {
+ return IndexType((int(s) ^ OrientTBL[Perspective][ksq]) + PieceSquareIndex[Perspective][pc]
+ + KingBuckets[Perspective][ksq]);
+}
+
+// Get a list of indices for active features
+template<Color Perspective>
+void HalfKAv2_hm::append_active_indices(const Position& pos, IndexList& active) {
+ Square ksq = pos.square<KING>(Perspective);
+ Bitboard bb = pos.pieces();