diff --git a/headers/eval.h b/headers/eval.h index 3558b80..06ca2e3 100644 --- a/headers/eval.h +++ b/headers/eval.h @@ -1,5 +1,4 @@ #ifndef EVAL_H #define EVAL_H move *findBest(move* move, size_t size, game* g); -void makeMove(game *g, move* m); #endif diff --git a/src/eval.c b/src/eval.c index d61e69e..5ac2f32 100644 --- a/src/eval.c +++ b/src/eval.c @@ -12,7 +12,7 @@ #define QUEEN_VALUE 900 #define KING_VALUE 20000 #define INF 9000000 -#define MAX_DEPTH 3 +#define MAX_DEPTH 3 // Adjustable depth int evaluateBoard(game *game); void makeMove(game *g, move* m); @@ -37,25 +37,33 @@ move *findBest(move* moves, size_t size, game* g){ } int evaluateBoard(game *game) { - int score = 0; - score += __builtin_popcountll(game->white.pawns) * PAWN_VALUE; - score += __builtin_popcountll(game->white.knights) * KNIGHT_VALUE; - score += __builtin_popcountll(game->white.bishops) * BISHOP_VALUE; - score += __builtin_popcountll(game->white.rooks) * ROOK_VALUE; - score += __builtin_popcountll(game->white.queen) * QUEEN_VALUE; - score += __builtin_popcountll(game->white.king) * KING_VALUE; + int score = 0; - score -= __builtin_popcountll(game->black.pawns) * PAWN_VALUE; - score -= __builtin_popcountll(game->black.knights) * KNIGHT_VALUE; - score -= __builtin_popcountll(game->black.bishops) * BISHOP_VALUE; - score -= __builtin_popcountll(game->black.rooks) * ROOK_VALUE; - score -= __builtin_popcountll(game->black.queen) * QUEEN_VALUE; - score -= __builtin_popcountll(game->black.king) * KING_VALUE; + for (int i = 0; i < 64; ++i) { + long long bit = 1LL << i; + if (game->white.pawns & bit) score += PAWN_VALUE; + else if (game->white.knights & bit) score += KNIGHT_VALUE; + else if (game->white.bishops & bit) score += BISHOP_VALUE; + else if (game->white.rooks & bit) score += ROOK_VALUE; + else if (game->white.queen & bit) score += QUEEN_VALUE; + else if (game->white.king & bit) score += KING_VALUE; + } - return score; + for (int i = 0; i < 64; ++i) { + long long bit = 1LL << i; + if (game->black.pawns & bit) score -= PAWN_VALUE; + else if (game->black.knights & bit) score -= KNIGHT_VALUE; + else if (game->black.bishops & bit) score -= BISHOP_VALUE; + else if (game->black.rooks & bit) score -= ROOK_VALUE; + else if (game->black.queen & bit) score -= QUEEN_VALUE; + else if (game->black.king & bit) score -= KING_VALUE; + } + + return score; } void makeMove(game *g, move* m) { + //should replace inside of PlayMoves but im lazy long long from_bit = 1LL << m->From; long long to_bit = 1LL << m->To; diff --git a/src/help.c b/src/help.c index 3f84553..89ed7d8 100644 --- a/src/help.c +++ b/src/help.c @@ -2,7 +2,7 @@ #include "types.h" long long fullSet(sets *s) { - return s->bishops | s->king | s->knights | s->pawns | s->queen | s->rooks; + return s->bishops ^ s->king ^ s->knights ^ s->pawns ^ s->queen ^ s->rooks; } long long fullSetBoth(game *g) { diff --git a/src/main.c b/src/main.c index fd9aa10..493c5bd 100644 --- a/src/main.c +++ b/src/main.c @@ -53,6 +53,7 @@ int main() { playMoves(g, lineRest); } else if (!strcmp("ucinewgame", token)) { } else if (!strcmp("isready", token)) { + srand(time(NULL)); printf("readyok\n"); } else if (!strcmp("go", token)) { static move mov[1500];//big dumb buffer @@ -121,16 +122,31 @@ game *fenGame(char *str) { } void playMoves(game *g, char *moves) { - char *moveStr; - moveStr = strtok_r(moves, " ", &moves); - moveStr = strtok_r(moves, " ", &moves); - while (moveStr) { - move m; - m.From = (moveStr[0]-'a') + (moveStr[1]-'1')*8; - m.To = (moveStr[2]-'a') + (moveStr[3]-'1')*8; - m.Promo = (strlen(moveStr) == 5) ? moveStr[4] : 0; - makeMove(g, &m); - moveStr = strtok_r(moves, " ", &moves); + char *move; + move = strtok_r(moves, " ", &moves); + move = strtok_r(moves, " ", &moves); + while (move) { + long long bit = 1LL << ((move[1] - '0' - 1) * 8 + (move[0] - 'a')); + long long *set = findSet(g, bit); + if (!set) { + printf("info fuck\n"); + return; + } + *set &= (~bit); + bit = 1LL << ((move[3] - '0' - 1) * 8 + (move[2] - 'a')); + long long *tmp = findSet(g, bit); + if (tmp) + *tmp &= (~bit); + if (strlen(move) == 5) { + char c = move[4]; + if (g->whiteToMove) + c = toupper(c); + set = charToSet(g, c); + } + *set |= bit; + + move = strtok_r(moves, " ", &moves); + g->whiteToMove = !g->whiteToMove; } }