Home Previous Bottom Next

Writing a chess program in 99 steps


We add a new command: moves, to display all generated pseudo-legal moves:

step 29: command.cpp

#ifndef _CRT_SECURE_NO_DEPRECATE
#define _CRT_SECURE_NO_DEPRECATE 1
#endif
#include <iostream>
#include "defines.h"
#include "protos.h"
#include "extglobals.h"
#include "board.h"
 
void readCommands()
{
       int nextc;
 
       if (board.nextMove == WHITE_MOVE)
       {
                     std::cout << "wt> ";
       }
       else
       {
                     std::cout << "bl> ";
       }
       std::cout.flush();
 
//     ===========================================================================
//     Read a command and call doCommand:
//     ===========================================================================
       while ((nextc = getc(stdin)) != EOF)
       {
              if (nextc == '\n')
              {
                     CMD_BUFF[CMD_BUFF_COUNT] = '\0';
                     while (CMD_BUFF_COUNT)
                     {
                           if (!doCommand(CMD_BUFF)) return;
                     }     
                     if (board.nextMove == WHITE_MOVE)
                     {
                           std::cout << "wt> ";
                     }
                     else
                     {
                           std::cout << "bl> ";
                     }
                     std::cout.flush();
              }
              else
              {
                     if (CMD_BUFF_COUNT >= MAX_CMD_BUFF-1)
                     {
                           std::cout << "Warning: command buffer full !! " << std::endl;
                           CMD_BUFF_COUNT = 0;
                     }
                     CMD_BUFF[CMD_BUFF_COUNT++] = nextc;
              }
       }
}
 
BOOLTYPE doCommand(const char *buf)
{
 
       char userinput[80];
       int i, number;
 
//     =================================================================
//  return when command buffer is empty
//     =================================================================
 
       if (!strcmp(buf, ""))
       {
              CMD_BUFF_COUNT = '\0';
              return true;    
       }
 
//     =================================================================
//  help, h, or ?: show this help
//     =================================================================
       if ((!strcmp(buf, "help")) || (!strcmp(buf, "h")) || (!strcmp(buf, "?")))
       {
              std::cout << std::endl << "help:" << std::endl;
              std::cout << "black               : BLACK to move" << std::endl;
              std::cout << "cc                  : play computer-to-computer " << std::endl;
              std::cout << "d                   : display board " << std::endl;
              std::cout << "exit                : exit program " << std::endl;
              std::cout << "eval                : show static evaluation of this position" << std::endl;
              std::cout << "game                : show game moves " << std::endl;
              std::cout << "go                  : computer next move " << std::endl;
              std::cout << "help, h, or ?       : show this help " << std::endl;
              std::cout << "info                : display variables (for testing purposes)" << std::endl;
              std::cout << "move e2e4, or h7h8q : enter a move (use this format)" << std::endl;
              std::cout << "moves               : show all legal moves" << std::endl;
              std::cout << "new                 : start new game" << std::endl;
              std::cout << "perf                : benchmark a number of key functions" << std::endl;
              std::cout << "perft n             : calculate raw number of nodes from here, depth n " << std::endl;
              std::cout << "quit                : exit program " << std::endl;
              std::cout << "r                   : rotate board " << std::endl;
              std::cout << "readfen filename n  : reads #-th FEN position from filename" << std::endl;
              std::cout << "sd n                : set the search depth to n" << std::endl;
              std::cout << "setup               : setup board... " << std::endl;
              std::cout << "undo                : take back last move" << std::endl;
              std::cout << "white               : WHITE to move" << std::endl;
              std::cout << std::endl;
              CMD_BUFF_COUNT = '\0';
              return true;
       }
 
//     =================================================================
//  black: black to move
//     =================================================================
       if (!strcmp(buf, "black"))
       {
              board.nextMove = BLACK_MOVE;
              CMD_BUFF_COUNT = '\0';
              return true;
       }     
 
//     =================================================================
//  d: display board
//     =================================================================
       if (!strcmp(buf, "d"))
       {
              board.display();
              CMD_BUFF_COUNT = '\0';
              return true;
       }     
      
//     =================================================================
//  exit or quit: exit program
//     =================================================================
       if ((!strcmp(buf, "exit")) || (!strcmp(buf, "quit")))
       {
              CMD_BUFF_COUNT = '\0';
              return false;
       }
      
//     =================================================================
//  info: display variables (for testing purposes)
//     =================================================================
       if (!strcmp(buf, "info"))
       {
              info();
              CMD_BUFF_COUNT = '\0';
              return true;
       }
 
//     =================================================================
//  moves: show all legal moves
//     =================================================================
       if (!strcmp(buf, "moves"))
       {
              board.moveBufLen[0] = 0;
              board.moveBufLen[1] = movegen(board.moveBufLen[0]);
              std::cout << std::endl << "pseudo-legal moves from this position:" << std::endl;
              for (i = board.moveBufLen[0]; i < board.moveBufLen[1]; i++)
              {
                           std::cout << i+1 << ". " ;
                           displayMove(board.moveBuffer[i]);       
                           std::cout << std::endl;
              }
              CMD_BUFF_COUNT = '\0';
              return true;
       }
 
//     =================================================================
//  new: start new game
//     =================================================================
       if (!strcmp(buf, "new"))
       {
              dataInit();
              board.init();
              board.display();
              CMD_BUFF_COUNT = '\0';
              return true;
       }
 
//     =================================================================
//  r: rotate board
//     =================================================================
       if (!strcmp(buf, "r"))
       {
              board.viewRotated = !board.viewRotated;
              board.display();
              CMD_BUFF_COUNT = '\0';
              return true;
       }
 
//     =================================================================
//  readfen filename n : reads #-th FEN position from filename
//     =================================================================
       if (!strncmp(buf, "readfen", 7))
       {
              sscanf(buf+7,"%s %d", userinput, &number);
              board.init();
              readFen(userinput, number);
              board.display();
              CMD_BUFF_COUNT = '\0';
              return true;
       }
 
//     =================================================================
//  setup : setup board...
//     =================================================================
       if (!strncmp(buf, "setup", 5))
       {
              setup();
              CMD_BUFF_COUNT = '\0';
              return true;
       }     
//     =================================================================
//  white: white to move
//     =================================================================
       if (!strcmp(buf, "white"))
       {
              board.nextMove = WHITE_MOVE;
              CMD_BUFF_COUNT = '\0';
              return true;
       }     
 
//     =================================================================
//  unknown command
//     =================================================================
       std::cout << "    command not implemented: " << buf << ", type 'help' for more info" << std::endl;
       CMD_BUFF_COUNT = '\0';
       return true;
}

 

Display the list of generated moves

Now is the time to add the function that displays one move at a time. Since only one move is passed, this function cannot do any disambiguation in the way the move is displayed. Later we will add more fancy move displaying functions, including disambiguation. At least for now this gives us a simple way of checking the move generator.

step 30: displaymove.cpp

#include <iostream>
#include "defines.h"
#include "extglobals.h"
 
void displayMove(Move &move)
{
       // displays a single move on the console, no disambiguation
 
       if ((move.getPiec() == WHITE_KING) && (move.isCastleOO()))
       {
              std::cout << "O-O";
              return;      
       };
       if ((move.getPiec() == WHITE_KING) && (move.isCastleOOO()))
       {
              std::cout << "O-O-O";
              return;      
       };
       if ((move.getPiec() == BLACK_KING) && (move.isCastleOO()))
       {
              std::cout << "O-O";
              return;      
       };
       if ((move.getPiec() == BLACK_KING) && (move.isCastleOOO()))
       {
              std::cout << "O-O-O";
              return;      
       };
 
       if ((move.getPiec() == WHITE_ROOK)   || (move.getPiec() == BLACK_ROOK))   std::cout << "R";
       if ((move.getPiec() == WHITE_BISHOP) || (move.getPiec() == BLACK_BISHOP)) std::cout << "B";
       if ((move.getPiec() == WHITE_KNIGHT) || (move.getPiec() == BLACK_KNIGHT)) std::cout << "N";
       if ((move.getPiec() == WHITE_KING)   || (move.getPiec() == BLACK_KING))   std::cout << "K";
       if ((move.getPiec() == WHITE_QUEEN)  || (move.getPiec() == BLACK_QUEEN))  std::cout << "Q";
       if (((move.getPiec() == WHITE_PAWN)  || (move.getPiec() == BLACK_PAWN)) && move.isCapture())
       {
              if (FILES[move.getFrom()] == 1) std::cout << "a";
              if (FILES[move.getFrom()] == 2) std::cout << "b";
              if (FILES[move.getFrom()] == 3) std::cout << "c";
              if (FILES[move.getFrom()] == 4) std::cout << "d";
              if (FILES[move.getFrom()] == 5) std::cout << "e";
              if (FILES[move.getFrom()] == 6) std::cout << "f";
              if (FILES[move.getFrom()] == 7) std::cout << "g";
              if (FILES[move.getFrom()] == 8) std::cout << "h";
       }
 
       if (move.isCapture()) std::cout << "x" ;
 
       if (FILES[move.getTosq()] == 1) std::cout << "a";
       if (FILES[move.getTosq()] == 2) std::cout << "b";
       if (FILES[move.getTosq()] == 3) std::cout << "c";
       if (FILES[move.getTosq()] == 4) std::cout << "d";
       if (FILES[move.getTosq()] == 5) std::cout << "e";
       if (FILES[move.getTosq()] == 6) std::cout << "f";
       if (FILES[move.getTosq()] == 7) std::cout << "g";
       if (FILES[move.getTosq()] == 8) std::cout << "h";
 
       std::cout << RANKS[move.getTosq()];
 
       if (move.isPromotion())
       {
              if ((move.getProm() == WHITE_ROOK)   || (move.getProm() == BLACK_ROOK))   std::cout << "=R";
              if ((move.getProm() == WHITE_BISHOP) || (move.getProm() == BLACK_BISHOP)) std::cout << "=B";
              if ((move.getProm() == WHITE_KNIGHT) || (move.getProm() == BLACK_KNIGHT)) std::cout << "=N";
              if ((move.getProm() == WHITE_KING)   || (move.getProm() == BLACK_KING))   std::cout << "=K";
              if ((move.getProm() == WHITE_QUEEN)  || (move.getProm() == BLACK_QUEEN))  std::cout << "=Q";
       }
       std::cout.flush();
       return;
}

 Three more functions to add here, movegen, isAttacked and displayMove:

step 31: protos.h

#ifndef WINGLET_PROTOS_H
#define WINGLET_PROTOS_H
 
#include "move.h"
 
unsigned int  bitCnt(BitMap);
void          dataInit();
void          displayBitmap(BitMap);
void          displayMove(Move &);
BOOLTYPE      doCommand(const char *);
unsigned int  firstOne(BitMap);
void          info();
BOOLTYPE      isAttacked(BitMap &, const unsigned char &);
unsigned int  lastOne(BitMap);
int           movegen(int);
void          readCommands();
BOOLTYPE      readFen(char *, int);
void          setup();
void          setupFen(char *, char *, char *, char *, int , int );
 
#endif

 The list of global variables is significantly increased, there are a number of new global bitmaps that are used for move generation:

step 32: globals.h

#ifndef WINGLET_GLOBALS_H
#define WINGLET_GLOBALS_H
 
#include "defines.h"
#include "board.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;
 
#endif

Extglobals.h is updated accordingly, as usual:

step 33: extglobals.h

#ifndef WINGLET_EXTGLOBALS_H
#define WINGLET_EXTGLOBALS_H
 
#include "defines.h"
#include "board.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;
 
int ICAPT;
int IEP;
int IPROM;
int ICASTLOO;
int ICASTLOOO;
int ICHECK;
 
#endif

Finally, we need to define the length of the move buffer array, MAX_MOVE_BUFF:

step 34: defines.h

#ifndef WINGLET_DEFINES_H
#define WINGLET_DEFINES_H
 
#define WINGLET_PROG_VERSION "winglet 0.0, Copyright (C) 2011, Stef Luijten"
 
#define MAX_CMD_BUFF 256     // Console command input buffer
#define MAX_MOV_BUFF 4096    // Number of moves that we can store (all plies)
#define MAX_PLY      64      // Search depth
 
typedef unsigned long long U64;
typedef unsigned long long BitMap;
typedef short SHORTINT;
typedef unsigned short USHORTINT;
typedef int BOOLTYPE;
 
#endif

 

read positions from BT2450.pgn, or set up a position manually, and then type "moves" to see all pseudo-legal moves.
change the side to move, to see the opponent's moves in this position.
try to set up a position that allows for an en-passant capture, or a pawn promotion, or a castling, and then type "moves" to see if that move shows up in the list.
note that illegal moves are also shown, like capturing a king, or leaving a king in check, or castling when the king is in check, or castling when the king passes through, or ends up on, a square that is attacked.

 


Home Previous Top Next

last update: Friday 10 June 2011