Subversion Repositories Games.Chess Giants

Rev

Rev 108 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 108 Rev 154
Line 1... Line 1...
1
#include "chess.h"
1
#include "chess.h"
2
#include "data.h"
2
#include "data.h"
3
/* last modified 01/10/16 */
3
/* last modified 08/03/16 */
4
/*
4
/*
5
 *******************************************************************************
5
 *******************************************************************************
6
 *                                                                             *
6
 *                                                                             *
7
 *   Quiece() is the recursive routine used to implement the quiescence        *
7
 *   Quiece() is the recursive routine used to implement the quiescence        *
8
 *   search part of the alpha/beta negamax search.  It performs the following  *
8
 *   search part of the alpha/beta negamax search.  It performs the following  *
Line 40... Line 40...
40
 *******************************************************************************
40
 *******************************************************************************
41
 */
41
 */
42
int Quiesce(TREE * RESTRICT tree, int ply, int wtm, int alpha, int beta,
42
int Quiesce(TREE * RESTRICT tree, int ply, int wtm, int alpha, int beta,
43
    int checks) {
43
    int checks) {
44
  unsigned *next, *movep;
44
  unsigned *next, *movep;
45
  int original_alpha = alpha, value;
45
  int original_alpha = alpha, value, repeat;
46
 
46
 
47
/*
47
/*
48
 ************************************************************
48
 ************************************************************
49
 *                                                          *
49
 *                                                          *
50
 *  Initialize.                                             *
50
 *  Initialize.                                             *
Line 73... Line 73...
73
 *  zero so that additional plies of checks are not tried.  *
73
 *  zero so that additional plies of checks are not tried.  *
74
 *                                                          *
74
 *                                                          *
75
 ************************************************************
75
 ************************************************************
76
 */
76
 */
77
  if (checks) {
77
  if (checks) {
78
    if (Repeat(tree, ply)) {
78
    repeat = Repeat(tree, ply);
-
 
79
    if (repeat) {
79
      value = DrawScore(wtm);
80
      value = DrawScore(wtm);
80
      if (value < beta)
81
      if (value < beta)
81
        SavePV(tree, ply, 0);
82
        SavePV(tree, ply, repeat);
82
#if defined(TRACE)
83
#if defined(TRACE)
83
      if (ply <= trace_level)
84
      if (ply <= trace_level)
84
        printf("draw by repetition detected, ply=%d.\n", ply);
85
        printf("draw by repetition detected, ply=%d.\n", ply);
85
#endif
86
#endif
86
      return value;
87
      return value;
Line 98... Line 99...
98
 ************************************************************
99
 ************************************************************
99
 */
100
 */
100
  value = Evaluate(tree, ply, wtm, alpha, beta);
101
  value = Evaluate(tree, ply, wtm, alpha, beta);
101
#if defined(TRACE)
102
#if defined(TRACE)
102
  if (ply <= trace_level)
103
  if (ply <= trace_level)
103
    Trace(tree, ply, value, wtm, alpha, beta, "Quiesce", serial, EVALUATION, 0);
104
    Trace(tree, ply, value, wtm, alpha, beta, "Quiesce", serial, EVALUATION,
-
 
105
        0);
104
#endif
106
#endif
105
  if (value > alpha) {
107
  if (value > alpha) {
106
    if (value >= beta)
108
    if (value >= beta)
107
      return value;
109
      return value;
108
    alpha = value;
110
    alpha = value;
Line 264... Line 266...
264
    tree->pv[ply - 1].path[ply - 1] = tree->curmv[ply - 1];
266
    tree->pv[ply - 1].path[ply - 1] = tree->curmv[ply - 1];
265
  }
267
  }
266
  return alpha;
268
  return alpha;
267
}
269
}
268
 
270
 
269
/* last modified 01/10/16 */
271
/* last modified 08/03/16 */
270
/*
272
/*
271
 *******************************************************************************
273
 *******************************************************************************
272
 *                                                                             *
274
 *                                                                             *
273
 *   QuiesceEvasions() is the recursive routine used to implement the alpha/   *
275
 *   QuiesceEvasions() is the recursive routine used to implement the alpha/   *
274
 *   beta negamax quiescence search.  The primary function here is to escape a *
276
 *   beta negamax quiescence search.  The primary function here is to escape a *
275
 *   check that was delivered by QuiesceChecks() at the previous ply.  We do   *
277
 *   check that was delivered by Quiesce() at the previous ply.  We do not     *
276
 *   not have the usual "stand pat" option because we have to find a legal     *
278
 *   have the usual "stand pat" option because we have to find a legal move to *
277
 *   move to prove we have not been checkmated.                                *
279
 *   prove we have not been checkmated.                                        *
278
 *                                                                             *
280
 *                                                                             *
279
 *   QuiesceEvasions() uses the legal move generator (GenerateCheckEvasions()) *
281
 *   QuiesceEvasions() uses the legal move generator (GenerateCheckEvasions()) *
280
 *   to produce only the set of legal moves that escape check.  We try those   *
282
 *   to produce only the set of legal moves that escape check.  We try those   *
281
 *   in the the order they are generated since we are going to try them all    *
283
 *   in the the order they are generated since we are going to try them all    *
282
 *   unless we get a fail-high.                                                *
284
 *   unless we get a fail-high.                                                *
283
 *                                                                             *
285
 *                                                                             *
284
 *******************************************************************************
286
 *******************************************************************************
285
 */
287
 */
286
int QuiesceEvasions(TREE * RESTRICT tree, int ply, int wtm, int alpha,
288
int QuiesceEvasions(TREE * RESTRICT tree, int ply, int wtm, int alpha,
287
    int beta) {
289
    int beta) {
288
  int original_alpha, value, moves_searched = 0, order;
290
  int original_alpha, value, moves_searched = 0, order, repeat;
289
 
291
 
290
/*
292
/*
291
 ************************************************************
293
 ************************************************************
292
 *                                                          *
294
 *                                                          *
293
 *  Initialize.                                             *
295
 *  Initialize.                                             *
Line 310... Line 312...
310
 *  Check for draw by repetition, which includes 50 move    *
312
 *  Check for draw by repetition, which includes 50 move    *
311
 *  draws also.                                             *
313
 *  draws also.                                             *
312
 *                                                          *
314
 *                                                          *
313
 ************************************************************
315
 ************************************************************
314
 */
316
 */
315
  if (Repeat(tree, ply)) {
317
  repeat = Repeat(tree, ply);
-
 
318
  if (repeat) {
316
    value = DrawScore(wtm);
319
    value = DrawScore(wtm);
317
    if (value < beta)
320
    if (value < beta)
318
      SavePV(tree, ply, 0);
321
      SavePV(tree, ply, repeat);
319
#if defined(TRACE)
322
#if defined(TRACE)
320
    if (ply <= trace_level)
323
    if (ply <= trace_level)
321
      printf("draw by repetition detected, ply=%d.\n", ply);
324
      printf("draw by repetition detected, ply=%d.\n", ply);
322
#endif
325
#endif
323
    return value;
326
    return value;