Page 1 of 1

KBB and KBBKN ending in SF

Posted: Sun Aug 05, 2012 5:40 pm
by quantum
I have a little more time now and I again try to learn some programming stuff... Besides working with a book, I toy around with stockfish from time to time...

This time I wanted sf to evaluate the KBBK and KBBKN endgames where both B are of the same color as 0.00. However I failed miserably.

In endgame.cpp I changed

Code: Select all

template<>
Value Endgame<KBBKN>::operator()(const Position& pos) const {

  assert(pos.piece_count(strongerSide, BISHOP) == 2);
  assert(pos.non_pawn_material(strongerSide) == 2*BishopValueMidgame);
  assert(pos.piece_count(weakerSide, KNIGHT) == 1);
  assert(pos.non_pawn_material(weakerSide) == KnightValueMidgame);
  assert(!pos.pieces(PAWN));

  Value result = BishopValueEndgame;
  Square wksq = pos.king_square(strongerSide);
  Square bksq = pos.king_square(weakerSide);
  Square nsq = pos.piece_list(weakerSide, KNIGHT)[0];

  // Bonus for attacking king close to defending king
  result += Value(DistanceBonus[square_distance(wksq, bksq)]);

  // Bonus for driving the defending king and knight apart
  result += Value(square_distance(bksq, nsq) * 32);

  // Bonus for restricting the knight's mobility
  result += Value((8 - popcount<Max15>(pos.attacks_from<KNIGHT>(nsq))) * 8);

  return strongerSide == pos.side_to_move() ? result : -result;
}
into

Code: Select all

template<>
Value Endgame<KBBKN>::operator()(const Position& pos) const {

  assert(pos.piece_count(strongerSide, BISHOP) == 2);
  assert(pos.non_pawn_material(strongerSide) == 2*BishopValueMidgame);
  assert(pos.piece_count(weakerSide, KNIGHT) == 1);
  assert(pos.non_pawn_material(weakerSide) == KnightValueMidgame);
  assert(!pos.pieces(PAWN));

  Value result = BishopValueEndgame;
  Square wksq = pos.king_square(strongerSide);
  Square bksq = pos.king_square(weakerSide);
  Square nsq = pos.piece_list(weakerSide, KNIGHT)[0];

if(pos.both_color_bishops(strongerSide)){
return VALUE_DRAW; 
}
else{
 // Bonus for attacking king close to defending king
  result += Value(DistanceBonus[square_distance(wksq, bksq)]);

  // Bonus for driving the defending king and knight apart
  result += Value(square_distance(bksq, nsq) * 32);

  // Bonus for restricting the knight's mobility
  result += Value((8 - popcount<Max15>(pos.attacks_from<KNIGHT>(nsq))) * 8);

  return strongerSide == pos.side_to_move() ? result : -result;
}
}
 
And in position.h I added

Code: Select all

inline bool Position::both_color_bishops(Color c) const {
return  pieceCount[c][BISHOP] >= 2 &&
       opposite_colors(pieceList[c][BISHOP][0], pieceList[c][BISHOP][1]);

}
almost at the end of the file -> see https://github.com/glinscott/Stockfish/ ... 0850dcd13e

Any idea what I did wrong?

Greetings