diff --git a/include/chess/bitboard.h b/include/chess/bitboard.h index 1e72b35..b49c2fd 100644 --- a/include/chess/bitboard.h +++ b/include/chess/bitboard.h @@ -3,6 +3,7 @@ #include #define REPETETION_TABLE_LENGTH 1024 +#define START_FEN "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1" bool bitboardGet(const uint_least64_t *board, struct piece_t piece, uint_least8_t i); uint_least64_t bitboardGetMask(const uint_least64_t *board, struct piece_t piece); @@ -13,4 +14,5 @@ void bitboardClear(uint_least64_t *board, struct piece_t piece, uint_least8_t i) void bitboardSet(uint_least64_t *board, struct piece_t piece, uint_least8_t i); struct piece_t pieceAtField(const uint_least64_t *board, uint_least8_t i); struct gameState_t newGameState(uint_least64_t *board, - struct zobristTableElement *repetitionTableStore, char *FEN); + struct zobristTableElement *repetitionTableStore, const char *FEN); +struct gameState_t parseFen(uint_least64_t *board, const char *FEN); diff --git a/src/chess/main.c b/src/chess/main.c index 9a4a015..db72e62 100644 --- a/src/chess/main.c +++ b/src/chess/main.c @@ -12,8 +12,6 @@ #include "evaluate.h" #include -#define START_FEN "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1" - struct drawData_t { RsvgHandle **piecesSvg; struct gameState_t *gameState; diff --git a/src/common/postCodeGen/bitboard.c b/src/common/postCodeGen/bitboard.c index 82b7f34..f1d6d10 100644 --- a/src/common/postCodeGen/bitboard.c +++ b/src/common/postCodeGen/bitboard.c @@ -67,8 +67,11 @@ struct piece_t pieceAtField(const uint_least64_t *board, uint_least8_t i) { } } +struct gameState_t parseFen(uint_least64_t *board, const char *FEN) { +} + struct gameState_t newGameState(uint_least64_t *board, - struct zobristTableElement *repetitionTableStore, char *FEN) { + struct zobristTableElement *repetitionTableStore, const char *FEN) { struct gameState_t gameState = {board, 0}; for(uint_least8_t i = 0; i < BITBOARD_LENGTH; ++i) { board[i] = 0; diff --git a/src/uci.c b/src/uci.c new file mode 100644 index 0000000..f411c8d --- /dev/null +++ b/src/uci.c @@ -0,0 +1,72 @@ +#include "chess/move.h" +#include "chess/types.h" +#include +#include +#include +#include +#include +#include +#include + +atomic_bool searchShouldStop; + +#define customStrCmp(input, cmd) customStrCmpFunc(&(input), cmd, sizeof(cmd)) +static bool customStrCmpFunc(char **input, const char *cmd, const size_t length) { + bool result = strncmp(*input, cmd, length) == 0; + if(result) *input += length + 1; + return result; +} + +int main() { + char input[4096]; + struct gameState_t gameState; + uint_least64_t board[TOTAL_BOARD_SIZE]; + gameState.repetitionTable = (struct zobristTable){NULL}; + initMagicTable(); + while(true) { + char *inputPtr = input; + if(fgets(input, sizeof input, stdin) == NULL) { + perror("Error: reading stdin: "); + continue; + } + if(customStrCmp(inputPtr, "uci")) { + printf( + "id name NoNameChessEngine\n" + "id author MrGeorgen\n" + "uciok\n" + ); + continue; + } + if(customStrCmp(inputPtr, "isready")) { + printf("readyok\n"); + continue; + } + if(customStrCmp(inputPtr, "position")) { + if(gameState.repetitionTable.arr == NULL) { + fprintf(stderr, "Error: required uicnewgame before a position command\n"); + continue; + } + if(customStrCmp(inputPtr, "startpos")) { + gameState = parseFen(board, START_FEN); + continue; + } + if(customStrCmp(inputPtr, "fen")) { + gameState = parseFen(board, inputPtr); + continue; + } + } + if(customStrCmp(inputPtr, "quit")) { + return 0; + } + if(customStrCmp(inputPtr, "go")) { + while(*inputPtr != '\0') { + //if(customStrCmp(inputPtr, "wtime")) + } + continue; + } + if(customStrCmp(inputPtr, "stop")) { + searchShouldStop = true; + continue; + } + } +}