#include "material.h"
#include "pawns.h"
#include "thread.h"
++#include "uci.h"
namespace Trace {
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.is_semiopen_file(Us, file_of(s)))
- score += RookOnFile[bool(pos.is_semiopen_file(Them, file_of(s)))];
+ if (pos.is_on_semiopen_file(Us, s))
+ score += RookOnFile[bool(pos.is_on_semiopen_file(Them, 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))
pe = Pawns::probe(pos);
score += pe->pawn_score(WHITE) - pe->pawn_score(BLACK);
+ // Early exit if score is high
+ Value v = (mg_value(score) + eg_value(score)) / 2;
- if (abs(v) > (LazyThreshold + pos.non_pawn_material() / 64))
++ if (abs(v) > (LazyThreshold + pos.non_pawn_material() / 64) && Options["UCI_Variant"] == "chess")
+ return pos.side_to_move() == WHITE ? v : -v;
+
// Main evaluation begins here
initialize<WHITE>();
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;
- bool is_semiopen_file(Color c, File f) const;
+ bool is_on_semiopen_file(Color c, Square s) const;
// Castling
int castling_rights(Color c) const;
return st->epSquare;
}
- inline bool Position::is_semiopen_file(Color c, File f) const {
- return !(pieces(c, PAWN, SHOGI_PAWN) & file_bb(f));
+ inline bool Position::is_on_semiopen_file(Color c, Square s) const {
- return !(pieces(c, PAWN) & file_bb(s));
++ return !(pieces(c, PAWN, SHOGI_PAWN) & file_bb(s));
}
inline bool Position::can_castle(CastlingRight cr) const {