我通过观看这些https://www.youtube.com/watch?v=Bi61lMwhksw&list=PLZ1QII7yudbc-Ky058TEaOstZHVbT-2hg&index=7的youtube讲座来制作国际象棋引擎,但是我得到了未定义的错误,如输出图像所示。我和他一样。
ChessEngine.c主文件
SingleOrder
defs.h,这是我的文件,其中包含所有定义
#include "stdio.h"
#include "defs.h"
extern int Sq120ToSq64[BRD_SQ_NUM];
extern int Sq64ToSq120[64];
int main()
{
AllInit();
int index = 0;
for(index = 0; index < BRD_SQ_NUM; ++index)
{
if(index%10==0) printf("\n");
printf("%5d", Sq120ToSq64[index]);
}
printf("\n");
printf("\n");
for(index=0; index < 64; ++index)
{
if(index%8==0) printf("\n");
printf("%5d",Sq64ToSq120[index]);
}
return 0;
}
init.c
/*All the definitions of the chess engine - ChessEngine.c */
#ifndef DEFS_h
#define DEFS_h
typedef unsigned long long U64;
#define NAME "ChessEngine 1.0"
#define BRD_SQ_NUM 120 /* Board Square Number from 0-119 */
#define MAXGAMEMOVES 2048
enum { EMPTY, wP, wN, wB, wR, wQ, wK, bP, bN, bB, bR, bQ, bK };
enum { FILE_A, FILE_B, FILE_C, FILE_D, FILE_E, FILE_F, FILE_G, FILE_H, FILE_NONE }; /* fILES are A-H */
enum { RANK_1, RANK_2, RANK_3, RANK_4, RANK_5, RANK_6, RANK_7, RANK_8, RANK_NONE}; /* Rank are 1-8*/
enum { WHITE, BLACK, BOTH };
enum{
A1 = 21, B1, C1, D1, E1, F1, G1, H1,
A2 = 31, B2, C2, D2, E2, F2, G2, H2,
A3 = 41, B3, C3, D3, E3, F3, G3, H3,
A4 = 51, B4, C4, D4, E4, F4, G4, H4,
A5 = 61, B5, C5, D5, E5, F5, G5, H5,
A6 = 71, B6, C6, D6, E6, F6, G6, H6,
A7 = 81, B7, C7, D7, E7, F7, G7, H7,
A8 = 91, B8, C8, D8, E8, F8, G8, H8, NO_SQ
};
enum {FALSE, TRUE };
/* For Castling*/
/* WKCA - white king castling, BKCA - black king Castling*/
enum { WKCA=1, WQCA=2, BKCA=4, BQCA=8 }; // 4-bit castling, i.e. 0000
/* Now structure for remembering the history such that undo move is to be achieved*/
typedef struct{
int move;
int castlePerm;
int enPas;
int fiftyMove;
U64 posKey;
} S_UNDO;
typedef struct{
int pieces[BRD_SQ_NUM];
U64 pawns[3]; //00000000
int KingSq[2]; // Square in which kings are placed either (white or black)
int side; // current side to move
int enPas; //set-1, if one is active if not then NO_sq
int fiftyMove; //store fifty move counter hits 50 when the game is drawn
int ply;
int display; //how far half moves have been made
int castlePerm; //Castle Permission
U64 posKey; //for each position
/* Now Defining an array to store the number of pieces on the board */
int pceNum[13]; //piece Number
int bigPce[3];
int majPce[3];
int minPce[3];
S_UNDO history[MAXGAMEMOVES];
} S_BOARD;
/* MACROS */
#define FR2SQ(f,r) ( (21 + (f) ) + ( (r) *10 ) ) //file and rank which returns equivalent square
/* GLOBALS */
extern int Sq120ToSq64[BRD_SQ_NUM];
extern int Sq64ToSq120[64];
/* FUNCTIONS */
extern void AllInit();
// init.c
#endif
我的make文件是:
#include "defs.h"
extern int Sq120ToSq64[BRD_SQ_NUM];
extern int Sq64ToSq120[64];
void InitSq120To64()
{
int index = 0;
int file = FILE_A;
int rank = RANK_1;
int sq = A1;
int sq64 = 0;
for(index = 0; index < BRD_SQ_NUM; ++index)
{
Sq120ToSq64[index] = 65;
}
for(index = 0; index < 64; ++index)
{
Sq64ToSq120[index] = 120;
}
for(rank = RANK_1; rank <= RANK_8; ++rank)
{
for(file = FILE_A; file <= FILE_H; ++file)
{
sq = FR2SQ(file, rank);
Sq64ToSq120[sq64] = sq;
Sq120ToSq64[sq] = sq64;
sq64++;
}
}
}
void AllInit()
{
InitSq120To64();
}