Subversion Repositories Games.Chess Giants

Rev

Rev 96 | Rev 169 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 96 Rev 154
Line 20... Line 20...
20
 
20
 
21
#include <algorithm>
21
#include <algorithm>
22
#include <cassert>
22
#include <cassert>
23
 
23
 
24
#include "bitboard.h"
24
#include "bitboard.h"
25
#include "bitcount.h"
-
 
26
#include "endgame.h"
25
#include "endgame.h"
27
#include "movegen.h"
26
#include "movegen.h"
28
 
27
 
29
using std::string;
28
using std::string;
30
 
29
 
Line 98... Line 97...
98
    std::transform(sides[c].begin(), sides[c].end(), sides[c].begin(), tolower);
97
    std::transform(sides[c].begin(), sides[c].end(), sides[c].begin(), tolower);
99
 
98
 
100
    string fen =  sides[0] + char(8 - sides[0].length() + '0') + "/8/8/8/8/8/8/"
99
    string fen =  sides[0] + char(8 - sides[0].length() + '0') + "/8/8/8/8/8/8/"
101
                + sides[1] + char(8 - sides[1].length() + '0') + " w - - 0 10";
100
                + sides[1] + char(8 - sides[1].length() + '0') + " w - - 0 10";
102
 
101
 
-
 
102
    StateInfo st;
103
    return Position(fen, false, nullptr).material_key();
103
    return Position().set(fen, false, &st, nullptr).material_key();
104
  }
104
  }
105
 
105
 
106
} // namespace
106
} // namespace
107
 
107
 
108
 
108
 
Line 257... Line 257...
257
           && rank_of(wksq) >= RANK_4
257
           && rank_of(wksq) >= RANK_4
258
           && distance(wksq, psq) > 2 + (pos.side_to_move() == strongSide))
258
           && distance(wksq, psq) > 2 + (pos.side_to_move() == strongSide))
259
      result = Value(80) - 8 * distance(wksq, psq);
259
      result = Value(80) - 8 * distance(wksq, psq);
260
 
260
 
261
  else
261
  else
262
      result =  Value(200) - 8 * (  distance(wksq, psq + DELTA_S)
262
      result =  Value(200) - 8 * (  distance(wksq, psq + SOUTH)
263
                                  - distance(bksq, psq + DELTA_S)
263
                                  - distance(bksq, psq + SOUTH)
264
                                  - distance(psq, queeningSq));
264
                                  - distance(psq, queeningSq));
265
 
265
 
266
  return strongSide == pos.side_to_move() ? result : -result;
266
  return strongSide == pos.side_to_move() ? result : -result;
267
}
267
}
268
 
268
 
Line 494... Line 494...
494
      return SCALE_FACTOR_DRAW;
494
      return SCALE_FACTOR_DRAW;
495
 
495
 
496
  // If the defending king blocks the pawn and the attacking king is too far
496
  // If the defending king blocks the pawn and the attacking king is too far
497
  // away, it's a draw.
497
  // away, it's a draw.
498
  if (   r <= RANK_5
498
  if (   r <= RANK_5
499
      && bksq == wpsq + DELTA_N
499
      && bksq == wpsq + NORTH
500
      && distance(wksq, wpsq) - tempo >= 2
500
      && distance(wksq, wpsq) - tempo >= 2
501
      && distance(wksq, brsq) - tempo >= 2)
501
      && distance(wksq, brsq) - tempo >= 2)
502
      return SCALE_FACTOR_DRAW;
502
      return SCALE_FACTOR_DRAW;
503
 
503
 
504
  // Pawn on the 7th rank supported by the rook from behind usually wins if the
504
  // Pawn on the 7th rank supported by the rook from behind usually wins if the
Line 515... Line 515...
515
  // Similar to the above, but with the pawn further back
515
  // Similar to the above, but with the pawn further back
516
  if (   f != FILE_A
516
  if (   f != FILE_A
517
      && file_of(wrsq) == f
517
      && file_of(wrsq) == f
518
      && wrsq < wpsq
518
      && wrsq < wpsq
519
      && (distance(wksq, queeningSq) < distance(bksq, queeningSq) - 2 + tempo)
519
      && (distance(wksq, queeningSq) < distance(bksq, queeningSq) - 2 + tempo)
520
      && (distance(wksq, wpsq + DELTA_N) < distance(bksq, wpsq + DELTA_N) - 2 + tempo)
520
      && (distance(wksq, wpsq + NORTH) < distance(bksq, wpsq + NORTH) - 2 + tempo)
521
      && (  distance(bksq, wrsq) + tempo >= 3
521
      && (  distance(bksq, wrsq) + tempo >= 3
522
          || (    distance(wksq, queeningSq) < distance(bksq, wrsq) + tempo
522
          || (    distance(wksq, queeningSq) < distance(bksq, wrsq) + tempo
523
              && (distance(wksq, wpsq + DELTA_N) < distance(bksq, wrsq) + tempo))))
523
              && (distance(wksq, wpsq + NORTH) < distance(bksq, wrsq) + tempo))))
524
      return ScaleFactor(  SCALE_FACTOR_MAX
524
      return ScaleFactor(  SCALE_FACTOR_MAX
525
                         - 8 * distance(wpsq, queeningSq)
525
                         - 8 * distance(wpsq, queeningSq)
526
                         - 2 * distance(wksq, queeningSq));
526
                         - 2 * distance(wksq, queeningSq));
527
 
527
 
528
  // If the pawn is not far advanced and the defending king is somewhere in
528
  // If the pawn is not far advanced and the defending king is somewhere in