]> git.sesse.net Git - stockfish/blobdiff - src/endgame.cpp
Proper indenting of multiple conditions
[stockfish] / src / endgame.cpp
index d7cb2b3c8c58541a54d0e662aff2d25110a1e07f..f1f29d61249371f9302d51d4c93ae3049489991d 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "bitcount.h"
 #include "endgame.h"
+#include "movegen.h"
 
 using std::string;
 
@@ -76,27 +77,12 @@ namespace {
     string fen =  sides[0] + char('0' + int(8 - code.length()))
                 + sides[1] + "/8/8/8/8/8/8/8 w - - 0 10";
 
-    return Position(fen, false, 0).material_key();
+    return Position(fen, false, NULL).material_key();
   }
 
   template<typename M>
   void delete_endgame(const typename M::value_type& p) { delete p.second; }
 
-  // Fast stalemate detection with lone king
-  bool is_kxk_stalemate(const Position &pos, const Color c) {
-    if ( pos.side_to_move() == c &&
-        !pos.in_check()) {
-      const Square from = pos.king_square(c);
-      Bitboard b = pos.attacks_from<KING>(from);
-      while (b) {
-        // Assume there are no pinned pieces, as it is a lone king
-        if (pos.pl_move_is_legal(make_move(from, pop_1st_bit(&b)), 0))
-          return false;
-      }
-      return true;
-    }
-    return false;
-  }
 } // namespace
 
 
@@ -130,10 +116,8 @@ Endgames::~Endgames() {
 template<EndgameType E>
 void Endgames::add(const string& code) {
 
-  typedef typename eg_family<E>::type T;
-
-  map((T*)0)[key(code, WHITE)] = new Endgame<E>(WHITE);
-  map((T*)0)[key(code, BLACK)] = new Endgame<E>(BLACK);
+  map((Endgame<E>*)0)[key(code, WHITE)] = new Endgame<E>(WHITE);
+  map((Endgame<E>*)0)[key(code, BLACK)] = new Endgame<E>(BLACK);
 }
 
 
@@ -147,10 +131,13 @@ Value Endgame<KXK>::operator()(const Position& pos) const {
   assert(pos.non_pawn_material(weakerSide) == VALUE_ZERO);
   assert(pos.piece_count(weakerSide, PAWN) == VALUE_ZERO);
 
-  if (is_kxk_stalemate(pos, weakerSide)) {
+  // Stalemate detection with lone king
+  if (    pos.side_to_move() == weakerSide
+      && !pos.in_check()
+      && !MoveList<MV_LEGAL>(pos).size()) {
     return VALUE_DRAW;
   }
-  
+
   Square winnerKSq = pos.king_square(strongerSide);
   Square loserKSq = pos.king_square(weakerSide);
 
@@ -161,7 +148,7 @@ Value Endgame<KXK>::operator()(const Position& pos) const {
 
   if (   pos.piece_count(strongerSide, QUEEN)
       || pos.piece_count(strongerSide, ROOK)
-      || pos.both_color_bishops(strongerSide)) {
+      || pos.bishop_pair(strongerSide)) {
     result += VALUE_KNOWN_WIN;
   }
 
@@ -423,7 +410,7 @@ ScaleFactor Endgame<KBPsK>::operator()(const Position& pos) const {
   File pawnFile = file_of(pos.piece_list(strongerSide, PAWN)[0]);
 
   // All pawns are on a single rook file ?
-  if (   (pawnFile == FILE_A || pawnFile == FILE_H)
+  if (    (pawnFile == FILE_A || pawnFile == FILE_H)
       && !(pawns & ~file_bb(pawnFile)))
   {
       Square bishopSq = pos.piece_list(strongerSide, BISHOP)[0];
@@ -663,7 +650,7 @@ ScaleFactor Endgame<KPsK>::operator()(const Position& pos) const {
   {
       // Does the defending king block the pawns?
       if (   square_distance(ksq, relative_square(strongerSide, SQ_A8)) <= 1
-          || (   file_of(ksq) == FILE_A
+          || (    file_of(ksq) == FILE_A
               && !in_front_bb(strongerSide, ksq) & pawns))
           return SCALE_FACTOR_DRAW;
   }
@@ -672,7 +659,7 @@ ScaleFactor Endgame<KPsK>::operator()(const Position& pos) const {
   {
     // Does the defending king block the pawns?
     if (   square_distance(ksq, relative_square(strongerSide, SQ_H8)) <= 1
-        || (   file_of(ksq) == FILE_H
+        || (    file_of(ksq) == FILE_H
             && !in_front_bb(strongerSide, ksq) & pawns))
         return SCALE_FACTOR_DRAW;
   }
@@ -723,7 +710,7 @@ ScaleFactor Endgame<KBPKB>::operator()(const Position& pos) const {
           return SCALE_FACTOR_DRAW;
       else
       {
-          Bitboard path = squares_in_front_of(strongerSide, pawnSq);
+          Bitboard path = forward_bb(strongerSide, pawnSq);
 
           if (path & pos.pieces(KING, weakerSide))
               return SCALE_FACTOR_DRAW;