king move
This commit is contained in:
parent
76c69dbf18
commit
9f06b9d86c
@ -5,4 +5,5 @@ int pawnMove(game *g, move *moves);
|
|||||||
int knightMove(game *g, move* moves);
|
int knightMove(game *g, move* moves);
|
||||||
int rookMove(game *g, move *moves);
|
int rookMove(game *g, move *moves);
|
||||||
int bishopMove(game *g, move *moves);
|
int bishopMove(game *g, move *moves);
|
||||||
|
int kingMove(game *g, move *moves);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -54,12 +54,13 @@ int main() {
|
|||||||
srand(time(NULL));
|
srand(time(NULL));
|
||||||
printf("readyok\n");
|
printf("readyok\n");
|
||||||
} else if (!strcmp("go", token)) {
|
} else if (!strcmp("go", token)) {
|
||||||
move mov[1500];//big dumb buffer
|
static move mov[1500];//big dumb buffer
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
cnt += pawnMove(g,mov);
|
cnt += pawnMove(g,mov);
|
||||||
cnt += knightMove(g,(mov+cnt));
|
cnt += knightMove(g,(mov+cnt));
|
||||||
cnt += rookMove(g,(mov+cnt));
|
cnt += rookMove(g,(mov+cnt));
|
||||||
cnt += bishopMove(g,(mov+cnt));
|
cnt += bishopMove(g,(mov+cnt));
|
||||||
|
cnt += kingMove(g,(mov+cnt));
|
||||||
move *m = &mov[rand() % cnt];
|
move *m = &mov[rand() % cnt];
|
||||||
|
|
||||||
char *end = "";
|
char *end = "";
|
||||||
|
|||||||
36
src/moves.c
36
src/moves.c
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
int rookScan(game *g, move *moves, long long w, long long b);
|
int rookScan(game *g, move *moves, long long w, long long b);
|
||||||
int bishopScan(game *g, move *moves, long long w, long long b);
|
int bishopScan(game *g, move *moves, long long w, long long b);
|
||||||
|
int kingScan(game *g, move *moves, long long w, long long b);
|
||||||
|
|
||||||
int pawnMove(game *g, move *moves) {
|
int pawnMove(game *g, move *moves) {
|
||||||
long long pawns = g->whiteToMove ? g->white.pawns : g->black.pawns;
|
long long pawns = g->whiteToMove ? g->white.pawns : g->black.pawns;
|
||||||
@ -236,3 +237,38 @@ int bishopScan(game *g, move *moves, long long w, long long b) {
|
|||||||
}
|
}
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int kingMove(game *g, move *moves){
|
||||||
|
return kingScan(g,moves,g->white.king,g->black.king);
|
||||||
|
}
|
||||||
|
|
||||||
|
int kingScan(game *g, move *moves, long long w, long long b) {
|
||||||
|
long long king = g->whiteToMove ? w : b;
|
||||||
|
long long occupied = g->whiteToMove ? fullSet(&g->white) : fullSet(&g->black);
|
||||||
|
int index = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < 64; i++){
|
||||||
|
long long bit = 1LL << i;
|
||||||
|
int x = i % 8;
|
||||||
|
int y = i / 8;
|
||||||
|
int movesX[] = {-1, 0, 1, -1, 1, -1, 0, 1};
|
||||||
|
int movesY[] = {-1, -1, -1, 0, 0, 1, 1, 1};
|
||||||
|
|
||||||
|
if(!(king & bit))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
for (int j = 0; j < 8; ++j) {
|
||||||
|
int toX = x + movesX[j];
|
||||||
|
int toY = y + movesY[j];
|
||||||
|
int to = (toY * 8) + toX;
|
||||||
|
long long destBit = 1LL << to;
|
||||||
|
|
||||||
|
if (toX >= 0 && toX < 8 && toY >= 0 && toY < 8) {
|
||||||
|
if (!(occupied & destBit)) {
|
||||||
|
moves[index++] = (move){.From = i, .To = to};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user