npm2 += pos.count_in_hand(pt) * PieceValue[MG][make_piece(WHITE, pt)];
e->gamePhase = Phase(PHASE_MIDGAME * npm / std::max(int(npm + npm2), 1));
int countAll = pos.count_with_hand(WHITE, ALL_PIECES) + pos.count_with_hand(BLACK, ALL_PIECES);
- e->materialDensity = (npm + npm2 + pos.count<PAWN>() * PawnValueMg) * countAll / ((pos.max_file() + 1) * (pos.max_rank() + 1));
+ e->materialDensity = (npm + npm2 + pos.count<PAWN>() * PawnValueMg) * countAll / (pos.files() * pos.ranks());
}
else
e->gamePhase = Phase(((npm - EndgameLimit) * PHASE_MIDGAME) / (MidgameLimit - EndgameLimit));
return t;
}
- static const std::string PieceToChar(" PNBRQK pnbrqk");
-
// Requires the buffer to have capacity for at least 5 values
static void format_cp_compact(Value v, char* buffer) {
std::stringstream ss;
- char board[3*8+1][8*8+2];
+ char board[3*RANK_NB+1][8*FILE_NB+2];
std::memset(board, ' ', sizeof(board));
- for (int row = 0; row < 3*8+1; ++row)
- board[row][8*8+1] = '\0';
+ for (int row = 0; row < 3*pos.ranks()+1; ++row)
+ board[row][pos.ranks()*pos.files()+1] = '\0';
// A lambda to output one box of the board
- auto writeSquare = [&board](File file, Rank rank, Piece pc, Value value) {
+ auto writeSquare = [&board, &pos](File file, Rank rank, Piece pc, Value value) {
const int x = ((int)file) * 8;
const int y = (7 - (int)rank) * 3;
board[y+i][x] = board[y+i][x+8] = '|';
board[y][x] = board[y][x+8] = board[y+3][x+8] = board[y+3][x] = '+';
if (pc != NO_PIECE)
- board[y+1][x+4] = PieceToChar[pc];
+ board[y+1][x+4] = pos.piece_to_char()[pc];
if (value != VALUE_NONE)
format_cp_compact(value, &board[y+2][x+2]);
};
Value base = evaluate(pos);
base = pos.side_to_move() == WHITE ? base : -base;
- for (File f = FILE_A; f <= FILE_H; ++f)
- for (Rank r = RANK_1; r <= RANK_8; ++r)
+ for (File f = FILE_A; f <= pos.max_file(); ++f)
+ for (Rank r = RANK_1; r <= pos.max_rank(); ++r)
{
Square sq = make_square(f, r);
Piece pc = pos.piece_on(sq);
+ Piece unpromotedPc = pos.unpromoted_piece_on(sq);
+ bool isPromoted = pos.is_promoted(sq);
Value v = VALUE_NONE;
if (pc != NO_PIECE && type_of(pc) != pos.nnue_king())
eval = pos.side_to_move() == WHITE ? eval : -eval;
v = base - eval;
- pos.put_piece(pc, sq);
+ pos.put_piece(pc, sq, isPromoted, unpromotedPc);
st->accumulator.computed[WHITE] = false;
st->accumulator.computed[BLACK] = false;
}
}
ss << " NNUE derived piece values:\n";
- for (int row = 0; row < 3*8+1; ++row)
+ for (int row = 0; row < 3*pos.ranks()+1; ++row)
ss << board[row] << '\n';
ss << '\n';
const Variant* variant() const;
Rank max_rank() const;
File max_file() const;
+ int ranks() const;
+ int files() const;
bool two_boards() const;
Bitboard board_bb() const;
Bitboard board_bb(Color c, PieceType pt) const;
return var->maxFile;
}
+inline int Position::ranks() const {
+ assert(var != nullptr);
+ return var->maxRank + 1;
+}
+
+inline int Position::files() const {
+ assert(var != nullptr);
+ return var->maxFile + 1;
+}
+
inline bool Position::two_boards() const {
assert(var != nullptr);
return var->twoBoards;