Subversion Repositories Games.Chess Giants

Rev

Rev 33 | 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 02/22/14 */
3
/* last modified 01/06/16 */
4
/*
4
/*
5
 *******************************************************************************
5
 *******************************************************************************
6
 *                                                                             *
6
 *                                                                             *
7
 *   MakeMove() is responsible for updating the position database whenever a   *
7
 *   MakeMove() is responsible for updating the position database whenever a   *
8
 *   piece is moved.  It performs the following operations:  (1) update the    *
8
 *   piece is moved.  It performs the following operations:  (1) update the    *
Line 19... Line 19...
19
 *   note:  side = 1 if white is to move, 0 otherwise.  enemy is the opposite  *
19
 *   note:  side = 1 if white is to move, 0 otherwise.  enemy is the opposite  *
20
 *   and is 1 if it is not white to move, 0 otherwise.                         *
20
 *   and is 1 if it is not white to move, 0 otherwise.                         *
21
 *                                                                             *
21
 *                                                                             *
22
 *******************************************************************************
22
 *******************************************************************************
23
 */
23
 */
24
void MakeMove(TREE * RESTRICT tree, int ply, int move, int side) {
24
void MakeMove(TREE * RESTRICT tree, int ply, int side, int move) {
25
  uint64_t bit_move;
25
  uint64_t bit_move;
26
  int piece, from, to, captured, promote, enemy = Flip(side);
26
  int piece, from, to, captured, promote, enemy = Flip(side), cpiece;
27
  int cpiece;
-
 
28
#if defined(DEBUG)
27
#if defined(DEBUG)
29
  int i;
28
  int i;
30
#endif
29
#endif
31
 
30
 
32
/*
31
/*
Line 116... Line 115...
116
        PcOnSq(to) = pieces[side][promote];
115
        PcOnSq(to) = pieces[side][promote];
117
        TotalPieces(side, occupied) += p_vals[promote];
116
        TotalPieces(side, occupied) += p_vals[promote];
118
        TotalPieces(side, promote)++;
117
        TotalPieces(side, promote)++;
119
        Material += PieceValues(side, promote);
118
        Material += PieceValues(side, promote);
120
        Set(to, Pieces(side, promote));
119
        Set(to, Pieces(side, promote));
121
        switch (promote) {
-
 
122
          case knight:
-
 
123
          case bishop:
-
 
124
            TotalMinors(side)++;
-
 
125
            break;
-
 
126
          case rook:
-
 
127
            TotalMajors(side)++;
-
 
128
            break;
-
 
129
          case queen:
-
 
130
            TotalMajors(side) += 2;
-
 
131
            break;
-
 
132
        }
-
 
133
      } else if ((Abs(to - from) == 16) && (mask_eptest[to] & Pawns(enemy))) {
120
      } else if ((Abs(to - from) == 16) && (mask_eptest[to] & Pawns(enemy))) {
134
        EnPassant(ply + 1) = to + epsq[side];
121
        EnPassant(ply + 1) = to + epsq[side];
135
        HashEP(to + epsq[side]);
122
        HashEP(to + epsq[side]);
136
      }
123
      }
137
      break;
124
      break;
Line 204... Line 191...
204
      case pawn:
191
      case pawn:
205
        HashP(enemy, to);
192
        HashP(enemy, to);
206
        break;
193
        break;
207
      case knight:
194
      case knight:
208
      case bishop:
195
      case bishop:
209
        TotalMinors(enemy)--;
196
      case queen:
210
        break;
197
        break;
211
      case rook:
198
      case rook:
212
        if (Castle(ply + 1, enemy) > 0) {
199
        if (Castle(ply + 1, enemy) > 0) {
213
          if ((to == rook_A[enemy]) && (Castle(ply + 1, enemy) & 2)) {
200
          if ((to == rook_A[enemy]) && (Castle(ply + 1, enemy) & 2)) {
214
            Castle(ply + 1, enemy) &= 1;
201
            Castle(ply + 1, enemy) &= 1;
Line 216... Line 203...
216
          } else if ((to == rook_H[enemy]) && (Castle(ply + 1, enemy) & 1)) {
203
          } else if ((to == rook_H[enemy]) && (Castle(ply + 1, enemy) & 1)) {
217
            Castle(ply + 1, enemy) &= 2;
204
            Castle(ply + 1, enemy) &= 2;
218
            HashCastle(0, enemy);
205
            HashCastle(0, enemy);
219
          }
206
          }
220
        }
207
        }
221
        TotalMajors(enemy)--;
-
 
222
        break;
-
 
223
      case queen:
-
 
224
        TotalMajors(enemy) -= 2;
-
 
225
        break;
208
        break;
226
      case king:
209
      case king:
227
#if defined(DEBUG)
210
#if defined(DEBUG)
228
        Print(128, "captured a king (Make)\n");
211
        Print(2048, "captured a king (Make)\n");
229
        for (i = 1; i <= ply; i++)
212
        for (i = 1; i <= ply; i++)
-
 
213
          Print(2048,
230
          Print(128, "ply=%2d, piece=%2d,from=%2d,to=%2d,captured=%2d\n", i,
214
              "ply=%2d, phase=%d, piece=%2d,from=%2d,to=%2d,captured=%2d\n",
231
              Piece(tree->curmv[i]), From(tree->curmv[i]), To(tree->curmv[i]),
215
              i, tree->phase[i], Piece(tree->curmv[i]), From(tree->curmv[i]),
232
              Captured(tree->curmv[i]));
216
              To(tree->curmv[i]), Captured(tree->curmv[i]));
233
        Print(128, "ply=%2d, piece=%2d,from=%2d,to=%2d,captured=%2d\n", i,
217
        Print(2048, "ply=%2d, piece=%2d,from=%2d,to=%2d,captured=%2d\n", i,
234
            piece, from, to, captured);
218
            piece, from, to, captured);
235
        if (log_file)
219
        if (log_file)
236
          DisplayChessBoard(log_file, tree->position);
220
          DisplayChessBoard(log_file, tree->position);
237
#endif
221
#endif
238
        break;
222
        break;
Line 242... Line 226...
242
  ValidatePosition(tree, ply + 1, move, "MakeMove(2)");
226
  ValidatePosition(tree, ply + 1, move, "MakeMove(2)");
243
#endif
227
#endif
244
  return;
228
  return;
245
}
229
}
246
 
230
 
247
/* last modified 05/08/14 */
231
/* last modified 01/06/16 */
248
/*
232
/*
249
 *******************************************************************************
233
 *******************************************************************************
250
 *                                                                             *
234
 *                                                                             *
251
 *   MakeMoveRoot() is used to make a move at the root of the game tree,       *
235
 *   MakeMoveRoot() is used to make a move at the root of the game tree,       *
252
 *   before any searching is done.  It uses MakeMove() to execute the move,    *
236
 *   before any searching is done.  It uses MakeMove() to execute the move,    *
Line 255... Line 239...
255
 *   rule by clearing the repetition list when a non-reversible move is made,  *
239
 *   rule by clearing the repetition list when a non-reversible move is made,  *
256
 *   since no repetitions are possible once such a move is played.             *
240
 *   since no repetitions are possible once such a move is played.             *
257
 *                                                                             *
241
 *                                                                             *
258
 *******************************************************************************
242
 *******************************************************************************
259
 */
243
 */
260
void MakeMoveRoot(TREE * RESTRICT tree, int move, int side) {
244
void MakeMoveRoot(TREE * RESTRICT tree, int side, int move) {
261
  int player;
245
  int player;
262
 
246
 
263
/*
247
/*
264
 ************************************************************
248
 ************************************************************
265
 *                                                          *
249
 *                                                          *
266
 *  First, make the move and then reset the repetition      *
250
 *  First, make the move and then reset the repetition      *
267
 *  index if the 50 move rule counter was reset to zero.    *
251
 *  index if the 50 move rule counter was reset to zero.    *
268
 *                                                          *
252
 *                                                          *
269
 ************************************************************
253
 ************************************************************
270
 */
254
 */
271
  MakeMove(tree, 0, move, side);
255
  MakeMove(tree, 0, side, move);
272
  if (Reversible(1) == 0)
256
  if (Reversible(1) == 0)
273
    tree->rep_index = -1;
257
    rep_index = -1;
274
  tree->rep_list[++(tree->rep_index)] = HashKey;
258
  tree->rep_list[++rep_index] = HashKey;
275
/*
259
/*
276
 ************************************************************
260
 ************************************************************
277
 *                                                          *
261
 *                                                          *
278
 *  One odd action is to note if the castle status is       *
262
 *  One odd action is to note if the castle status is       *
279
 *  currently negative, which indicates that that side      *
263
 *  currently negative, which indicates that that side      *