Home Previous Bottom Next

Writing a chess program in 99 steps


step 51: data.cpp

#include <iostream>
#include <iomanip>
#include "defines.h"
#include "protos.h"
#include "extglobals.h"
 
void dataInit()
{
       unsigned char CHARBITSET[8];
       int i, square, rank, file, arank, afile, state, slide, diaga1h8, diaga8h1, attackbit;
       unsigned char state6Bit, state8Bit, attack8Bit;
       Move move;
 
//     ===========================================================================
//     BITSET has only one bit set:
//     ===========================================================================
       BITSET[0] = 0x1;
       for (i = 1; i < 64 ; i++)
       {
                     BITSET[i] = BITSET[i-1] << 1;
       }
 
//     ===========================================================================
//     BOARDINDEX is used to translate [file][rank] to [square],
//  Note that file is from 1..8 and rank from 1..8 (not starting from 0)
//     ===========================================================================
       for (rank = 0 ; rank < 9; rank++)
       {
              for (file = 0 ; file < 9; file++)
              {
                     BOARDINDEX[file][rank] = (rank-1) * 8 + file - 1;
              }
       }
 
//     ===========================================================================
//     Initialize the board
//     ===========================================================================
       board.init();
 
//     ===========================================================================
//     Initialize MS1BTABLE, used in lastOne (see bitops.cpp)
//     ===========================================================================
    for (i = 0; i < 256; i++)
    {
        MS1BTABLE[i] = (
            (i > 127) ? 7 :
            (i >  63) ? 6 :
            (i >  31) ? 5 :
            (i >  15) ? 4 :
            (i >   7) ? 3 :
            (i >   3) ? 2 :
            (i >   1) ? 1 : 0 );
    }
 
//     ===========================================================================
//     Initialize rank, file and diagonal 6-bit masking bitmaps, to get the
//  occupancy state, used in the movegenerator (see movegen.ccp)
//     ===========================================================================
 
       for (square = 0; square < 64; square++)
       {
              RANKMASK[square] = 0x0;
              FILEMASK[square] = 0x0;
              DIAGA8H1MASK[square] = 0x0;
              DIAGA1H8MASK[square] = 0x0;
              FILEMAGIC[square] = 0x0;
              DIAGA8H1MAGIC[square] = 0x0;
              DIAGA1H8MAGIC[square] = 0x0;
       }
 
       for (file = 1; file < 9; file++)
       {
              for (rank = 1; rank < 9; rank++)
              {
//             ===========================================================================
//             initialize 6-bit rank mask, used in the movegenerator (see movegen.ccp)
//             ===========================================================================
 
                     RANKMASK[BOARDINDEX[file][rank]]  = BITSET[BOARDINDEX[2][rank]] | BITSET[BOARDINDEX[3][rank]] | BITSET[BOARDINDEX[4][rank]] ;
                     RANKMASK[BOARDINDEX[file][rank]] |= BITSET[BOARDINDEX[5][rank]] | BITSET[BOARDINDEX[6][rank]] | BITSET[BOARDINDEX[7][rank]] ;
 
//             ===========================================================================
//             initialize 6-bit file mask, used in the movegenerator (see movegen.ccp)
//             ===========================================================================
                     FILEMASK[BOARDINDEX[file][rank]]  = BITSET[BOARDINDEX[file][2]] | BITSET[BOARDINDEX[file][3]] | BITSET[BOARDINDEX[file][4]] ;
                     FILEMASK[BOARDINDEX[file][rank]] |= BITSET[BOARDINDEX[file][5]] | BITSET[BOARDINDEX[file][6]] | BITSET[BOARDINDEX[file][7]] ;
 
//             ===========================================================================
//             Initialize diagonal magic multiplication numbers, used in the movegenerator (see movegen.ccp)
//             ===========================================================================
                     diaga8h1 = file + rank; // from 2 to 16, longest diagonal = 9
                     DIAGA8H1MAGIC[BOARDINDEX[file][rank]] = _DIAGA8H1MAGICS[diaga8h1 - 2];
 
//             ===========================================================================
//             Initialize 6-bit diagonal mask, used in the movegenerator (see movegen.ccp)
//             ===========================================================================
                     DIAGA8H1MASK[BOARDINDEX[file][rank]] = 0x0;
                     if (diaga8h1 < 10)  // lower half, diagonals 2 to 9
                     {
                           for (square = 2 ; square < diaga8h1-1 ; square ++)
                           {
                                  DIAGA8H1MASK[BOARDINDEX[file][rank]] |= BITSET[BOARDINDEX[square][diaga8h1-square]];
                           }
                     }
                     else  // upper half, diagonals 10 to 16
                     {
                           for (square = 2 ; square < 17 - diaga8h1 ; square ++)
                           {
                                  DIAGA8H1MASK[BOARDINDEX[file][rank]] |= BITSET[BOARDINDEX[diaga8h1+square-9][9-square]];
                           }
                     }
      
//             ===========================================================================
//             Initialize diagonal magic multiplication numbers, used in the movegenerator (see movegen.ccp)
//             ===========================================================================
                     diaga1h8 = file - rank; // from -7 to +7, longest diagonal = 0
                     DIAGA1H8MAGIC[BOARDINDEX[file][rank]] = _DIAGA1H8MAGICS[diaga1h8+7];
 
//             ===========================================================================
//             Initialize 6-bit diagonal mask, used in the movegenerator (see movegen.ccp)
//             ===========================================================================
                     DIAGA1H8MASK[BOARDINDEX[file][rank]] = 0x0;
                     if (diaga1h8 > -1)  // lower half, diagonals 0 to 7
                     {
                           for (square = 2 ; square < 8 - diaga1h8 ; square ++)
                           {
                                  DIAGA1H8MASK[BOARDINDEX[file][rank]] |= BITSET[BOARDINDEX[diaga1h8 + square][square]];
                           }
                     }
                     else
                     {
                           for (square = 2 ; square < 8 + diaga1h8 ; square ++)
                           {
                                  DIAGA1H8MASK[BOARDINDEX[file][rank]] |= BITSET[BOARDINDEX[square][square - diaga1h8]];
                           }
                     }
 
//             ===========================================================================
//             Initialize file magic multiplication numbers, used in the movegenerator (see movegen.ccp)
//             ===========================================================================
                     FILEMAGIC[BOARDINDEX[file][rank]] = _FILEMAGICS[file-1];
 
              }
       }
 
//     ===========================================================================
//     Now initialize the GEN_SLIDING_ATTACKS array, used to generate the sliding
//  attack bitboards.
//  unsigned char GEN_SLIDING_ATTACKS[8 squares][64 states] holds the attacks
//  for any file, rank or diagonal - it is going to be usefull when generating the
//  RANK_ATTACKS[64][64], FILE_ATTACKS[64][64], DIAGA8H1_ATTACKS[64][64] and
//  DIAGA1H8_ATTACKS[64][64] arrays
//     ===========================================================================
 
       // initialize CHARBITSET, this array is equivalant to BITSET for bitboards:
       // 8 chars, each with only 1 bit set.
       CHARBITSET[0] = 1;
       for (square = 1; square <= 7; square++) 
       {
              CHARBITSET[square] = CHARBITSET[square-1] << 1;
       }
 
       // loop over rank, file or diagonal squares:
       for (square = 0; square <= 7; square++)
       {
              // loop of occupancy states
              // state6Bit represents the 64 possible occupancy states of a rank,
              // except the 2 end-bits, because they don't matter for calculating attacks
              for (state6Bit = 0; state6Bit < 64; state6Bit++)      
              {
                     state8Bit = state6Bit << 1; // create an 8-bit occupancy state
                     attack8Bit = 0;
                     if (square < 7)
                     {
                           attack8Bit |= CHARBITSET[square + 1];
                     }
                     slide = square + 2;
                     while (slide <= 7) // slide in '+' direction
                     {
                           if ((~state8Bit) & (CHARBITSET[slide - 1]))
                           {
                                  attack8Bit |= CHARBITSET[slide];
                           }
                           else break;
                           slide++;
                     }
                     if (square > 0)
                     {
                           attack8Bit |= CHARBITSET[square - 1];
                     }
                     slide = square - 2;
                     while (slide >= 0) // slide in '-' direction
                     {
                           if ((~state8Bit) & (CHARBITSET[slide + 1]))
                           {
                                  attack8Bit |= CHARBITSET[slide];
                           }
                           else break;
                           slide--;
                     }
                     GEN_SLIDING_ATTACKS[square][state6Bit] = attack8Bit;
              }
       }
 
//     ===========================================================================
//     Initialize all attack bitmaps, used in the movegenerator (see movegen.ccp)
//     ===========================================================================
 
       for (square = 0; square < 64; square++)
       {
              KNIGHT_ATTACKS[square] = 0x0;
              KING_ATTACKS[square] = 0x0;
              WHITE_PAWN_ATTACKS[square] = 0x0;
              WHITE_PAWN_MOVES[square] = 0x0;
              WHITE_PAWN_DOUBLE_MOVES[square] = 0x0;
              BLACK_PAWN_ATTACKS[square] = 0x0;
              BLACK_PAWN_MOVES[square] = 0x0;
              BLACK_PAWN_DOUBLE_MOVES[square] = 0x0;   
              for (state = 0; state < 64; state++)
              {
                     RANK_ATTACKS[square][state] = 0x0;
                     FILE_ATTACKS[square][state] = 0x0;
                     DIAGA8H1_ATTACKS[square][state] = 0x0;
                     DIAGA1H8_ATTACKS[square][state] = 0x0;
              }
       }
 
       // WHITE_PAWN_ATTACKS
       for (square = 0; square < 64; square++)
       {
              file = FILES[square]; rank = RANKS[square];
              afile = file - 1; arank = rank + 1;
              if ((afile >= 1) & (afile <= 8) & (arank >= 1) & (arank <= 8))
                     WHITE_PAWN_ATTACKS[square] |= BITSET[BOARDINDEX[afile][arank]];
              afile = file + 1; arank = rank + 1;
              if ((afile >= 1) & (afile <= 8) & (arank >= 1) & (arank <= 8))
                     WHITE_PAWN_ATTACKS[square] |= BITSET[BOARDINDEX[afile][arank]];
       }
 
       // WHITE_PAWN_MOVES
       for (square = 0; square <64; square++)
       {
              file = FILES[square]; rank = RANKS[square];
              afile = file; arank = rank + 1;
              if ((afile >= 1) & (afile <= 8) & (arank >= 1) & (arank <= 8))
                     WHITE_PAWN_MOVES[square] |= BITSET[BOARDINDEX[afile][arank]];       
              if (rank == 2)
              {
                     afile = file; arank = rank + 2;
                     if ((afile >= 1) & (afile <= 8) & (arank >= 1) & (arank <= 8))
                           WHITE_PAWN_DOUBLE_MOVES[square] |= BITSET[BOARDINDEX[afile][arank]];
              }
       }
 
       // BLACK_PAWN_ATTACKS
       for (square = 0; square < 64; square++)
       {
              file = FILES[square]; rank = RANKS[square];
              afile = file - 1; arank = rank - 1;
              if ((afile >= 1) & (afile <= 8) & (arank >= 1) & (arank <= 8))
                     BLACK_PAWN_ATTACKS[square] |= BITSET[BOARDINDEX[afile][arank]];
              afile = file + 1; arank = rank - 1;
              if ((afile >= 1) & (afile <= 8) & (arank >= 1) & (arank <= 8))
                     BLACK_PAWN_ATTACKS[square] |= BITSET[BOARDINDEX[afile][arank]];
       }
 
       // BLACK_PAWN_MOVES
       for (square = 0; square < 64; square++)
       {
              file = FILES[square]; rank = RANKS[square];
              afile = file; arank = rank - 1;
              if ((afile >= 1) & (afile <= 8) & (arank >= 1) & (arank <= 8))
                     BLACK_PAWN_MOVES[square] |= BITSET[BOARDINDEX[afile][arank]];
              if (rank == 7)
              {
                     afile = file; arank = rank - 2;
                     if ((afile >= 1) & (afile <= 8) & (arank >= 1) & (arank <= 8))
                           BLACK_PAWN_DOUBLE_MOVES[square] |= BITSET[BOARDINDEX[afile][arank]];
              }
       }
 
       // KNIGHT attacks;
       for (square = 0; square < 64; square++)
       {
              file = FILES[square];
              rank = RANKS[square];
              afile = file - 2; arank = rank + 1;
              if ((afile >= 1) & (afile <= 8) & (arank >= 1) & (arank <= 8))
                     KNIGHT_ATTACKS[square] |= BITSET[BOARDINDEX[afile][arank]];
              afile = file - 1; arank = rank + 2;
              if ((afile >= 1) & (afile <= 8) & (arank >= 1) & (arank <= 8))
                     KNIGHT_ATTACKS[square] |= BITSET[BOARDINDEX[afile][arank]];
              afile = file + 1; arank = rank + 2;
              if ((afile >= 1) & (afile <= 8) & (arank >= 1) & (arank <= 8))
                     KNIGHT_ATTACKS[square] |= BITSET[BOARDINDEX[afile][arank]];
              afile = file + 2; arank = rank + 1;
              if ((afile >= 1) & (afile <= 8) & (arank >= 1) & (arank <= 8))
                     KNIGHT_ATTACKS[square] |= BITSET[BOARDINDEX[afile][arank]];
              afile = file + 2; arank = rank - 1;
              if ((afile >= 1) & (afile <= 8) & (arank >= 1) & (arank <= 8))
                     KNIGHT_ATTACKS[square] |= BITSET[BOARDINDEX[afile][arank]];
              afile = file + 1; arank = rank - 2;
              if ((afile >= 1) & (afile <= 8) & (arank >= 1) & (arank <= 8))
                     KNIGHT_ATTACKS[square] |= BITSET[BOARDINDEX[afile][arank]];
              afile = file - 1; arank = rank - 2;
              if ((afile >= 1) & (afile <= 8) & (arank >= 1) & (arank <= 8))
                     KNIGHT_ATTACKS[square] |= BITSET[BOARDINDEX[afile][arank]];
              afile = file - 2; arank = rank - 1;
              if ((afile >= 1) & (afile <= 8) & (arank >= 1) & (arank <= 8))
                     KNIGHT_ATTACKS[square] |= BITSET[BOARDINDEX[afile][arank]];
       }
 
       // KING attacks;
       for (square = 0; square < 64; square++)
       {
              file = FILES[square]; rank = RANKS[square];
              afile = file - 1; arank = rank;
              if ((afile >= 1) & (afile <= 8) & (arank >= 1) & (arank <= 8))
                     KING_ATTACKS[square] |= BITSET[BOARDINDEX[afile][arank]];
              afile = file - 1; arank = rank + 1;
              if ((afile >= 1) & (afile <= 8) & (arank >= 1) & (arank <= 8))
                     KING_ATTACKS[square] |= BITSET[BOARDINDEX[afile][arank]];
              afile = file; arank = rank + 1;
              if ((afile >= 1) & (afile <= 8) & (arank >= 1) & (arank <= 8))
                     KING_ATTACKS[square] |= BITSET[BOARDINDEX[afile][arank]];
              afile = file + 1; arank = rank + 1;
              if ((afile >= 1) & (afile <= 8) & (arank >= 1) & (arank <= 8))
                     KING_ATTACKS[square] |= BITSET[BOARDINDEX[afile][arank]];
              afile = file + 1; arank = rank;
              if ((afile >= 1) & (afile <= 8) & (arank >= 1) & (arank <= 8))
                     KING_ATTACKS[square] |= BITSET[BOARDINDEX[afile][arank]];
              afile = file + 1; arank = rank - 1;
              if ((afile >= 1) & (afile <= 8) & (arank >= 1) & (arank <= 8))
                     KING_ATTACKS[square] |= BITSET[BOARDINDEX[afile][arank]];
              afile = file; arank = rank - 1;
              if ((afile >= 1) & (afile <= 8) & (arank >= 1) & (arank <= 8))
                     KING_ATTACKS[square] |= BITSET[BOARDINDEX[afile][arank]];
              afile = file - 1; arank = rank - 1;
              if ((afile >= 1) & (afile <= 8) & (arank >= 1) & (arank <= 8))
                     KING_ATTACKS[square] |= BITSET[BOARDINDEX[afile][arank]];
       }
 
       //  RANK attacks (ROOKS and QUEENS):
       //  use           unsigned char GEN_SLIDING_ATTACKS[8 squares] [64 states]
       //  to initialize BitMap        RANK_ATTACKS       [64 squares][64 states]
       //
       for (square = 0; square < 64; square++)
       {
              for (state6Bit = 0; state6Bit < 64; state6Bit++)
              {
                     RANK_ATTACKS[square][state6Bit] = 0;
                     RANK_ATTACKS[square][state6Bit] |=
                           BitMap(GEN_SLIDING_ATTACKS[FILES[square]-1][state6Bit]) << (RANKSHIFT[square] - 1);
              }
       }
 
       //  FILE attacks (ROOKS and QUEENS):
       //  use           unsigned char GEN_SLIDING_ATTACKS[8 squares] [64 states]
       //  to initialize BitMap        FILE_ATTACKS       [64 squares][64 states]
       //
       //  Occupancy transformation is as follows:
       //
       //   occupancy state bits of the file:               occupancy state bits in GEN_SLIDING_ATTACKS:
       //
       //        . . . . . . . . MSB                           LSB         MSB
       //        . . . . . A . .                    =>         A B C D E F . .                            
       //        . . . . . B . .
       //        . . . . . C . .
       //        . . . . . D . .
       //        . . . . . E . .
       //        . . . . . F . .
       //    LSB . . . . . . . .
       //
       //  The reverse transformation is as follows:
       //
       //   attack bits in GEN_SLIDING_ATTACKS:             attack bits in the file:
       //
       //        LSB         MSB                               . . . . . m . . MSB
       //        m n o p q r s t                    =>         . . . . . n . .
       //                                                      . . . . . o . .
       //                                                      . . . . . p . .
       //                                                      . . . . . q . .
       //                                                      . . . . . r . .
       //                                                      . . . . . s . .
       //                                                 LSB  . . . . . t . .
       //
       for (square = 0; square < 64; square++)
       {
              for (state6Bit = 0; state6Bit < 64; state6Bit++)
              {
                     FILE_ATTACKS[square][state6Bit] = 0x0;
 
                     // check to see if attackbit'-th  bit is set in GEN_SLIDING_ATTACKS, for this combination of square/occupancy state
                     for (attackbit = 0; attackbit < 8; attackbit++) // from LSB to MSB
                     {
                           //  conversion from 64 board squares to the 8 corresponding positions in the GEN_SLIDING_ATTACKS array: "8-RANKS[square]"
                           if (GEN_SLIDING_ATTACKS[8-RANKS[square]][state6Bit] & CHARBITSET[attackbit])
                           {
                                  // the bit is set, so we need to update FILE_ATTACKS accordingly:
                                  // conversion of square/attackbit to the corresponding 64 board FILE: FILES[square]
                                  // conversion of square/attackbit to the corresponding 64 board RANK: 8-attackbit
                                  file = FILES[square];
                                  rank = 8 - attackbit;
                                  FILE_ATTACKS[square][state6Bit] |=  BITSET[BOARDINDEX[file][rank]];
                           }
                     }
              }
       }
 
       //  DIAGA8H1_ATTACKS attacks (BISHOPS and QUEENS):
       for (square = 0; square < 64; square++)
       {
              for (state6Bit = 0; state6Bit < 64; state6Bit++)
              {
                     DIAGA8H1_ATTACKS[square][state6Bit] = 0x0;
                     for (attackbit = 0; attackbit < 8; attackbit++) // from LSB to MSB
                     {
                           //  conversion from 64 board squares to the 8 corresponding positions in the GEN_SLIDING_ATTACKS array: MIN((8-RANKS[square]),(FILES[square]-1))
                           if (GEN_SLIDING_ATTACKS[(8-RANKS[square]) < (FILES[square]-1) ? (8-RANKS[square]) : (FILES[square]-1)][state6Bit] & CHARBITSET[attackbit])
                           {
                                  // the bit is set, so we need to update FILE_ATTACKS accordingly:
                                  // conversion of square/attackbit to the corresponding 64 board file and rank:
                                  diaga8h1 = FILES[square] + RANKS[square]; // from 2 to 16, longest diagonal = 9
                                  if (diaga8h1 < 10)
                                  {
                                    file = attackbit + 1;
                                    rank = diaga8h1 - file;
                                  }
                                  else
                                  {
                                    rank = 8 - attackbit;
                                    file = diaga8h1 - rank;
                                  }
                                  if ((file > 0) && (file < 9) && (rank > 0) && (rank < 9))
                                  {
                                         DIAGA8H1_ATTACKS[square][state6Bit] |=  BITSET[BOARDINDEX[file][rank]];
                                  }
                           }
                     }
              }
       }
 
       //  DIAGA1H8_ATTACKS attacks (BISHOPS and QUEENS):
       for (square = 0; square < 64; square++)
       {
              for (state6Bit = 0; state6Bit < 64; state6Bit++)
              {
                     DIAGA1H8_ATTACKS[square][state6Bit] = 0x0;
                     for (attackbit = 0; attackbit < 8; attackbit++) // from LSB to MSB
                     {
                           //  conversion from 64 board squares to the 8 corresponding positions in the GEN_SLIDING_ATTACKS array: MIN((8-RANKS[square]),(FILES[square]-1))
                           if (GEN_SLIDING_ATTACKS[(RANKS[square]-1) < (FILES[square]-1) ? (RANKS[square]-1) : (FILES[square]-1)][state6Bit] & CHARBITSET[attackbit])
                           {
                                  // the bit is set, so we need to update FILE_ATTACKS accordingly:
                                  // conversion of square/attackbit to the corresponding 64 board file and rank:
                                  diaga1h8 = FILES[square] - RANKS[square]; // from -7 to 7, longest diagonal = 0
                                  if (diaga1h8 < 0)
                                  {
                                    file = attackbit + 1;
                                    rank = file - diaga1h8;
                                  }
                                  else
                                  {
                                    rank = attackbit + 1;
                                    file = diaga1h8 + rank;
                                  }
                                  if ((file > 0) && (file < 9) && (rank > 0) && (rank < 9))
                                  {
                                          DIAGA1H8_ATTACKS[square][state6Bit] |=  BITSET[BOARDINDEX[file][rank]];
                                  }
                           }
                     }
              }
       }
 
 
//     ===========================================================================
//     Masks for castling, index 0 is for white, 1 is for black
//     ===========================================================================
 
       maskEG[0] = BITSET[E1] | BITSET[F1] | BITSET[G1];
       maskEG[1] = BITSET[E8] | BITSET[F8] | BITSET[G8];
 
       maskFG[0] = BITSET[F1] | BITSET[G1];
       maskFG[1] = BITSET[F8] | BITSET[G8];
 
       maskBD[0] = BITSET[B1] | BITSET[C1] | BITSET[D1];
       maskBD[1] = BITSET[B8] | BITSET[C8] | BITSET[D8];
 
       maskCE[0] = BITSET[C1] | BITSET[D1] | BITSET[E1];
       maskCE[1] = BITSET[C8] | BITSET[D8] | BITSET[E8];
 
//     ===========================================================================
//     The 4 castling moves can be predefined:
//     ===========================================================================
 
       move.clear();
       move.setCapt(EMPTY);
       move.setPiec(WHITE_KING);
       move.setProm(WHITE_KING);
       move.setFrom(E1);
       move.setTosq(G1);
       WHITE_OO_CASTL = move.moveInt;
       move.setTosq(C1);
       WHITE_OOO_CASTL = move.moveInt;
 
       move.setPiec(BLACK_KING);
       move.setProm(BLACK_KING);
       move.setFrom(E8);
       move.setTosq(G8);
       BLACK_OO_CASTL = move.moveInt;
       move.setTosq(C8);
       BLACK_OOO_CASTL = move.moveInt;
 
//     ===========================================================================
//     Initialize evaluation data & bitmaps
//     ===========================================================================
 
       BLACK_SQUARES = 0;
       for (i = 0; i < 64; i++)
       {
              if ((i + RANKS[i]) % 2) BLACK_SQUARES ^= BITSET[i];
       }
       WHITE_SQUARES = ~BLACK_SQUARES;
 
       // Clear bitmaps:
       for (i = 0; i < 64; i++)
       {
              PASSED_WHITE[i] = 0;
              PASSED_BLACK[i] = 0;
              ISOLATED_WHITE[i] = 0;
              ISOLATED_BLACK[i] = 0;
              BACKWARD_WHITE[i] = 0;
              BACKWARD_BLACK[i] = 0;
              KINGSHIELD_STRONG_W[i] = 0;
              KINGSHIELD_STRONG_B[i] = 0;
              KINGSHIELD_WEAK_W[i] = 0;
              KINGSHIELD_WEAK_B[i] = 0;
       }
 
       for (i = 0; i < 64; i++)
       {
        //  PASSED_WHITE:
              for (rank = RANKS[i] + 1; rank < 8; rank++)
              {
                     // 3 files:
                     if (FILES[i] - 1 > 0) PASSED_WHITE[i] ^= BITSET[BOARDINDEX[FILES[i] - 1][rank]];
                     PASSED_WHITE[i] ^= BITSET[BOARDINDEX[FILES[i]][rank]];
                     if (FILES[i] + 1 < 9 ) PASSED_WHITE[i] ^= BITSET[BOARDINDEX[FILES[i] + 1][rank]];
              }
 
              // ISOLATED_WHITE:
              for (rank = 2; rank < 8; rank++)
              {
                     // 2 files:
                     if (FILES[i] - 1 > 0) ISOLATED_WHITE[i] ^= BITSET[BOARDINDEX[FILES[i] - 1][rank]];
                     if (FILES[i] + 1 < 9 ) ISOLATED_WHITE[i] ^= BITSET[BOARDINDEX[FILES[i] + 1][rank]];
              }
 
              //  BACKWARD_WHITE:
              for (rank = 2; rank <= RANKS[i]; rank++)
              {
                     // 2 files:
                     if (FILES[i] - 1 > 0) BACKWARD_WHITE[i] ^= BITSET[BOARDINDEX[FILES[i] - 1][rank]];
                     if (FILES[i] + 1 < 9 ) BACKWARD_WHITE[i] ^= BITSET[BOARDINDEX[FILES[i] + 1][rank]];
              }
       }
 
       // Pawn shield bitmaps for king safety, only if the king is on the first 3 ranks:
       for (i = 0; i < 24; i++)
       {
        //  KINGSHIELD_STRONG_W & KINGSHIELD_WEAK_W:
              KINGSHIELD_STRONG_W[i] ^= BITSET[i + 8];
              KINGSHIELD_WEAK_W[i] ^= BITSET[i + 16];
              if (FILES[i] > 1)
              {
                     KINGSHIELD_STRONG_W[i] ^= BITSET[i + 7];
                     KINGSHIELD_WEAK_W[i] ^= BITSET[i + 15];
              }
              if (FILES[i] < 8)
              {
                     KINGSHIELD_STRONG_W[i] ^= BITSET[i + 9];
                     KINGSHIELD_WEAK_W[i] ^= BITSET[i + 17];
              }
              if (FILES[i]== 1)
              {
                     KINGSHIELD_STRONG_W[i] ^= BITSET[i + 10];
                     KINGSHIELD_WEAK_W[i] ^= BITSET[i + 18];
              }
              if (FILES[i]== 8)
              {
                     KINGSHIELD_STRONG_W[i] ^= BITSET[i + 6];
                     KINGSHIELD_WEAK_W[i] ^= BITSET[i + 14];
              }
       }
 
//     ===========================================================================
//     DISTANCE array, distance is measured as max of (rank,file)-difference
//     ===========================================================================
       for (i = 0 ; i < 64; i++)
       {
              for (square = 0 ; square < 64; square++)
              {
                     if (abs(RANKS[i] - RANKS[square]) > abs(FILES[i] - FILES[square]))
                           DISTANCE[i][square] = abs(RANKS[i] - RANKS[square]);
                     else
                           DISTANCE[i][square] = abs(FILES[i] - FILES[square]);
              }
       }
 
//     ===========================================================================
//     Initialize MIRRORed data:
//     ===========================================================================
       // Data is supplied as mirrored for WHITE, so it's ready for BLACK to use:
       for (square = 0; square < 64; square++)
       {
              PAWNPOS_B[square] = PAWNPOS_W[square];
              KNIGHTPOS_B[square] = KNIGHTPOS_W[square];
              BISHOPPOS_B[square] = BISHOPPOS_W[square];
              ROOKPOS_B[square] = ROOKPOS_W[square];
              QUEENPOS_B[square] = QUEENPOS_W[square];
              KINGPOS_B[square] = KINGPOS_W[square];
              KINGPOS_ENDGAME_B[square] = KINGPOS_ENDGAME_W[square];
       }
 
       // Complete missing mirrored data:
       for (i = 0; i < 64; i++)
       {
              PAWNPOS_W[i] = PAWNPOS_B[MIRROR[i]];
              KNIGHTPOS_W[i] = KNIGHTPOS_B[MIRROR[i]];
              BISHOPPOS_W[i] = BISHOPPOS_B[MIRROR[i]];
              ROOKPOS_W[i] = ROOKPOS_B[MIRROR[i]];
              QUEENPOS_W[i] = QUEENPOS_B[MIRROR[i]];
              KINGPOS_W[i] = KINGPOS_B[MIRROR[i]];
              KINGPOS_ENDGAME_W[i] = KINGPOS_ENDGAME_B[MIRROR[i]];
 
              for (square = 0; square < 64; square ++)
              {
                     //  PASSED_BLACK bitmaps (mirror of PASSED_WHITE bitmaps):
                     if (PASSED_WHITE[i] & BITSET[square]) PASSED_BLACK[MIRROR[i]] |= BITSET[MIRROR[square]];
 
                     //  ISOLATED_BLACK bitmaps (mirror of ISOLATED_WHITE bitmaps):
                     if (ISOLATED_WHITE[i] & BITSET[square]) ISOLATED_BLACK[MIRROR[i]] |= BITSET[MIRROR[square]];
 
                     //  BACKWARD_BLACK bitmaps (mirror of BACKWARD_WHITE bitmaps):
                     if (BACKWARD_WHITE[i] & BITSET[square]) BACKWARD_BLACK[MIRROR[i]] |= BITSET[MIRROR[square]];
 
                     //  KINGSHIELD_STRONG_B bitmaps (mirror of KINGSHIELD_STRONG_W bitmaps):
                     if (KINGSHIELD_STRONG_W[i] & BITSET[square]) KINGSHIELD_STRONG_B[MIRROR[i]] |= BITSET[MIRROR[square]];
 
                     //  KINGSHIELD_WEAK_B bitmaps (mirror of KINGSHIELD_WEAK_W bitmaps):
                     if (KINGSHIELD_WEAK_W[i] & BITSET[square]) KINGSHIELD_WEAK_B[MIRROR[i]] |= BITSET[MIRROR[square]];
              }
       }
 
    return;
}
 
void info()
{
 
       //  your playground... display variables - meant for testing/verification purposes only
       std::cout << std::endl << "============ info start ==============" << std::endl;
       std::cout << "size of board, in bytes   = " << sizeof(board) << std::endl;
       std::cout << "Material value            = " << board.Material << std::endl;
       std::cout << "White castling rights     = " << int(board.castleWhite) << std::endl;
       std::cout << "Black castling rights     = " << int(board.castleBlack) << std::endl;
       std::cout << "En-passant square         = " << board.epSquare << std::endl;
       std::cout << "Fifty move count          = " << board.fiftyMove << std::endl;
       std::cout << "============ info end ================" << std::endl << std::endl;
 
       return;
} 

 
 
step 52: globals.h  

#ifndef WINGLET_GLOBALS_H
#define WINGLET_GLOBALS_H
 
#include "defines.h"
#include "board.h"
#include "move.h"
#include "gameline.h"
 
char CMD_BUFF[MAX_CMD_BUFF];
int CMD_BUFF_COUNT = 0;
 
Board board;
 
extern const int A8 = 56; extern const int B8 = 57; extern const int C8 = 58; extern const int D8 = 59;
extern const int E8 = 60; extern const int F8 = 61; extern const int G8 = 62; extern const int H8 = 63;
extern const int A7 = 48; extern const int B7 = 49; extern const int C7 = 50; extern const int D7 = 51;
extern const int E7 = 52; extern const int F7 = 53; extern const int G7 = 54; extern const int H7 = 55;
extern const int A6 = 40; extern const int B6 = 41; extern const int C6 = 42; extern const int D6 = 43;
extern const int E6 = 44; extern const int F6 = 45; extern const int G6 = 46; extern const int H6 = 47;
extern const int A5 = 32; extern const int B5 = 33; extern const int C5 = 34; extern const int D5 = 35;
extern const int E5 = 36; extern const int F5 = 37; extern const int G5 = 38; extern const int H5 = 39;
extern const int A4 = 24; extern const int B4 = 25; extern const int C4 = 26; extern const int D4 = 27;
extern const int E4 = 28; extern const int F4 = 29; extern const int G4 = 30; extern const int H4 = 31;
extern const int A3 = 16; extern const int B3 = 17; extern const int C3 = 18; extern const int D3 = 19;
extern const int E3 = 20; extern const int F3 = 21; extern const int G3 = 22; extern const int H3 = 23;
extern const int A2 =  8; extern const int B2 =  9; extern const int C2 = 10; extern const int D2 = 11;
extern const int E2 = 12; extern const int F2 = 13; extern const int G2 = 14; extern const int H2 = 15;
extern const int A1 =  0; extern const int B1 =  1; extern const int C1 =  2; extern const int D1 =  3;
extern const int E1 =  4; extern const int F1 =  5; extern const int G1 =  6; extern const int H1 =  7;
 
const char* SQUARENAME[64] = {"a1","b1","c1","d1","e1","f1","g1","h1",
                              "a2","b2","c2","d2","e2","f2","g2","h2",
                              "a3","b3","c3","d3","e3","f3","g3","h3",
                              "a4","b4","c4","d4","e4","f4","g4","h4",
                              "a5","b5","c5","d5","e5","f5","g5","h5",
                              "a6","b6","c6","d6","e6","f6","g6","h6",
                              "a7","b7","c7","d7","e7","f7","g7","h7",
                              "a8","b8","c8","d8","e8","f8","g8","h8"};
 
extern const int FILES[64] = {
       1, 2, 3, 4, 5, 6, 7, 8,
       1, 2, 3, 4, 5, 6, 7, 8,
       1, 2, 3, 4, 5, 6, 7, 8,
       1, 2, 3, 4, 5, 6, 7, 8,
       1, 2, 3, 4, 5, 6, 7, 8,
       1, 2, 3, 4, 5, 6, 7, 8,
       1, 2, 3, 4, 5, 6, 7, 8,
       1, 2, 3, 4, 5, 6, 7, 8
};
 
extern const int RANKS[64] = {
       1, 1, 1, 1, 1, 1, 1, 1,
       2, 2, 2, 2, 2, 2, 2, 2,
       3, 3, 3, 3, 3, 3, 3, 3,
       4, 4, 4, 4, 4, 4, 4, 4,
       5, 5, 5, 5, 5, 5, 5, 5,
       6, 6, 6, 6, 6, 6, 6, 6,
       7, 7, 7, 7, 7, 7, 7, 7,
       8, 8, 8, 8, 8, 8, 8, 8
};
 
// Identifier of next move:
extern const unsigned char WHITE_MOVE  = 0; 
extern const unsigned char BLACK_MOVE  = 1; 
 
// Piece identifiers, 4 bits each.
// Usefull bitwise properties of this numbering scheme:
// white = 0..., black = 1..., sliding = .1.., nonsliding = .0..
// rank/file sliding pieces = .11., diagonally sliding pieces = .1.1
// pawns and kings (without color bits), are < 3
// major pieces (without color bits set), are > 5
// minor and major pieces (without color bits set), are > 2
extern const unsigned char EMPTY = 0;                //  0000
extern const unsigned char WHITE_PAWN = 1;           //  0001
extern const unsigned char WHITE_KING = 2;           //  0010
extern const unsigned char WHITE_KNIGHT = 3;         //  0011
extern const unsigned char WHITE_BISHOP =  5;        //  0101
extern const unsigned char WHITE_ROOK = 6;           //  0110
extern const unsigned char WHITE_QUEEN = 7;          //  0111
extern const unsigned char BLACK_PAWN = 9;           //  1001
extern const unsigned char BLACK_KING = 10;          //  1010
extern const unsigned char BLACK_KNIGHT = 11;        //  1011
extern const unsigned char BLACK_BISHOP = 13;        //  1101
extern const unsigned char BLACK_ROOK = 14;          //  1110
extern const unsigned char BLACK_QUEEN = 15;         //  1111
 
const char* PIECENAMES[16] = {"  ","P ","K ","N ","  ","B ","R ","Q ",
                              "  ","P*","K*","N*","  ","B*","R*","Q*"};
 
BitMap BITSET[64];
int BOARDINDEX[9][9]; // index 0 is not used, only 1..8.
 
// Value of material, in centipawns:
extern const int PAWN_VALUE = 100;
extern const int KNIGHT_VALUE = 300;
extern const int BISHOP_VALUE = 300;
extern const int ROOK_VALUE = 500;
extern const int QUEEN_VALUE = 900;
extern const int KING_VALUE = 9999;
extern const int CHECK_MATE = KING_VALUE;
 
// used in Eugene Nalimov's bitScanReverse
int MS1BTABLE[256];
 
// Attack tables:
BitMap WHITE_PAWN_ATTACKS[64];
BitMap WHITE_PAWN_MOVES[64];
BitMap WHITE_PAWN_DOUBLE_MOVES[64];
BitMap BLACK_PAWN_ATTACKS[64];
BitMap BLACK_PAWN_MOVES[64];
BitMap BLACK_PAWN_DOUBLE_MOVES[64];
BitMap KNIGHT_ATTACKS[64];
BitMap KING_ATTACKS[64];
BitMap RANK_ATTACKS[64][64];      // 32KB
BitMap FILE_ATTACKS[64][64];      // 32KB
BitMap DIAGA8H1_ATTACKS[64][64];  // 32KB
BitMap DIAGA1H8_ATTACKS[64][64];  // 32KB
 
// Move generator shift for ranks:
extern const int RANKSHIFT[64] = {
        1,  1,  1,  1,  1,  1,  1,  1,
        9,  9,  9,  9,  9,  9,  9,  9,
       17, 17, 17, 17, 17, 17, 17, 17,  
       25, 25, 25, 25, 25, 25, 25, 25,
       33, 33, 33, 33, 33, 33, 33, 33,
       41, 41, 41, 41, 41, 41, 41, 41,
       49, 49, 49, 49, 49, 49, 49, 49,
       57, 57, 57, 57, 57, 57, 57, 57
};
 
// Move generator magic multiplication numbers for files:
extern const BitMap _FILEMAGICS[8] = {
       0x8040201008040200,
       0x4020100804020100,
       0x2010080402010080,
       0x1008040201008040,
       0x0804020100804020,
       0x0402010080402010,
       0x0201008040201008,
       0x0100804020100804
};
 
// Move generator magic multiplication numbers for diagonals:
extern const BitMap _DIAGA8H1MAGICS[15] = {
       0x0,
       0x0,
       0x0101010101010100,
       0x0101010101010100,
       0x0101010101010100,
       0x0101010101010100,
       0x0101010101010100,
       0x0101010101010100,
       0x0080808080808080,
       0x0040404040404040,
       0x0020202020202020,
       0x0010101010101010,
       0x0008080808080808,
       0x0,
       0x0
};
 
// Move generator magic multiplication numbers for diagonals:
extern const BitMap _DIAGA1H8MAGICS[15] = {
       0x0,
       0x0,
       0x0101010101010100,
       0x0101010101010100,
       0x0101010101010100,
       0x0101010101010100,
       0x0101010101010100,
       0x0101010101010100,
       0x8080808080808000,
       0x4040404040400000,
       0x2020202020000000,
       0x1010101000000000,
       0x0808080000000000,
       0x0,
       0x0
};
 
// Move generator 6-bit masking and magic multiplication numbers:
BitMap RANKMASK[64];
BitMap FILEMASK[64];
BitMap FILEMAGIC[64];
BitMap DIAGA8H1MASK[64];
BitMap DIAGA8H1MAGIC[64];
BitMap DIAGA1H8MASK[64];
BitMap DIAGA1H8MAGIC[64];
 
// We use one generalized sliding attacks array: [8 squares][64 states]
// the unsigned char (=8 bits) contains the attacks for a rank, file or diagonal
unsigned char GEN_SLIDING_ATTACKS[8][64];
 
// Used for castling:
unsigned char CANCASTLEOO = 1;
unsigned char CANCASTLEOOO = 2;
BitMap maskEG[2];
BitMap maskFG[2];
BitMap maskBD[2];
BitMap maskCE[2];
unsigned int WHITE_OOO_CASTL;
unsigned int BLACK_OOO_CASTL;
unsigned int WHITE_OO_CASTL;
unsigned int BLACK_OO_CASTL;
 
int ICAPT;
int IEP;
int IPROM;
int ICASTLOO;
int ICASTLOOO;
int ICHECK;
 
// Evaluation scores start here, all scores are in centipawns.
// If there are scoring data that is supposed to be symmetrical (i.e. same for BLACK & WHITE),
// then only the data for WHITE is supplied, and data for BLACK is calculated in dataInit().
// This is done to make data entry easier, eliminate typos and guarantuee symmetry.
//
// MIRRORED:
// Some scoring arrays are supplied MIRRORED, i.e. starting with the last rank (see the comments below).
// They are mirrored back in the right order in dataInit().
// This is only done to make data entry easier, because you can enter the scoring data as if you're
// looking at the chess board from White's point of perspective.
 
int PENALTY_DOUBLED_PAWN          = 10;
int PENALTY_ISOLATED_PAWN         = 20;
int PENALTY_BACKWARD_PAWN         =  8;
int BONUS_PASSED_PAWN             = 20;
int BONUS_BISHOP_PAIR             = 10;
int BONUS_ROOK_BEHIND_PASSED_PAWN = 20;
int BONUS_ROOK_ON_OPEN_FILE       = 20;
int BONUS_TWO_ROOKS_ON_OPEN_FILE  = 20;
 
int BONUS_PAWN_SHIELD_STRONG = 9;
int BONUS_PAWN_SHIELD_WEAK = 4;
 
int PAWN_OWN_DISTANCE[8] =           { 0,   8,  4,  2,  0,  0,  0,  0 };
int PAWN_OPPONENT_DISTANCE[8] =      { 0,   2,  1,  0,  0,  0,  0,  0 };
int KNIGHT_DISTANCE[8] =             { 0,   4,  4,  0,  0,  0,  0,  0 };
int BISHOP_DISTANCE[8] =             { 0,   5,  4,  3,  2,  1,  0,  0 };
int ROOK_DISTANCE[8] =               { 0,   7,  5,  4,  3,  0,  0,  0 };
int QUEEN_DISTANCE[8] =              { 0,  10,  8,  5,  4,  0,  0,  0 };
 
// *** This array is MIRRORED                          ***
// *** You can enter the scoring data as if you're     ***
// *** looking at the chess board from white's point   ***
// *** of perspective. Lower left corner is square a1: ***
int PAWNPOS_W[64] = {
         0,   0,   0,   0,   0,   0,   0,   0,
         5,  10,  15,  20,  20,  15,  10,   5,
         4,   8,  12,  16,  16,  12,   8,   4,
         3,   6,   9,  12,  12,   9,   6,   3,
         2,   4,   6,   8,   8,   6,   4,   2,
         1,   2,   3, -10, -10,   3,   2,   1,
         0,   0,   0, -40, -40,   0,   0,   0,
         0,   0,   0,   0,   0,   0,   0,   0
};
 
// *** This array is MIRRORED                          ***
// *** You can enter the scoring data as if you're     ***
// *** looking at the chess board from white's point   ***
// *** of perspective. Lower left corner is square a1: ***
int KNIGHTPOS_W[64] = {
       -10, -10, -10, -10, -10, -10, -10, -10,
       -10,   0,   0,   0,   0,   0,   0, -10,
       -10,   0,   5,   5,   5,   5,   0, -10,
       -10,   0,   5,  10,  10,   5,   0, -10,
       -10,   0,   5,  10,  10,   5,   0, -10,
       -10,   0,   5,   5,   5,   5,   0, -10,
       -10,   0,   0,   0,   0,   0,   0, -10,
       -10, -30, -10, -10, -10, -10, -30, -10
};
 
// *** This array is MIRRORED                          ***
// *** You can enter the scoring data as if you're     ***
// *** looking at the chess board from white's point   ***
// *** of perspective. Lower left corner is square a1: ***
int BISHOPPOS_W[64] = {
       -10, -10, -10, -10, -10, -10, -10, -10,
       -10,   0,   0,   0,   0,   0,   0, -10,
       -10,   0,   5,   5,   5,   5,   0, -10,
       -10,   0,   5,  10,  10,   5,   0, -10,
       -10,   0,   5,  10,  10,   5,   0, -10,
       -10,   0,   5,   5,   5,   5,   0, -10,
       -10,   0,   0,   0,   0,   0,   0, -10,
       -10, -10, -20, -10, -10, -20, -10, -10
};
 
// *** This array is MIRRORED                          ***
// *** You can enter the scoring data as if you're     ***
// *** looking at the chess board from white's point   ***
// *** of perspective. Lower left corner is square a1: ***
int ROOKPOS_W[64] = {
      0,  0,  0,  0,   0,  0,  0,   0,
     15, 15, 15, 15,  15, 15, 15,  15,
      0,  0,  0,  0,   0,  0,  0,   0,
      0,  0,  0,  0,   0,  0,  0,   0,
      0,  0,  0,  0,   0,  0,  0,   0,
      0,  0,  0,  0,   0,  0,  0,   0,
      0,  0,  0,  0,   0,  0,  0,   0,
    -10,  0,  0, 10,  10,  0,  0, -10
};
 
// *** This array is MIRRORED                          ***
// *** You can enter the scoring data as if you're     ***
// *** looking at the chess board from white's point   ***
// *** of perspective. Lower left corner is square a1: ***
int QUEENPOS_W[64] = {
       -10, -10, -10, -10, -10, -10, -10, -10,
       -10,   0,   0,   0,   0,   0,   0, -10,
       -10,   0,   5,   5,   5,   5,   0, -10,
       -10,   0,   5,  10,  10,   5,   0, -10,
       -10,   0,   5,  10,  10,   5,   0, -10,
       -10,   0,   5,   5,   5,   5,   0, -10,
       -10,   0,   0,   0,   0,   0,   0, -10,
       -10, -10, -20, -10, -10, -20, -10, -10
};
 
// *** This array is MIRRORED                          ***
// *** You can enter the scoring data as if you're     ***
// *** looking at the chess board from white's point   ***
// *** of perspective. Lower left corner is square a1: ***
int KINGPOS_W[64]  = {
       -40, -40, -40, -40, -40, -40, -40, -40,
       -40, -40, -40, -40, -40, -40, -40, -40,
       -40, -40, -40, -40, -40, -40, -40, -40,
       -40, -40, -40, -40, -40, -40, -40, -40,
       -40, -40, -40, -40, -40, -40, -40, -40,
       -40, -40, -40, -40, -40, -40, -40, -40,
       -20, -20, -20, -20, -20, -20, -20, -20,
         0,  20,  40, -20,   0, -20,  40,  20
};
 
// *** This array is MIRRORED                          ***
// *** You can enter the scoring data as if you're     ***
// *** looking at the chess board from white's point   ***
// *** of perspective. Lower left corner is square a1: ***
int KINGPOS_ENDGAME_W[64] = {
         0,  10,  20,  30,  30,  20,  10,   0,
        10,  20,  30,  40,  40,  30,  20,  10,
        20,  30,  40,  50,  50,  40,  30,  20,
        30,  40,  50,  60,  60,  50,  40,  30,
        30,  40,  50,  60,  60,  50,  40,  30,
        20,  30,  40,  50,  50,  40,  30,  20,
        10,  20,  30,  40,  40,  30,  20,  10,
         0,  10,  20,  30,  30,  20,  10,   0
};
 
int MIRROR[64] = {
        56,  57,  58,  59,  60,  61,  62,  63,
        48,  49,  50,  51,  52,  53,  54,  55,
        40,  41,  42,  43,  44,  45,  46,  47,
        32,  33,  34,  35,  36,  37,  38,  39,
        24,  25,  26,  27,  28,  29,  30,  31,
        16,  17,  18,  19,  20,  21,  22,  23,
         8,   9,  10,  11,  12,  13,  14,  15,  
         0,   1,   2,   3,   4,   5,   6,   7
};
 
int DISTANCE[64][64];
int PAWNPOS_B[64];
int KNIGHTPOS_B[64];
int BISHOPPOS_B[64];
int ROOKPOS_B[64];
int QUEENPOS_B[64];
int KINGPOS_B[64];
int KINGPOS_ENDGAME_B[64];
BitMap PASSED_WHITE[64];
BitMap PASSED_BLACK[64];
BitMap ISOLATED_WHITE[64];
BitMap ISOLATED_BLACK[64];
BitMap BACKWARD_WHITE[64];
BitMap BACKWARD_BLACK[64];
BitMap KINGSHIELD_STRONG_W[64];
BitMap KINGSHIELD_STRONG_B[64];
BitMap KINGSHIELD_WEAK_W[64];
BitMap KINGSHIELD_WEAK_B[64];
BitMap WHITE_SQUARES;
BitMap BLACK_SQUARES;
 
#endif


step 53: extglobals.h  

#ifndef WINGLET_EXTGLOBALS_H
#define WINGLET_EXTGLOBALS_H
 
#include "defines.h"
#include "board.h"
#include "move.h"
#include "gameline.h"
 
extern char CMD_BUFF[];
extern int CMD_BUFF_COUNT;
 
extern Board board;
 
extern const int A8; extern const int B8; extern const int C8; extern const int D8;
extern const int E8; extern const int F8; extern const int G8; extern const int H8;
extern const int A7; extern const int B7; extern const int C7; extern const int D7;
extern const int E7; extern const int F7; extern const int G7; extern const int H7;
extern const int A6; extern const int B6; extern const int C6; extern const int D6;
extern const int E6; extern const int F6; extern const int G6; extern const int H6;
extern const int A5; extern const int B5; extern const int C5; extern const int D5;
extern const int E5; extern const int F5; extern const int G5; extern const int H5;
extern const int A4; extern const int B4; extern const int C4; extern const int D4;
extern const int E4; extern const int F4; extern const int G4; extern const int H4;
extern const int A3; extern const int B3; extern const int C3; extern const int D3;
extern const int E3; extern const int F3; extern const int G3; extern const int H3;
extern const int A2; extern const int B2; extern const int C2; extern const int D2;
extern const int E2; extern const int F2; extern const int G2; extern const int H2;
extern const int A1; extern const int B1; extern const int C1; extern const int D1;
extern const int E1; extern const int F1; extern const int G1; extern const int H1;
 
extern const char* SQUARENAME[];
 
extern const int FILES[];
extern const int RANKS[];
 
extern const unsigned char WHITE_MOVE; 
extern const unsigned char BLACK_MOVE; 
 
extern const unsigned char EMPTY;
extern const unsigned char WHITE_KNIGHT;
extern const unsigned char WHITE_PAWN;
extern const unsigned char WHITE_KING;
extern const unsigned char WHITE_BISHOP;
extern const unsigned char WHITE_ROOK;
extern const unsigned char WHITE_QUEEN;
extern const unsigned char BLACK_KNIGHT;
extern const unsigned char BLACK_PAWN;
extern const unsigned char BLACK_KING;
extern const unsigned char BLACK_BISHOP;
extern const unsigned char BLACK_ROOK;
extern const unsigned char BLACK_QUEEN;
 
extern const char* PIECENAMES[];
 
extern BitMap BITSET[];
extern int BOARDINDEX[9][9];
 
extern const int PAWN_VALUE;
extern const int KNIGHT_VALUE;
extern const int BISHOP_VALUE;
extern const int ROOK_VALUE;
extern const int QUEEN_VALUE;
extern const int KING_VALUE;
extern const int CHECK_MATE;
 
extern int MS1BTABLE[];            
 
extern BitMap WHITE_PAWN_ATTACKS[];
extern BitMap WHITE_PAWN_MOVES[];
extern BitMap WHITE_PAWN_DOUBLE_MOVES[];
extern BitMap BLACK_PAWN_ATTACKS[];
extern BitMap BLACK_PAWN_MOVES[];
extern BitMap BLACK_PAWN_DOUBLE_MOVES[];
extern BitMap KNIGHT_ATTACKS[];
extern BitMap KING_ATTACKS[];
extern BitMap RANK_ATTACKS[64][64];
extern BitMap FILE_ATTACKS[64][64];
extern BitMap DIAGA8H1_ATTACKS[64][64];
extern BitMap DIAGA1H8_ATTACKS[64][64];
 
extern const int RANKSHIFT[];
extern const BitMap _FILEMAGICS[];
extern const BitMap _DIAGA8H1MAGICS[];
extern const BitMap _DIAGA1H8MAGICS[];
 
extern BitMap RANKMASK[];
extern BitMap FILEMAGIC[];
extern BitMap FILEMASK[];
extern BitMap DIAGA8H1MASK[];
extern BitMap DIAGA8H1MAGIC[];
extern BitMap DIAGA1H8MASK[];
extern BitMap DIAGA1H8MAGIC[];
 
extern unsigned char GEN_SLIDING_ATTACKS[8][64];
 
extern unsigned char CANCASTLEOO;
extern unsigned char CANCASTLEOOO;
extern BitMap maskEG[];
extern BitMap maskFG[];
extern BitMap maskBD[];
extern BitMap maskCE[];
extern unsigned int WHITE_OOO_CASTL;
extern unsigned int BLACK_OOO_CASTL;
extern unsigned int WHITE_OO_CASTL;
extern unsigned int BLACK_OO_CASTL;
 
extern int ICAPT;
extern int IEP;
extern int IPROM;
extern int ICASTLOO;
extern int ICASTLOOO;
extern int ICHECK;
 
extern int PENALTY_DOUBLED_PAWN;
extern int PENALTY_ISOLATED_PAWN;
extern int PENALTY_BACKWARD_PAWN;
extern int BONUS_PASSED_PAWN;
extern int BONUS_BISHOP_PAIR;
extern int BONUS_ROOK_BEHIND_PASSED_PAWN;
extern int BONUS_ROOK_ON_OPEN_FILE;
extern int BONUS_PAWN_SHIELD_STRONG;
extern int BONUS_PAWN_SHIELD_WEAK;
extern int PAWN_OWN_DISTANCE[];
extern int PAWN_OPPONENT_DISTANCE[];
extern int KNIGHT_DISTANCE[];
extern int BISHOP_DISTANCE[];
extern int ROOK_DISTANCE[];
extern int QUEEN_DISTANCE[];
extern int PAWNPOS_W[];
extern int KNIGHTPOS_W[];
extern int BISHOPPOS_W[];
extern int ROOKPOS_W[];
extern int QUEENPOS_W[];
extern int KINGPOS_W[];
extern int KINGPOS_ENDGAME_W[];
extern int MIRROR[];
extern int DISTANCE[64][64];
extern int PAWNPOS_B[];
extern int KNIGHTPOS_B[];
extern int BISHOPPOS_B[];
extern int ROOKPOS_B[];
extern int QUEENPOS_B[];
extern int KINGPOS_B[];
extern int KINGPOS_ENDGAME_B[];
extern BitMap PASSED_WHITE[];
extern BitMap PASSED_BLACK[];
extern BitMap ISOLATED_WHITE[];
extern BitMap ISOLATED_BLACK[];
extern BitMap BACKWARD_WHITE[];
extern BitMap BACKWARD_BLACK[];
extern BitMap KINGSHIELD_STRONG_W[];
extern BitMap KINGSHIELD_STRONG_B[];
extern BitMap KINGSHIELD_WEAK_W[];
extern BitMap KINGSHIELD_WEAK_B[];
extern BitMap WHITE_SQUARES;
extern BitMap BLACK_SQUARES;
 
#endif

 

 

  read, or setup, positions and type "eval" to get the static evaluation of the position, change the side to move and type "eval" again.

  activate  WINGLET_VERBOSE_EVAL to see how the evaluation score is build up.

 


Home Previous Top Next

last update: Friday 10 June 2011