home *** CD-ROM | disk | FTP | other *** search
/ Dream 57 / Amiga_Dream_57.iso / Amiga / Jeux / Reflexion / Crafty-15.19.lha / crafty-15.19 / src / make.c < prev    next >
C/C++ Source or Header  |  1998-09-13  |  23KB  |  663 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "chess.h"
  4. #include "data.h"
  5.  
  6. /* last modified 03/11/98 */
  7. /*
  8. ********************************************************************************
  9. *                                                                              *
  10. *   MakeMove() is responsible for updating the position database whenever a    *
  11. *   piece is moved.  it performs the following operations:  (1) update the     *
  12. *   board structure itself by moving the piece and removing any captured       *
  13. *   piece.  (2) update the hash keys.  (3) update material counts.  (4) update *
  14. *   castling status.  (5) update number of moves since last reversible move.   *
  15. *                                                                              *
  16. ********************************************************************************
  17. */
  18. void MakeMove(TREE *tree, int ply, int move, int wtm)
  19. {
  20.   register int piece, from, to, captured, promote;
  21.   BITBOARD bit_move;
  22. /*
  23.  ----------------------------------------------------------
  24. |                                                          |
  25. |   first, clear the EnPassant_Target bit-mask.  moving a  |
  26. |   pawn two ranks will set it later in MakeMove().        |
  27. |                                                          |
  28.  ----------------------------------------------------------
  29. */
  30. #if defined(DEBUG)
  31.   ValidatePosition(tree,ply,move,"MakeMove(1)");
  32. #endif
  33.   tree->position[ply+1]=tree->position[ply];
  34.   tree->save_hash_key[ply]=HashKey;
  35.   tree->save_pawn_hash_key[ply]=PawnHashKey;
  36.   if (EnPassant(ply+1)) {
  37.     HashEP(EnPassant(ply+1),HashKey);
  38.     EnPassant(ply+1)=0;
  39.   }
  40.   Rule50Moves(ply+1)++;
  41. /*
  42.  ----------------------------------------------------------
  43. |                                                          |
  44. |   now do the piece-specific things by calling the        |
  45. |   appropriate routine.                                   |
  46. |                                                          |
  47.  ----------------------------------------------------------
  48. */
  49.   piece=Piece(move);
  50.   from=From(move);
  51.   to=To(move);
  52.   captured=Captured(move);
  53.   promote=Promote(move);
  54. MakePieceMove:
  55.   ClearRL90(from,OccupiedRL90);
  56.   ClearRL45(from,OccupiedRL45);
  57.   ClearRR45(from,OccupiedRR45);
  58.   SetRL90(to,OccupiedRL90);
  59.   SetRL45(to,OccupiedRL45);
  60.   SetRR45(to,OccupiedRR45);
  61.   bit_move=Or(set_mask[from],set_mask[to]);
  62.   PieceOnSquare(from)=0;
  63.   switch (piece) {
  64. /*
  65. ********************************************************************************
  66. *                                                                              *
  67. *   make pawn moves.  there are two special cases:  (a) enpassant captures     *
  68. *   where the captured pawn is not on the "to" square and must be removed in   *
  69. *   a different way, and (2) pawn promotions (where the "Promote" variable     *
  70. *   is non-zero) requires updating the appropriate bit boards since we are     *
  71. *   creating a new piece.                                                      *
  72. *                                                                              *
  73. ********************************************************************************
  74. */
  75.   case pawn:
  76.     if (wtm) {
  77.       ClearSet(bit_move,WhitePawns);
  78.       ClearSet(bit_move,WhitePieces);
  79.       HashPW(from,HashKey);
  80.       HashPW32(from,PawnHashKey);
  81.       HashPW(to,HashKey);
  82.       HashPW32(to,PawnHashKey);
  83.       PieceOnSquare(to)=pawn;
  84.       if (captured == 1) {
  85.         if(!And(BlackPawns,set_mask[to])) {
  86.           ClearRL90(to-8,OccupiedRL90);
  87.           ClearRL45(to-8,OccupiedRL45);
  88.           ClearRR45(to-8,OccupiedRR45);
  89.           Clear(to-8,BlackPawns);
  90.           Clear(to-8,BlackPieces);
  91.           HashPB(to-8,HashKey);
  92.           HashPB32(to-8,PawnHashKey);
  93.           PieceOnSquare(to-8)=0;
  94.           Material+=PAWN_VALUE;
  95.           TotalBlackPawns--;
  96.           TotalPieces--;
  97.           captured=0;
  98.         }
  99.       }
  100.   /*
  101.    --------------------------------------------------------------------
  102.   |                                                                    |
  103.   |  if this is a pawn promotion, remove the pawn from the counts      |
  104.   |  then update the correct piece board to reflect the piece just     |
  105.   |  created.                                                          |
  106.   |                                                                    |
  107.    --------------------------------------------------------------------
  108.   */
  109.       if (promote) {
  110.         TotalWhitePawns--;
  111.         Material-=PAWN_VALUE;
  112.         Clear(to,WhitePawns);
  113.         HashPW(to,HashKey);
  114.         HashPW32(to,PawnHashKey);
  115.         switch (promote) {
  116.         case knight:
  117.           Set(to,WhiteKnights);
  118.           HashNW(to,HashKey);
  119.           PieceOnSquare(to)=knight;
  120.           TotalWhitePieces+=knight_v;
  121.           WhiteMinors++;
  122.           Material+=KNIGHT_VALUE;
  123.           break;
  124.         case bishop:
  125.           Set(to,WhiteBishops);
  126.           Set(to,BishopsQueens);
  127.           HashBW(to,HashKey);
  128.           PieceOnSquare(to)=bishop;
  129.           TotalWhitePieces+=bishop_v;
  130.           WhiteMinors++;
  131.           Material+=BISHOP_VALUE;
  132.           break;
  133.         case rook:
  134.           Set(to,WhiteRooks);
  135.           Set(to,RooksQueens);
  136.           HashRW(to,HashKey);
  137.           PieceOnSquare(to)=rook;
  138.           TotalWhitePieces+=rook_v;
  139.           WhiteMajors++;
  140.           Material+=ROOK_VALUE;
  141.           break;
  142.         case queen:
  143.           Set(to,WhiteQueens);
  144.           Set(to,BishopsQueens);
  145.           Set(to,RooksQueens);
  146.           HashQW(to,HashKey);
  147.           PieceOnSquare(to)=queen;
  148.           TotalWhitePieces+=queen_v;
  149.           WhiteMajors+=2;
  150.           Material+=QUEEN_VALUE;
  151.           break;
  152.         }
  153.       }
  154.       else 
  155.         if (((to-from) == 16) && And(mask_eptest[to],BlackPawns)) {
  156.           EnPassant(ply+1)=to-8;
  157.           HashEP(to-8,HashKey);
  158.         }
  159.     }
  160.     else {
  161.       ClearSet(bit_move,BlackPawns);
  162.       ClearSet(bit_move,BlackPieces);
  163.       HashPB(from,HashKey);
  164.       HashPB32(from,PawnHashKey);
  165.       HashPB(to,HashKey);
  166.       HashPB32(to,PawnHashKey);
  167.       PieceOnSquare(to)=-pawn;
  168.       if (captured == 1) {
  169.         if(!And(WhitePawns,set_mask[to])) {
  170.           ClearRL90(to+8,OccupiedRL90);
  171.           ClearRL45(to+8,OccupiedRL45);
  172.           ClearRR45(to+8,OccupiedRR45);
  173.           Clear(to+8,WhitePawns);
  174.           Clear(to+8,WhitePieces);
  175.           HashPW(to+8,HashKey);
  176.           HashPW32(to+8,PawnHashKey);
  177.           PieceOnSquare(to+8)=0;
  178.           Material-=PAWN_VALUE;
  179.           TotalWhitePawns--;
  180.           TotalPieces--;
  181.           captured=0;
  182.         }
  183.       }
  184. /*
  185.  --------------------------------------------------------------------
  186. |                                                                    |
  187. |  if this is a pawn promotion, remove the pawn from the counts      |
  188. |  then update the correct piece board to reflect the piece just     |
  189. |  created.                                                          |
  190. |                                                                    |
  191.  --------------------------------------------------------------------
  192. */
  193.       if (promote) {
  194.         TotalBlackPawns--;
  195.         Material+=PAWN_VALUE;
  196.         Clear(to,BlackPawns);
  197.         HashPB(to,HashKey);
  198.         HashPB32(to,PawnHashKey);
  199.         switch (promote) {
  200.         case knight:
  201.           Set(to,BlackKnights);
  202.           HashNB(to,HashKey);
  203.           PieceOnSquare(to)=-knight;
  204.           TotalBlackPieces+=knight_v;
  205.           BlackMinors++;
  206.           Material-=KNIGHT_VALUE;
  207.           break;
  208.         case bishop:
  209.           Set(to,BlackBishops);
  210.           Set(to,BishopsQueens);
  211.           HashBB(to,HashKey);
  212.           PieceOnSquare(to)=-bishop;
  213.           TotalBlackPieces+=bishop_v;
  214.           BlackMinors++;
  215.           Material-=BISHOP_VALUE;
  216.           break;
  217.         case rook:
  218.           Set(to,BlackRooks);
  219.           Set(to,RooksQueens);
  220.           HashRB(to,HashKey);
  221.           PieceOnSquare(to)=-rook;
  222.           TotalBlackPieces+=rook_v;
  223.           BlackMajors++;
  224.           Material-=ROOK_VALUE;
  225.           break;
  226.         case queen:
  227.           Set(to,BlackQueens);
  228.           Set(to,BishopsQueens);
  229.           Set(to,RooksQueens);
  230.           HashQB(to,HashKey);
  231.           PieceOnSquare(to)=-queen;
  232.           TotalBlackPieces+=queen_v;
  233.           BlackMajors+=2;
  234.           Material-=QUEEN_VALUE;
  235.           break;
  236.         }
  237.       }
  238.       else 
  239.         if (((from-to) == 16) && And(mask_eptest[to],WhitePawns)) {
  240.           EnPassant(ply+1)=to+8;
  241.           HashEP(to+8,HashKey);
  242.         }
  243.     }
  244.     Rule50Moves(ply+1)=0;
  245.     break;
  246. /*
  247. ********************************************************************************
  248. *                                                                              *
  249. *   make knight moves.                                                         *
  250. *                                                                              *
  251. ********************************************************************************
  252. */
  253.   case knight:
  254.     if (wtm) {
  255.       ClearSet(bit_move,WhiteKnights);
  256.       ClearSet(bit_move,WhitePieces);
  257.       HashNW(from,HashKey);
  258.       HashNW(to,HashKey);
  259.       PieceOnSquare(to)=knight;
  260.     }
  261.     else {
  262.       ClearSet(bit_move,BlackKnights);
  263.       ClearSet(bit_move,BlackPieces);
  264.       HashNB(from,HashKey);
  265.       HashNB(to,HashKey);
  266.       PieceOnSquare(to)=-knight;
  267.     }
  268.     break;
  269. /*
  270. ********************************************************************************
  271. *                                                                              *
  272. *   make bishop moves.                                                         *
  273. *                                                                              *
  274. ********************************************************************************
  275. */
  276.   case bishop:
  277.     ClearSet(bit_move,BishopsQueens);
  278.     if (wtm) {
  279.       ClearSet(bit_move,WhiteBishops);
  280.       ClearSet(bit_move,WhitePieces);
  281.       HashBW(from,HashKey);
  282.       HashBW(to,HashKey);
  283.       PieceOnSquare(to)=bishop;
  284.     }
  285.     else {
  286.       ClearSet(bit_move,BlackBishops);
  287.       ClearSet(bit_move,BlackPieces);
  288.       HashBB(from,HashKey);
  289.       HashBB(to,HashKey);
  290.       PieceOnSquare(to)=-bishop;
  291.     }
  292.     break;
  293. /*
  294. ********************************************************************************
  295. *                                                                              *
  296. *   make rook moves.  the only special case handling required is to determine  *
  297. *   if x_castle is non-zero [x=w or b based on side to move].  if it is non-   *
  298. *   zero, the value must be corrected if either rook is moving from its        *
  299. *   original square, so that castling with that rook becomes impossible.       *
  300. *                                                                              *
  301. ********************************************************************************
  302. */
  303.   case rook:
  304.     ClearSet(bit_move,RooksQueens);
  305.     if (wtm) {
  306.       ClearSet(bit_move,WhiteRooks);
  307.       ClearSet(bit_move,WhitePieces);
  308.       HashRW(from,HashKey);
  309.       HashRW(to,HashKey);
  310.       PieceOnSquare(to)=rook;
  311.       if (WhiteCastle(ply+1) > 0) {
  312.         if ((from == 0) && (WhiteCastle(ply+1)&2)) {
  313.           WhiteCastle(ply+1)&=1;
  314.           HashCastleW(1,HashKey);
  315.         }
  316.         else if ((from == 7) && (WhiteCastle(ply+1)&1)) {
  317.           WhiteCastle(ply+1)&=2;
  318.           HashCastleW(0,HashKey);
  319.         }
  320.       }
  321.     }
  322.     else {
  323.       ClearSet(bit_move,BlackRooks);
  324.       ClearSet(bit_move,BlackPieces);
  325.       HashRB(from,HashKey);
  326.       HashRB(to,HashKey);
  327.       PieceOnSquare(to)=-rook;
  328.       if (BlackCastle(ply+1) > 0) {
  329.         if ((from == 56) && (BlackCastle(ply+1)&2)) {
  330.           BlackCastle(ply+1)&=1;
  331.           HashCastleB(1,HashKey);
  332.         }
  333.         else if ((from == 63) && (BlackCastle(ply+1)&1)) {
  334.           BlackCastle(ply+1)&=2;
  335.           HashCastleB(0,HashKey);
  336.         }
  337.       }
  338.     }
  339.     break;
  340. /*
  341. ********************************************************************************
  342. *                                                                              *
  343. *   make queen moves                                                           *
  344. *                                                                              *
  345. ********************************************************************************
  346. */
  347.   case queen:
  348.     ClearSet(bit_move,BishopsQueens);
  349.     ClearSet(bit_move,RooksQueens);
  350.     if (wtm) {
  351.       ClearSet(bit_move,WhiteQueens);
  352.       ClearSet(bit_move,WhitePieces);
  353.       HashQW(from,HashKey);
  354.       HashQW(to,HashKey);
  355.       PieceOnSquare(to)=queen;
  356.     }
  357.     else {
  358.       ClearSet(bit_move,BlackQueens);
  359.       ClearSet(bit_move,BlackPieces);
  360.       HashQB(from,HashKey);
  361.       HashQB(to,HashKey);
  362.       PieceOnSquare(to)=-queen;
  363.     }
  364.     break;
  365. /*
  366. ********************************************************************************
  367. *                                                                              *
  368. *   make king moves.  the only special case is castling, which is indicated    *
  369. *   by from=4, to=6 for o-o as an example.  the king is moving from e1-g1      *
  370. *   which is normally illegal.  in this case, the correct rook is also moved.  *
  371. *                                                                              *
  372. *   note that moving the king in any direction resets the x_castle [x=w or b]  *
  373. *   flag indicating that castling is not possible in *this* position.          *
  374. *                                                                              *
  375. ********************************************************************************
  376. */
  377.   case king:
  378.     if (wtm) {
  379.       ClearSet(bit_move,WhitePieces);
  380.       HashKW(from,HashKey);
  381.       HashKW(to,HashKey);
  382.       PieceOnSquare(to)=king;
  383.       WhiteKingSQ=to;
  384.       if (WhiteCastle(ply) > 0) {
  385.         if (WhiteCastle(ply+1)&2) HashCastleW(1,HashKey);
  386.         if (WhiteCastle(ply+1)&1) HashCastleW(0,HashKey);
  387.         if (abs(to-from) == 2) WhiteCastle(ply+1)=-4;
  388.         else WhiteCastle(ply+1)=0;
  389.         if (abs(to-from) == 2) {
  390.           if (to == G1) {
  391.             from=H1;
  392.             to=F1;
  393.             piece=rook;
  394.             goto MakePieceMove;
  395.           }
  396.           else {
  397.             from=A1;
  398.             to=D1;
  399.             piece=rook;
  400.             goto MakePieceMove;
  401.           }
  402.         }
  403.       }
  404.     }
  405.     else {
  406.       ClearSet(bit_move,BlackPieces);
  407.       HashKB(from,HashKey);
  408.       HashKB(to,HashKey);
  409.       PieceOnSquare(to)=-king;
  410.       BlackKingSQ=to;
  411.       if (BlackCastle(ply+1) > 0) {
  412.         if (BlackCastle(ply+1)&2) HashCastleB(1,HashKey);
  413.         if (BlackCastle(ply+1)&1) HashCastleB(0,HashKey);
  414.         if (abs(to-from) == 2) BlackCastle(ply+1)=-4;
  415.         else BlackCastle(ply+1)=0;
  416.         if (abs(to-from) == 2) {
  417.           if (to == G8) {
  418.             from=H8;
  419.             to=F8;
  420.             piece=rook;
  421.             goto MakePieceMove;
  422.           }
  423.           else {
  424.             from=A8;
  425.             to=D8;
  426.             piece=rook;
  427.             goto MakePieceMove;
  428.           }
  429.         }
  430.       }
  431.     }
  432.     break;
  433.   }
  434. /*
  435. ********************************************************************************
  436. *                                                                              *
  437. *   now it is time to "gracefully" remove a piece from the game board since it *
  438. *   is being captured.  this includes updating the board structure.            *
  439. *                                                                              *
  440. ********************************************************************************
  441. */
  442.   if(captured) {
  443.     Rule50Moves(ply+1)=0;
  444.     TotalPieces--;
  445.     if (promote) piece=promote;
  446.     switch (captured) {
  447. /*
  448.  ----------------------------------------------------------
  449. |                                                          |
  450. |   remove a captured pawn.                                |
  451. |                                                          |
  452.  ----------------------------------------------------------
  453. */
  454.     case pawn: 
  455.       if (wtm) {
  456.         Clear(to,BlackPawns);
  457.         Clear(to,BlackPieces);
  458.         HashPB(to,HashKey);
  459.         HashPB32(to,PawnHashKey);
  460.         Material+=PAWN_VALUE;
  461.         TotalBlackPawns--;
  462.       }
  463.       else {
  464.         Clear(to,WhitePawns);
  465.         Clear(to,WhitePieces);
  466.         HashPW(to,HashKey);
  467.         HashPW32(to,PawnHashKey);
  468.         Material-=PAWN_VALUE;
  469.         TotalWhitePawns--;
  470.       }
  471.     break;
  472. /*
  473.  ----------------------------------------------------------
  474. |                                                          |
  475. |   remove a captured knight.                              |
  476. |                                                          |
  477.  ----------------------------------------------------------
  478. */
  479.     case knight: 
  480.       if (wtm) {
  481.         Clear(to,BlackKnights);
  482.         Clear(to,BlackPieces);
  483.         HashNB(to,HashKey);
  484.         TotalBlackPieces-=knight_v;
  485.         BlackMinors--;
  486.         Material+=KNIGHT_VALUE;
  487.       }
  488.       else {
  489.         Clear(to,WhiteKnights);
  490.         Clear(to,WhitePieces);
  491.         HashNW(to,HashKey);
  492.         TotalWhitePieces-=knight_v;
  493.         WhiteMinors--;
  494.         Material-=KNIGHT_VALUE;
  495.       }
  496.     break;
  497. /*
  498.  ----------------------------------------------------------
  499. |                                                          |
  500. |   remove a captured bishop.                              |
  501. |                                                          |
  502.  ----------------------------------------------------------
  503. */
  504.     case bishop: 
  505.       if (SlidingDiag(piece)) Set(to,BishopsQueens);
  506.       else Clear(to,BishopsQueens);
  507.       if (wtm) {
  508.         Clear(to,BlackBishops);
  509.         Clear(to,BlackPieces);
  510.         HashBB(to,HashKey);
  511.         TotalBlackPieces-=bishop_v;
  512.         BlackMinors--;
  513.         Material+=BISHOP_VALUE;
  514.       }
  515.       else {
  516.         Clear(to,WhiteBishops);
  517.         Clear(to,WhitePieces);
  518.         HashBW(to,HashKey);
  519.         TotalWhitePieces-=bishop_v;
  520.         WhiteMinors--;
  521.         Material-=BISHOP_VALUE;
  522.       }
  523.     break;
  524. /*
  525.  ----------------------------------------------------------
  526. |                                                          |
  527. |   remove a captured rook.                                |
  528. |                                                          |
  529.  ----------------------------------------------------------
  530. */
  531.     case rook: 
  532.       if (SlidingRow(piece)) Set(to,RooksQueens);
  533.       else Clear(to,RooksQueens);
  534.       if (wtm) {
  535.         Clear(to,BlackRooks);
  536.         Clear(to,BlackPieces);
  537.         HashRB(to,HashKey);
  538.         if (BlackCastle(ply) > 0) {
  539.           if ((to == 56) && (BlackCastle(ply+1)&2)) {
  540.             BlackCastle(ply+1)&=1;
  541.             HashCastleB(1,HashKey);
  542.           }
  543.           else if ((to == 63) && (BlackCastle(ply+1)&1)) {
  544.             BlackCastle(ply+1)&=2;
  545.             HashCastleB(0,HashKey);
  546.           }
  547.         }
  548.         TotalBlackPieces-=rook_v;
  549.         BlackMajors--;
  550.         Material+=ROOK_VALUE;
  551.       }
  552.       else {
  553.         Clear(to,WhiteRooks);
  554.         Clear(to,WhitePieces);
  555.         HashRW(to,HashKey);
  556.         if (WhiteCastle(ply) > 0) {
  557.           if ((to == 0) && (WhiteCastle(ply+1)&2)) {
  558.             WhiteCastle(ply+1)&=1;
  559.             HashCastleW(1,HashKey);
  560.           }
  561.           else if ((to == 7) && (WhiteCastle(ply+1)&1)) {
  562.             WhiteCastle(ply+1)&=2;
  563.             HashCastleW(0,HashKey);
  564.           }
  565.         }
  566.         TotalWhitePieces-=rook_v;
  567.         WhiteMajors--;
  568.         Material-=ROOK_VALUE;
  569.       }
  570.     break;
  571. /*
  572.  ----------------------------------------------------------
  573. |                                                          |
  574. |   remove a captured queen.                               |
  575. |                                                          |
  576.  ----------------------------------------------------------
  577. */
  578.     case queen: 
  579.       if (SlidingDiag(piece)) Set(to,BishopsQueens);
  580.       else Clear(to,BishopsQueens);
  581.       if (SlidingRow(piece)) Set(to,RooksQueens);
  582.       else Clear(to,RooksQueens);
  583.       if (wtm) {
  584.         Clear(to,BlackQueens);
  585.         Clear(to,BlackPieces);
  586.         HashQB(to,HashKey);
  587.         TotalBlackPieces-=queen_v;
  588.         BlackMajors-=2;
  589.         Material+=QUEEN_VALUE;
  590.       }
  591.       else {
  592.         Clear(to,WhiteQueens);
  593.         Clear(to,WhitePieces);
  594.         HashQW(to,HashKey);
  595.         TotalWhitePieces-=queen_v;
  596.         WhiteMajors-=2;
  597.         Material-=QUEEN_VALUE;
  598.       }
  599.       break;
  600. /*
  601.  ----------------------------------------------------------
  602. |                                                          |
  603. |   remove a captured king. [this is an error condition]   |
  604. |                                                          |
  605.  ----------------------------------------------------------
  606. */
  607.     case king: 
  608.       Print(128,"captured a king\n");
  609.       Print(128,"piece=%d,from=%d,to=%d,captured=%d\n",
  610.             piece,from,to,captured);
  611.       Print(128,"ply=%d\n",ply);
  612.       if (log_file) DisplayChessBoard(log_file,tree->pos);
  613.     }
  614.   }
  615. #if defined(DEBUG)
  616.   ValidatePosition(tree,ply+1,move,"MakeMove(2)");
  617. #endif
  618.   return;
  619. }
  620. /*
  621. ********************************************************************************
  622. *                                                                              *
  623. *   MakeMoveRoot() is used to make a move at the root of the game tree,        *
  624. *   before any searching is done.  it uses MakeMove() to execute the move,      *
  625. *   but then copies the resulting position back to position[0], the actual     *
  626. *   board position.  it handles the special-case of the draw-by-repetition     *
  627. *   rule by maintaining a list of previous positions, which is reset each time *
  628. *   a non-reversible (pawn move or capture move) is made.                      *
  629. *                                                                              *
  630. ********************************************************************************
  631. */
  632. void MakeMoveRoot(TREE *tree, int move, int wtm)
  633. {
  634. /*
  635.  ----------------------------------------------------------
  636. |                                                          |
  637. |   first, make the move and replace position[0] with the  |
  638. |   new position.                                          |
  639. |                                                          |
  640.  ----------------------------------------------------------
  641. */
  642.   MakeMove(tree, 0,move,wtm);
  643. /*
  644.  ----------------------------------------------------------
  645. |                                                          |
  646. |   now, if this is a non-reversible move, reset the       |
  647. |   repetition list pointer to start the count over.       |
  648. |                                                          |
  649.  ----------------------------------------------------------
  650. */
  651.   if (Rule50Moves(1) == 0) {
  652.     tree->rephead_b=tree->replist_b;
  653.     tree->rephead_w=tree->replist_w;
  654.   }
  655.   WhiteCastle(1)=Max(0,WhiteCastle(1));
  656.   BlackCastle(1)=Max(0,BlackCastle(1));
  657.   tree->position[0]=tree->position[1];
  658.   if (ChangeSide(wtm))
  659.     *tree->rephead_w++=HashKey;
  660.   else
  661.     *tree->rephead_b++=HashKey;
  662. }
  663.