Subversion Repositories Games.Chess Giants

Rev

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

Rev 33 Rev 108
Line 1... Line 1...
1
#include "chess.h"
1
#include "chess.h"
2
#include "data.h"
2
#include "data.h"
3
/* last modified 05/08/14 */
3
/* last modified 04/29/15 */
4
/*
4
/*
5
 *******************************************************************************
5
 *******************************************************************************
6
 *                                                                             *
6
 *                                                                             *
7
 *   Repeat() is used to detect a draw by repetition.  The repetition list is  *
7
 *   Repeat() is used to detect a draw by repetition.  The repetition list is  *
8
 *   a simple 1d array that contains the Zobrist signatures for each position  *
8
 *   a simple 1d array that contains the Zobrist signatures for each position  *
Line 30... Line 30...
30
 *   in Iterate() or repetition detection will be broken.                      *
30
 *   in Iterate() or repetition detection will be broken.                      *
31
 *                                                                             *
31
 *                                                                             *
32
 *******************************************************************************
32
 *******************************************************************************
33
 */
33
 */
34
int Repeat(TREE * RESTRICT tree, int ply) {
34
int Repeat(TREE * RESTRICT tree, int ply) {
35
  int where;
35
  int where, count;
36
 
36
 
37
/*
37
/*
38
 ************************************************************
38
 ************************************************************
39
 *                                                          *
39
 *                                                          *
40
 *  If the 50-move rule has been reached, then adjust the   *
40
 *  If the 50-move rule has been reached, then adjust the   *
Line 43... Line 43...
43
 *  irreversible move, there is no way to repeat a prior    *
43
 *  irreversible move, there is no way to repeat a prior    *
44
 *  position.                                               *
44
 *  position.                                               *
45
 *                                                          *
45
 *                                                          *
46
 ************************************************************
46
 ************************************************************
47
 */
47
 */
48
  tree->rep_list[tree->rep_index + ply] = HashKey;
48
  tree->rep_list[rep_index + ply] = HashKey;
49
  if (Reversible(ply) < 4)
49
  if (Reversible(ply) < 4)
50
    return 0;
50
    return 0;
51
  if (Reversible(ply) > 99)
51
  if (Reversible(ply) > 99)
52
    return 2;
52
    return 2;
53
/*
53
/*
Line 63... Line 63...
63
 *  beyond the last capture/pawn move since there can not   *
63
 *  beyond the last capture/pawn move since there can not   *
64
 *  possibly be a repeat beyond that point.                 *
64
 *  possibly be a repeat beyond that point.                 *
65
 *                                                          *
65
 *                                                          *
66
 ************************************************************
66
 ************************************************************
67
 */
67
 */
68
  for (where = tree->rep_index + ply - 2; where >= ply - Reversible(ply) - 2;
68
  count = Reversible(ply) / 2 - 1;
69
      where -= 2)
69
  for (where = rep_index + ply - 4; count; where -= 2, count--) {
70
    if (HashKey == tree->rep_list[where])
70
    if (HashKey == tree->rep_list[where])
71
      return 1;
71
      return 1;
-
 
72
  }
72
  return 0;
73
  return 0;
73
}
74
}
74
 
75
 
75
/* last modified 05/08/14 */
76
/* last modified 05/08/14 */
76
/*
77
/*
Line 82... Line 83...
82
 *   position.)  This is used to actually claim a draw by repetition or by the *
83
 *   position.)  This is used to actually claim a draw by repetition or by the *
83
 *   50 move rule.                                                             *
84
 *   50 move rule.                                                             *
84
 *                                                                             *
85
 *                                                                             *
85
 *******************************************************************************
86
 *******************************************************************************
86
 */
87
 */
87
int Repeat3x(TREE * RESTRICT tree, int wtm) {
88
int Repeat3x(TREE * RESTRICT tree) {
88
  int reps, where;
89
  int reps = 0, where;
89
 
90
 
90
/*
91
/*
91
 ************************************************************
92
 ************************************************************
92
 *                                                          *
93
 *                                                          *
93
 *  If the 50-move rule has been reached, then return an    *
94
 *  If the 50-move rule has been reached, then return an    *
Line 106... Line 107...
106
 *  other entry since the position has to be repeated 3x    *
107
 *  other entry since the position has to be repeated 3x    *
107
 *  with the SAME side on move.                             *
108
 *  with the SAME side on move.                             *
108
 *                                                          *
109
 *                                                          *
109
 ************************************************************
110
 ************************************************************
110
 */
111
 */
111
  reps = 0;
-
 
112
  for (where = tree->rep_index % 2; where < tree->rep_index; where += 2)
112
  for (where = rep_index % 2; where < rep_index; where += 2)
113
    if (HashKey == tree->rep_list[where])
113
    if (HashKey == tree->rep_list[where])
114
      reps++;
114
      reps++;
115
  return reps == 2;
115
  return reps == 2;
116
}
116
}