Skip to content

Commit

Permalink
Added files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
NervosTech committed May 8, 2016
1 parent f782b73 commit f60eef4
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 32 deletions.
4 changes: 0 additions & 4 deletions Srcs/bitboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,6 @@ inline int popcount(Bitboard b) {

return (int)_mm_popcnt_u64(b);

#elif defined(_MSC_VER)

return (int)__popcnt64(b);

#else // Assumed gcc or compatible compiler

return __builtin_popcountll(b);
Expand Down
59 changes: 38 additions & 21 deletions Srcs/evaluate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ namespace {
const Score Unstoppable = S( 0, 20);
Score Hanging = S(48, 27);
const Score PawnAttackThreat = S(38, 22);
const Score Checked = S(20, 20);
const Score SafeCheck = S(20, 20);
const Score OtherCheck = S(10, 10);

// Penalty for a bishop on a1/h1 (a8/h8 for black) which is trapped by
// a friendly pawn on b2/g2 (b7/g7 for black). This can obviously only
Expand Down Expand Up @@ -392,9 +393,10 @@ namespace {
template<Color Us, bool Trace>
Score evaluate_king(const Position& pos, const EvalInfo& ei) {

const Color Them = (Us == WHITE ? BLACK : WHITE);
const Color Them = (Us == WHITE ? BLACK : WHITE);
const Square Up = (Us == WHITE ? DELTA_N : DELTA_S);

Bitboard undefended, b, b1, b2, safe;
Bitboard undefended, b, b1, b2, safe, other;
int attackUnits;
const Square ksq = pos.square<KING>(Us);

Expand Down Expand Up @@ -441,27 +443,42 @@ namespace {
if (b)attackUnits += QueenContactCheck * popcount(b);
}

// Analyse the enemy's safe distance checks for sliders and knights
safe = ~(ei.attackedBy[Us][ALL_PIECES] | pos.pieces(Them));
// Analyse the safe enemy's checks which are possible on next move...
safe = ~(ei.attackedBy[Us][ALL_PIECES] | pos.pieces(Them));

// ... and some other potential checks, only requiring the square to be
// safe from pawn-attacks, and not being occupied by a blocked pawn.
other = ~( ei.attackedBy[Us][PAWN]
| (pos.pieces(Them, PAWN) & shift_bb<Up>(pos.pieces(PAWN))));

b1 = pos.attacks_from<ROOK >(ksq) & safe;
b2 = pos.attacks_from<BISHOP>(ksq) & safe;
b1 = pos.attacks_from<ROOK >(ksq);
b2 = pos.attacks_from<BISHOP>(ksq);

// Enemy queen safe checks
if ((b1 | b2) & ei.attackedBy[Them][QUEEN])
attackUnits += QueenCheck, score -= Checked;

// Enemy rooks safe checks
if (b1 & ei.attackedBy[Them][ROOK])
attackUnits += RookCheck, score -= Checked;

// Enemy bishops safe checks
if (b2 & ei.attackedBy[Them][BISHOP])
attackUnits += BishopCheck, score -= Checked;

// Enemy knights safe checks
if (pos.attacks_from<KNIGHT>(ksq) & ei.attackedBy[Them][KNIGHT] & safe)
attackUnits += KnightCheck, score -= Checked;
if ((b1 | b2) & ei.attackedBy[Them][QUEEN] & safe)
attackUnits += QueenCheck, score -= SafeCheck;

// Enemy rooks safe and other checks
if (b1 & ei.attackedBy[Them][ROOK] & safe)
attackUnits += RookCheck, score -= SafeCheck;

else if (b1 & ei.attackedBy[Them][ROOK] & other)
score -= OtherCheck;

// Enemy bishops safe and other checks
if (b2 & ei.attackedBy[Them][BISHOP] & safe)
attackUnits += BishopCheck, score -= SafeCheck;

else if (b2 & ei.attackedBy[Them][BISHOP] & other)
score -= OtherCheck;

// Enemy knights safe and other checks
b = pos.attacks_from<KNIGHT>(ksq) & ei.attackedBy[Them][KNIGHT];
if (b & safe)
attackUnits += KnightCheck, score -= SafeCheck;

else if (b & other)
score -= OtherCheck;

// Finally, extract the king danger score from the KingDanger[]
// array and subtract the score from the evaluation.
Expand Down
2 changes: 1 addition & 1 deletion Srcs/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace {

/// Version number. If Version is left empty, then compile date in the format
/// DD-MM-YY and show in engine_info.
static const string Version = "Nayeem 5.1";
static const string Version = "Nayeem 5.2";

/// Our fancy logging facility. The trick here is to replace cin.rdbuf() and
/// cout.rdbuf() with two Tie objects that tie cin and cout to a file stream. We
Expand Down
7 changes: 3 additions & 4 deletions Srcs/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1011,13 +1011,12 @@ namespace {
Value fmValue = (fm ? (*fm)[pos.piece_on(to_sq(move))][to_sq(move)] : VALUE_ZERO);
Value fm2Value = (fm2 ? (*fm2)[pos.piece_on(to_sq(move))][to_sq(move)] : VALUE_ZERO);

// Increase reduction for cut nodes and moves with a bad history
if ( (!PvNode && cutNode)
|| (hValue < VALUE_ZERO && cmhValue <= VALUE_ZERO))
// Increase reduction for cut nodes
if (!PvNode && cutNode)
r += ONE_PLY;

// Decrease/increase reduction for moves with a good/bad history
int rHist = (hValue + cmhValue + fmValue + fm2Value) / 20000;
int rHist = (hValue + cmhValue + fmValue + fm2Value - 10000) / 20000;
r = std::max(DEPTH_ZERO, r - rHist * ONE_PLY);

// Decrease reduction for moves that escape a capture. Filter out
Expand Down
4 changes: 2 additions & 2 deletions Srcs/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@
/// _WIN64 Building on Windows 64 bit

#if defined(_WIN64) && defined(_MSC_VER) // No Makefile used
# include <intrin.h> // MSVC popcnt and bsfq instrinsics
# include <intrin.h> // Microsoft header for _BitScanForward64()
# define IS_64BIT
#endif


#if defined(USE_POPCNT) && (defined(__INTEL_COMPILER) || defined(_MSC_VER))
# include <nmmintrin.h> // Intel header for _mm_popcnt_u64() intrinsic
# include <nmmintrin.h> // Intel and Microsoft header for _mm_popcnt_u64()
#endif

#if !defined(NO_PREFETCH) && (defined(__INTEL_COMPILER) || defined(_MSC_VER))
Expand Down

0 comments on commit f60eef4

Please sign in to comment.