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

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "chess.h"
  4. #include "data.h"
  5.  
  6. void ValidatePosition(TREE *tree, int ply, int move, char *caller)
  7. {
  8.   BITBOARD temp, temp_occ, temp_occ_rl90, temp_occ_rl45;
  9.   BITBOARD temp_occ_rr45, temp_occx, cattacks, rattacks;
  10.   unsigned int temp1;
  11.   int i,square,error;
  12.   int temp_score;
  13. /*
  14.   first, test w_occupied and b_occupied
  15. */
  16.   error=0;
  17.   temp_occ=Or(Or(Or(Or(Or(WhitePawns,WhiteKnights),WhiteBishops),
  18.                     WhiteRooks),WhiteQueens),WhiteKing);
  19.   if(Xor(WhitePieces,temp_occ)) {
  20.     Print(128,"ERROR white occupied squares is bad!\n");
  21.     Display2BitBoards(temp_occ,WhitePieces);
  22.     error=1;
  23.   }
  24.   temp_occ=Or(Or(Or(Or(Or(BlackPawns,BlackKnights),BlackBishops),
  25.                     BlackRooks),BlackQueens),BlackKing);
  26.   if(Xor(BlackPieces,temp_occ)) {
  27.     Print(128,"ERROR black occupied squares is bad!\n");
  28.     Display2BitBoards(temp_occ,BlackPieces);
  29.     error=1;
  30.   }
  31. /*
  32.   now test rotated occupied bitboards.
  33. */
  34.   temp_occ_rl90=0;
  35.   temp_occ_rl45=0;
  36.   temp_occ_rr45=0;
  37.   for (i=0;i<64;i++) {
  38.     if (PieceOnSquare(i)) {
  39.       temp_occ_rl90=Or(temp_occ_rl90,set_mask_rl90[i]);
  40.       temp_occ_rl45=Or(temp_occ_rl45,set_mask_rl45[i]);
  41.       temp_occ_rr45=Or(temp_occ_rr45,set_mask_rr45[i]);
  42.     }
  43.   }
  44.   if(Xor(OccupiedRL90,temp_occ_rl90)) {
  45.     Print(128,"ERROR occupied squares (rotated left 90) is bad!\n");
  46.     Display2BitBoards(temp_occ_rl90,OccupiedRL90);
  47.     error=1;
  48.   }
  49.   if(Xor(OccupiedRL45,temp_occ_rl45)) {
  50.     Print(128,"ERROR occupied squares (rotated left 45) is bad!\n");
  51.     Display2BitBoards(temp_occ_rl45,OccupiedRL45);
  52.     error=1;
  53.   }
  54.   if(Xor(OccupiedRR45,temp_occ_rr45)) {
  55.     Print(128,"ERROR occupied squares (rotated right 45) is bad!\n");
  56.     Display2BitBoards(temp_occ_rr45,OccupiedRR45);
  57.     error=1;
  58.   }
  59. /*
  60.   now test bishops_queens and rooks_queens
  61. */
  62.   temp_occ=Or(Or(Or(WhiteBishops,WhiteQueens),BlackBishops),
  63.               BlackQueens);
  64.   if(Xor(BishopsQueens,temp_occ)) {
  65.     Print(128,"ERROR bishops_queens is bad!\n");
  66.     Display2BitBoards(temp_occ,BishopsQueens);
  67.     error=1;
  68.   }
  69.     temp_occ=Or(Or(Or(WhiteRooks,WhiteQueens),BlackRooks),
  70.                 BlackQueens);
  71.   if(Xor(RooksQueens,temp_occ)) {
  72.     Print(128,"ERROR rooks_queens is bad!\n");
  73.     Display2BitBoards(temp_occ,RooksQueens);
  74.     error=1;
  75.   }
  76. /*
  77.   check individual piece bit-boards to make sure two pieces
  78.   don't occupy the same square (bit)
  79. */
  80.     temp_occ=Xor(Xor(Xor(Xor(Xor(Xor(Xor(Xor(Xor(Xor(Xor(
  81.        WhitePawns,WhiteKnights),WhiteBishops),WhiteRooks),
  82.        WhiteQueens),BlackPawns),BlackKnights),BlackBishops),
  83.        BlackRooks),BlackQueens),WhiteKing),BlackKing);
  84.     temp_occx=Or(Or(Or(Or(Or(Or(Or(Or(Or(Or(Or(
  85.        WhitePawns,WhiteKnights),WhiteBishops),WhiteRooks),
  86.        WhiteQueens),BlackPawns),BlackKnights),BlackBishops),
  87.        BlackRooks),BlackQueens),WhiteKing),BlackKing);
  88.     if(Xor(temp_occ,temp_occx)) {
  89.       Print(128,"ERROR two pieces on same square\n");
  90.       error=1;
  91.     }
  92. /*
  93.   test material_evaluation
  94. */
  95.   temp_score=PopCnt(WhitePawns)*PAWN_VALUE;
  96.   temp_score-=PopCnt(BlackPawns)*PAWN_VALUE;
  97.   temp_score+=PopCnt(WhiteKnights)*KNIGHT_VALUE;
  98.   temp_score-=PopCnt(BlackKnights)*KNIGHT_VALUE;
  99.   temp_score+=PopCnt(WhiteBishops)*BISHOP_VALUE;
  100.   temp_score-=PopCnt(BlackBishops)*BISHOP_VALUE;
  101.   temp_score+=PopCnt(WhiteRooks)*ROOK_VALUE;
  102.   temp_score-=PopCnt(BlackRooks)*ROOK_VALUE;
  103.   temp_score+=PopCnt(WhiteQueens)*QUEEN_VALUE;
  104.   temp_score-=PopCnt(BlackQueens)*QUEEN_VALUE;
  105.   if(temp_score != Material) {
  106.     Print(128,"ERROR  material_evaluation is wrong, good=%d, bad=%d\n",
  107.            temp_score,Material);
  108.     error=1;
  109.   }
  110.   temp_score=PopCnt(WhiteKnights)*knight_v;
  111.   temp_score+=PopCnt(WhiteBishops)*bishop_v;
  112.   temp_score+=PopCnt(WhiteRooks)*rook_v;
  113.   temp_score+=PopCnt(WhiteQueens)*queen_v;
  114.   if(temp_score != TotalWhitePieces) {
  115.     Print(128,"ERROR  white_pieces is wrong, good=%d, bad=%d\n",
  116.            temp_score,TotalWhitePieces);
  117.     error=1;
  118.   }
  119.   temp_score=PopCnt(WhiteKnights);
  120.   temp_score+=PopCnt(WhiteBishops);
  121.   if(temp_score != WhiteMinors) {
  122.     Print(128,"ERROR  white_minors is wrong, good=%d, bad=%d\n",
  123.            temp_score,WhiteMinors);
  124.     error=1;
  125.   }
  126.   temp_score=PopCnt(WhiteRooks);
  127.   temp_score+=PopCnt(WhiteQueens)*2;
  128.   if(temp_score != WhiteMajors) {
  129.     Print(128,"ERROR  white_majors is wrong, good=%d, bad=%d\n",
  130.            temp_score,WhiteMajors);
  131.     error=1;
  132.   }
  133.   temp_score=PopCnt(WhitePawns);
  134.   if(temp_score != TotalWhitePawns) {
  135.     Print(128,"ERROR  white_pawns is wrong, good=%d, bad=%d\n",
  136.            temp_score,TotalWhitePawns);
  137.     error=1;
  138.   }
  139.   temp_score=PopCnt(BlackKnights)*knight_v;
  140.   temp_score+=PopCnt(BlackBishops)*bishop_v;
  141.   temp_score+=PopCnt(BlackRooks)*rook_v;
  142.   temp_score+=PopCnt(BlackQueens)*queen_v;
  143.   if(temp_score != TotalBlackPieces) {
  144.     Print(128,"ERROR  black_pieces is wrong, good=%d, bad=%d\n",
  145.            temp_score,TotalBlackPieces);
  146.     error=1;
  147.   }
  148.   temp_score=PopCnt(BlackKnights);
  149.   temp_score+=PopCnt(BlackBishops);
  150.   if(temp_score != BlackMinors) {
  151.     Print(128,"ERROR  black_minors is wrong, good=%d, bad=%d\n",
  152.            temp_score,BlackMinors);
  153.     error=1;
  154.   }
  155.   temp_score=PopCnt(BlackRooks);
  156.   temp_score+=PopCnt(BlackQueens)*2;
  157.   if(temp_score != BlackMajors) {
  158.     Print(128,"ERROR  black_majors is wrong, good=%d, bad=%d\n",
  159.            temp_score,BlackMajors);
  160.     error=1;
  161.   }
  162.   temp_score=PopCnt(BlackPawns);
  163.   if(temp_score != TotalBlackPawns) {
  164.     Print(128,"ERROR  black_pawns is wrong, good=%d, bad=%d\n",
  165.            temp_score,TotalBlackPawns);
  166.     error=1;
  167.   }
  168. /*
  169.   now test the board[...] to make sure piece values are correct.
  170. */
  171. /*
  172.    test pawn locations
  173. */
  174.   temp=WhitePawns;
  175.   while(temp) {
  176.     square=FirstOne(temp);
  177.     if (PieceOnSquare(square) != pawn) {
  178.       Print(128,"ERROR!  board[%d]=%d, should be 1\n",square,
  179.             PieceOnSquare(square));
  180.       error=1;
  181.     }
  182.     Clear(square,temp);
  183.   }
  184.   temp=BlackPawns;
  185.   while(temp) {
  186.     square=FirstOne(temp);
  187.     if (PieceOnSquare(square) != -pawn) {
  188.       Print(128,"ERROR!  board[%d]=%d, should be -1\n",square,
  189.             PieceOnSquare(square));
  190.       error=1;
  191.     }
  192.     Clear(square,temp);
  193.   }
  194. /*
  195.    test knight locations
  196. */
  197.   temp=WhiteKnights;
  198.   while(temp) {
  199.     square=FirstOne(temp);
  200.     if (PieceOnSquare(square) != knight) {
  201.       Print(128,"ERROR!  board[%d]=%d, should be 2\n",square,
  202.             PieceOnSquare(square));
  203.       error=1;
  204.     }
  205.     Clear(square,temp);
  206.   }
  207.   temp=BlackKnights;
  208.   while(temp) {
  209.     square=FirstOne(temp);
  210.     if (PieceOnSquare(square) != -knight) {
  211.       Print(128,"ERROR!  board[%d]=%d, should be -2\n",square,
  212.             PieceOnSquare(square));
  213.       error=1;
  214.     }
  215.     Clear(square,temp);
  216.   }
  217. /*
  218.    test bishop locations
  219. */
  220.   temp=WhiteBishops;
  221.   while(temp) {
  222.     square=FirstOne(temp);
  223.     if (PieceOnSquare(square) != bishop) {
  224.       Print(128,"ERROR!  board[%d]=%d, should be 3\n",square,
  225.             PieceOnSquare(square));
  226.       error=1;
  227.     }
  228.     rattacks=AttacksBishop(square);
  229.     cattacks=ValidateComputeBishopAttacks(tree,square);
  230.     if (rattacks != cattacks) {
  231.       Print(128,"ERROR!  bishop attacks wrong, square=%d\n",square);
  232.       Display2BitBoards(cattacks,rattacks);
  233.       error=1;
  234.     }
  235.     Clear(square,temp);
  236.   }
  237.   temp=BlackBishops;
  238.   while(temp) {
  239.     square=FirstOne(temp);
  240.     if (PieceOnSquare(square) != -bishop) {
  241.       Print(128,"ERROR!  board[%d]=%d, should be -3\n",square,
  242.             PieceOnSquare(square));
  243.       error=1;
  244.     }
  245.     rattacks=AttacksBishop(square);
  246.     cattacks=ValidateComputeBishopAttacks(tree,square);
  247.     if (rattacks != cattacks) {
  248.       Print(128,"ERROR!  bishop attacks wrong, square=%d\n",square);
  249.       Display2BitBoards(cattacks,rattacks);
  250.       error=1;
  251.     }
  252.     Clear(square,temp);
  253.   }
  254. /*
  255.    test rook locations
  256. */
  257.   temp=WhiteRooks;
  258.   while(temp) {
  259.     square=FirstOne(temp);
  260.     if (PieceOnSquare(square) != rook) {
  261.       Print(128,"ERROR!  board[%d]=%d, should be 4\n",square,
  262.             PieceOnSquare(square));
  263.       error=1;
  264.     }
  265.     rattacks=AttacksRook(square);
  266.     cattacks=ValidateComputeRookAttacks(tree,square);
  267.     if (rattacks != cattacks) {
  268.       Print(128,"ERROR!  Rook attacks wrong, square=%d\n",square);
  269.       Display2BitBoards(cattacks,rattacks);
  270.       error=1;
  271.     }
  272.     Clear(square,temp);
  273.   }
  274.   temp=BlackRooks;
  275.   while(temp) {
  276.     square=FirstOne(temp);
  277.     if (PieceOnSquare(square) != -rook) {
  278.       Print(128,"ERROR!  board[%d]=%d, should be -4\n",square,
  279.             PieceOnSquare(square));
  280.       error=1;
  281.     }
  282.     rattacks=AttacksRook(square);
  283.     cattacks=ValidateComputeRookAttacks(tree,square);
  284.     if (rattacks != cattacks) {
  285.       Print(128,"ERROR!  Rook attacks wrong, square=%d\n",square);
  286.       Display2BitBoards(cattacks,rattacks);
  287.       error=1;
  288.     }
  289.     Clear(square,temp);
  290.   }
  291. /*
  292.    test queen locations
  293. */
  294.   temp=WhiteQueens;
  295.   while(temp) {
  296.     square=FirstOne(temp);
  297.     if (PieceOnSquare(square) != queen) {
  298.       Print(128,"ERROR!  board[%d]=%d, should be 5\n",square,
  299.             PieceOnSquare(square));
  300.       error=1;
  301.     }
  302.     rattacks=AttacksQueen(square);
  303.     cattacks=Or(ValidateComputeRookAttacks(tree,square),ValidateComputeBishopAttacks(tree,square));
  304.     if (rattacks != cattacks) {
  305.       Print(128,"ERROR!  queen attacks wrong, square=%d\n",square);
  306.       Display2BitBoards(cattacks,rattacks);
  307.       error=1;
  308.     }
  309.     Clear(square,temp);
  310.   }
  311.   temp=BlackQueens;
  312.   while(temp) {
  313.     square=FirstOne(temp);
  314.     if (PieceOnSquare(square) != -queen) {
  315.       Print(128,"ERROR!  board[%d]=%d, should be -5\n",square,
  316.             PieceOnSquare(square));
  317.       error=1;
  318.     }
  319.     rattacks=AttacksQueen(square);
  320.     cattacks=Or(ValidateComputeRookAttacks(tree,square),ValidateComputeBishopAttacks(tree,square));
  321.     if (rattacks != cattacks) {
  322.       Print(128,"ERROR!  queen attacks wrong, square=%d\n",square);
  323.       Display2BitBoards(cattacks,rattacks);
  324.       error=1;
  325.     }
  326.     Clear(square,temp);
  327.   }
  328. /*
  329.    test king locations
  330. */
  331.   temp=WhiteKing;
  332.   while(temp) {
  333.     square=FirstOne(temp);
  334.     if (PieceOnSquare(square) != king) {
  335.       Print(128,"ERROR!  board[%d]=%d, should be 6\n",square,
  336.             PieceOnSquare(square));
  337.       error=1;
  338.     }
  339.     if (WhiteKingSQ != square) {
  340.       Print(128,"ERROR!  white_king is %d, should be %d\n",
  341.             WhiteKingSQ,square);
  342.       error=1;
  343.     }
  344.     Clear(square,temp);
  345.   }
  346.   temp=BlackKing;
  347.   while(temp) {
  348.     square=FirstOne(temp);
  349.     if (PieceOnSquare(square) != -king) {
  350.       Print(128,"ERROR!  board[%d]=%d, should be -6\n",square,
  351.             PieceOnSquare(square));
  352.       error=1;
  353.     }
  354.     if (BlackKingSQ != square) {
  355.       Print(128,"ERROR!  black_king is %d, should be %d\n",
  356.             BlackKingSQ,square);
  357.       error=1;
  358.     }
  359.     Clear(square,temp);
  360.   }
  361. /*
  362.    test board[i] fully now.
  363. */
  364.   for (i=0;i<64;i++)
  365.   switch (PieceOnSquare(i)) {
  366.     case -king:
  367.       if (!And(BlackKing,set_mask[i])) {
  368.         Print(128,"ERROR!  b_king/board[%d] don't agree!\n",i);
  369.         error=1;
  370.       }
  371.       break;
  372.     case -queen:
  373.       if (!And(BlackQueens,set_mask[i])) {
  374.         Print(128,"ERROR!  b_queen/board[%d] don't agree!\n",i);
  375.         error=1;
  376.       }
  377.       break;
  378.     case -rook:
  379.       if (!And(BlackRooks,set_mask[i])) {
  380.         Print(128,"ERROR!  b_rook/board[%d] don't agree!\n",i);
  381.         error=1;
  382.       }
  383.       break;
  384.     case -bishop:
  385.       if (!And(BlackBishops,set_mask[i])) {
  386.         Print(128,"ERROR!  b_bishop/board[%d] don't agree!\n",i);
  387.         error=1;
  388.       }
  389.       break;
  390.     case -knight:
  391.       if (!And(BlackKnights,set_mask[i])) {
  392.         Print(128,"ERROR!  b_knight/board[%d] don't agree!\n",i);
  393.         error=1;
  394.       }
  395.       break;
  396.     case -pawn:
  397.       if (!And(BlackPawns,set_mask[i])) {
  398.         Print(128,"ERROR!  b_pawn/board[%d] don't agree!\n",i);
  399.         error=1;
  400.       }
  401.       break;
  402.     case king:
  403.       if (!And(WhiteKing,set_mask[i])) {
  404.         Print(128,"ERROR!  w_king/board[%d] don't agree!\n",i);
  405.         error=1;
  406.       }
  407.       break;
  408.     case queen:
  409.       if (!And(WhiteQueens,set_mask[i])) {
  410.         Print(128,"ERROR!  w_queen/board[%d] don't agree!\n",i);
  411.         error=1;
  412.       }
  413.       break;
  414.     case rook:
  415.       if (!And(WhiteRooks,set_mask[i])) {
  416.         Print(128,"ERROR!  w_rook/board[%d] don't agree!\n",i);
  417.         error=1;
  418.       }
  419.       break;
  420.     case bishop:
  421.       if (!And(WhiteBishops,set_mask[i])) {
  422.         Print(128,"ERROR!  w_bishop/board[%d] don't agree!\n",i);
  423.         error=1;
  424.       }
  425.       break;
  426.     case knight:
  427.       if (!And(WhiteKnights,set_mask[i])) {
  428.         Print(128,"ERROR!  w_knight/board[%d] don't agree!\n",i);
  429.         error=1;
  430.       }
  431.       break;
  432.     case pawn:
  433.       if (!And(WhitePawns,set_mask[i])) {
  434.         Print(128,"ERROR!  w_pawn/board[%d] don't agree!\n",i);
  435.         error=1;
  436.       }
  437.       break;
  438.   }
  439. /*
  440.    test empty squares now
  441. */
  442.   temp=Compl(Or(temp_occ,temp_occx));
  443.   while(temp) {
  444.     square=FirstOne(temp);
  445.     if (PieceOnSquare(square)) {
  446.       Print(128,"ERROR!  board[%d]=%d, should be 0\n",square,
  447.             PieceOnSquare(square));
  448.       error=1;
  449.     }
  450.     Clear(square,temp);
  451.   }
  452. /*
  453.    test total piece count now
  454. */
  455.   i=PopCnt(Occupied);
  456.   if (i != TotalPieces) {
  457.     Print(128,"ERROR!  TotalPieces is wrong, correct=%d  bad=%d\n",
  458.           i,TotalPieces);
  459.     error=1;
  460.   }
  461. /*
  462.    test hash key
  463. */
  464.   temp=0;
  465.   temp1=0;
  466.   for (i=0;i<64;i++) {
  467.     switch (PieceOnSquare(i)) {
  468.       case king:
  469.         temp=Xor(temp,w_king_random[i]);
  470.         break;
  471.       case queen:
  472.         temp=Xor(temp,w_queen_random[i]);
  473.         break;
  474.       case rook:
  475.         temp=Xor(temp,w_rook_random[i]);
  476.         break;
  477.       case bishop:
  478.         temp=Xor(temp,w_bishop_random[i]);
  479.         break;
  480.       case knight:
  481.         temp=Xor(temp,w_knight_random[i]);
  482.         break;
  483.       case pawn:
  484.         temp=Xor(temp,w_pawn_random[i]);
  485.         temp1=temp1^w_pawn_random32[i];
  486.         break;
  487.       case -pawn:
  488.         temp=Xor(temp,b_pawn_random[i]);
  489.         temp1=temp1^b_pawn_random32[i];
  490.         break;
  491.       case -knight:
  492.         temp=Xor(temp,b_knight_random[i]);
  493.         break;
  494.       case -bishop:
  495.         temp=Xor(temp,b_bishop_random[i]);
  496.         break;
  497.       case -rook:
  498.         temp=Xor(temp,b_rook_random[i]);
  499.         break;
  500.       case -queen:
  501.         temp=Xor(temp,b_queen_random[i]);
  502.         break;
  503.       case -king:
  504.         temp=Xor(temp,b_king_random[i]);
  505.         break;
  506.       default:
  507.         break;
  508.     }
  509.   }
  510.   if (EnPassant(ply)) HashEP(EnPassant(ply),temp);
  511.   if (!(WhiteCastle(ply)&1)) HashCastleW(0,temp);
  512.   if (!(WhiteCastle(ply)&2)) HashCastleW(1,temp);
  513.   if (!(BlackCastle(ply)&1)) HashCastleB(0,temp);
  514.   if (!(BlackCastle(ply)&2)) HashCastleB(1,temp);
  515.   if(Xor(temp,HashKey)) {
  516.     Print(128,"ERROR!  hash_key is bad.\n");
  517.     error=1;
  518.   }
  519.   if(temp1^PawnHashKey) {
  520.     Print(128,"ERROR!  pawn_hash_key is bad.\n");
  521.     error=1;
  522.   }
  523.   if (error) {
  524.     Print(4095,"processor id: cpu-%d\n",tree->thread_id);
  525.     Print(4095,"current move:\n");
  526.     DisplayChessMove("move=",move);
  527.     DisplayChessBoard(stdout,tree->pos);
  528.     Print(4095,"called from %s, ply=%d\n",caller,ply);
  529.     Print(4095,"node=%d\n",tree->nodes_searched);
  530.     Print(4095,"active path:\n");
  531.     for (i=1;i<=ply;i++)
  532.       DisplayChessMove("move=",move);
  533.     exit(1);
  534.   }
  535. }
  536.  
  537. BITBOARD ValidateComputeBishopAttacks(TREE *tree, int square)
  538. {
  539.   BITBOARD attacks, temp_attacks;
  540.   BITBOARD temp7, temp9;
  541.   attacks=bishop_attacks[square];
  542.   temp_attacks=And(attacks,Compl(Occupied));
  543.   temp_attacks=Compl(Or(temp_attacks,Compl(bishop_attacks[square])));
  544.   temp7=And(temp_attacks,plus7dir[square]);
  545.   temp9=And(temp_attacks,plus9dir[square]);
  546.   attacks=Xor(attacks,plus7dir[FirstOne(temp7)]);
  547.   attacks=Xor(attacks,plus9dir[FirstOne(temp9)]);
  548.   temp7=And(temp_attacks,minus7dir[square]);
  549.   temp9=And(temp_attacks,minus9dir[square]);
  550.   attacks=Xor(attacks,minus7dir[LastOne(temp7)]);
  551.   attacks=Xor(attacks,minus9dir[LastOne(temp9)]);
  552.   return(attacks);
  553. }
  554.  
  555. BITBOARD ValidateComputeRookAttacks(TREE *tree, int square)
  556. {
  557.   BITBOARD attacks, temp_attacks;
  558.   BITBOARD temp1, temp8;
  559.   attacks=rook_attacks[square];
  560.   temp_attacks=And(attacks,Compl(Occupied));
  561.   temp_attacks=Compl(Or(temp_attacks,Compl(rook_attacks[square])));
  562.   temp1=And(temp_attacks,plus1dir[square]);
  563.   temp8=And(temp_attacks,plus8dir[square]);
  564.   attacks=Xor(attacks,plus1dir[FirstOne(temp1)]);
  565.   attacks=Xor(attacks,plus8dir[FirstOne(temp8)]);
  566.   temp1=And(temp_attacks,minus1dir[square]);
  567.   temp8=And(temp_attacks,minus8dir[square]);
  568.   attacks=Xor(attacks,minus1dir[LastOne(temp1)]);
  569.   attacks=Xor(attacks,minus8dir[LastOne(temp8)]);
  570.   return(attacks);
  571. }
  572.