Compare commits
2 Commits
eaaa0ca24d
...
05a0b2b7f1
| Author | SHA1 | Date | |
|---|---|---|---|
| 05a0b2b7f1 | |||
| e1fe8ee603 |
@ -1,4 +1,5 @@
|
|||||||
#ifndef EVAL_H
|
#ifndef EVAL_H
|
||||||
#define EVAL_H
|
#define EVAL_H
|
||||||
move *findBest(move* move, size_t size, game* g);
|
move *findBest(move* move, size_t size, game* g);
|
||||||
|
void makeMove(game *g, move* m);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
34
src/eval.c
34
src/eval.c
@ -12,7 +12,7 @@
|
|||||||
#define QUEEN_VALUE 900
|
#define QUEEN_VALUE 900
|
||||||
#define KING_VALUE 20000
|
#define KING_VALUE 20000
|
||||||
#define INF 9000000
|
#define INF 9000000
|
||||||
#define MAX_DEPTH 3 // Adjustable depth
|
#define MAX_DEPTH 3
|
||||||
|
|
||||||
int evaluateBoard(game *game);
|
int evaluateBoard(game *game);
|
||||||
void makeMove(game *g, move* m);
|
void makeMove(game *g, move* m);
|
||||||
@ -38,32 +38,24 @@ move *findBest(move* moves, size_t size, game* g){
|
|||||||
|
|
||||||
int evaluateBoard(game *game) {
|
int evaluateBoard(game *game) {
|
||||||
int score = 0;
|
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;
|
||||||
|
|
||||||
for (int i = 0; i < 64; ++i) {
|
score -= __builtin_popcountll(game->black.pawns) * PAWN_VALUE;
|
||||||
long long bit = 1LL << i;
|
score -= __builtin_popcountll(game->black.knights) * KNIGHT_VALUE;
|
||||||
if (game->white.pawns & bit) score += PAWN_VALUE;
|
score -= __builtin_popcountll(game->black.bishops) * BISHOP_VALUE;
|
||||||
else if (game->white.knights & bit) score += KNIGHT_VALUE;
|
score -= __builtin_popcountll(game->black.rooks) * ROOK_VALUE;
|
||||||
else if (game->white.bishops & bit) score += BISHOP_VALUE;
|
score -= __builtin_popcountll(game->black.queen) * QUEEN_VALUE;
|
||||||
else if (game->white.rooks & bit) score += ROOK_VALUE;
|
score -= __builtin_popcountll(game->black.king) * KING_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;
|
return score;
|
||||||
}
|
}
|
||||||
|
|
||||||
void makeMove(game *g, move* m) {
|
void makeMove(game *g, move* m) {
|
||||||
//should replace inside of PlayMoves but im lazy
|
|
||||||
long long from_bit = 1LL << m->From;
|
long long from_bit = 1LL << m->From;
|
||||||
long long to_bit = 1LL << m->To;
|
long long to_bit = 1LL << m->To;
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
long long fullSet(sets *s) {
|
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) {
|
long long fullSetBoth(game *g) {
|
||||||
|
|||||||
36
src/main.c
36
src/main.c
@ -53,7 +53,6 @@ int main() {
|
|||||||
playMoves(g, lineRest);
|
playMoves(g, lineRest);
|
||||||
} else if (!strcmp("ucinewgame", token)) {
|
} else if (!strcmp("ucinewgame", token)) {
|
||||||
} else if (!strcmp("isready", token)) {
|
} else if (!strcmp("isready", token)) {
|
||||||
srand(time(NULL));
|
|
||||||
printf("readyok\n");
|
printf("readyok\n");
|
||||||
} else if (!strcmp("go", token)) {
|
} else if (!strcmp("go", token)) {
|
||||||
static move mov[1500];//big dumb buffer
|
static move mov[1500];//big dumb buffer
|
||||||
@ -122,31 +121,16 @@ game *fenGame(char *str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void playMoves(game *g, char *moves) {
|
void playMoves(game *g, char *moves) {
|
||||||
char *move;
|
char *moveStr;
|
||||||
move = strtok_r(moves, " ", &moves);
|
moveStr = strtok_r(moves, " ", &moves);
|
||||||
move = strtok_r(moves, " ", &moves);
|
moveStr = strtok_r(moves, " ", &moves);
|
||||||
while (move) {
|
while (moveStr) {
|
||||||
long long bit = 1LL << ((move[1] - '0' - 1) * 8 + (move[0] - 'a'));
|
move m;
|
||||||
long long *set = findSet(g, bit);
|
m.From = (moveStr[0]-'a') + (moveStr[1]-'1')*8;
|
||||||
if (!set) {
|
m.To = (moveStr[2]-'a') + (moveStr[3]-'1')*8;
|
||||||
printf("info fuck\n");
|
m.Promo = (strlen(moveStr) == 5) ? moveStr[4] : 0;
|
||||||
return;
|
makeMove(g, &m);
|
||||||
}
|
moveStr = strtok_r(moves, " ", &moves);
|
||||||
*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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user