Compare commits

..

No commits in common. "05a0b2b7f12a12066dc28eb38d0b8228083147d6" and "eaaa0ca24dbc6d06233d5ad7ae0e77b030871f63" have entirely different histories.

4 changed files with 50 additions and 27 deletions

View File

@ -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

View File

@ -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);
@ -38,24 +38,32 @@ 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;
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;
}
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;

View File

@ -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) {

View File

@ -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;
}
}