Improved promotion
This commit is contained in:
parent
5dd8f04286
commit
9534803a60
@ -20,6 +20,7 @@ typedef struct {
|
||||
typedef struct {
|
||||
int From;
|
||||
int To;
|
||||
char Promo;
|
||||
} move;
|
||||
|
||||
#endif
|
||||
|
||||
@ -27,7 +27,8 @@ int main() {
|
||||
char ltz[] = "abcdefgh";
|
||||
int cnt = 0;
|
||||
while (1) {
|
||||
(void)fgets(line, sizeof(line), stdin);
|
||||
if(!fgets(line, sizeof(line), stdin))
|
||||
return 0;
|
||||
size_t len = strlen(line);
|
||||
if (len - 1)
|
||||
line[len - 1] = '\0';
|
||||
@ -72,7 +73,7 @@ int main() {
|
||||
yFrom = m->From / 8 + 1;
|
||||
|
||||
long long bit = 1LL << m->From;
|
||||
if (((g->whiteToMove && yTo == 8) || (!g->whiteToMove && yTo == 1)) && ((findSet(g,bit) == &g->white.pawns) || (findSet(g,bit) == &g->black.pawns))) {
|
||||
if (m->Promo) {
|
||||
end = "q\n";
|
||||
} else {
|
||||
end = "\n";
|
||||
|
||||
33
src/moves.c
33
src/moves.c
@ -12,6 +12,7 @@ int pawnMove(game *g, move *moves) {
|
||||
long long pawns = g->whiteToMove ? g->white.pawns : g->black.pawns;
|
||||
long long enemy = g->whiteToMove ? fullSet(&g->black) : fullSet(&g->white);
|
||||
long long occupied = fullSetBoth(g);
|
||||
long long promo = (0xFFLL) << (g->whiteToMove ? 56 : 0);
|
||||
|
||||
int movdir = g->whiteToMove ? 8 : -8;
|
||||
int capLeft = g->whiteToMove ? 7 : -9;
|
||||
@ -21,25 +22,29 @@ int pawnMove(game *g, move *moves) {
|
||||
|
||||
for (int i = 0; i < 64; ++i) {
|
||||
long long bit = 1LL << i;
|
||||
char p = 0;
|
||||
if (!(pawns & bit))
|
||||
continue;
|
||||
|
||||
// forword
|
||||
int to = i + movdir;
|
||||
p = (promo & (1LL << to)) ? 'q' : 0;
|
||||
if (to >= 0 && to < 64 && !(occupied & (1LL << to))) {
|
||||
moves[index++] = (move){.From = i, .To = to};
|
||||
moves[index++] = (move){.From = i, .To = to, .Promo = p};
|
||||
}
|
||||
|
||||
// left
|
||||
to = i + capLeft;
|
||||
p = (promo & (1LL << to)) ? 'q' : 0;
|
||||
if (i % 8 > 0 && (to >= 0 && to < 64) && (enemy & (1LL << to))) {
|
||||
moves[index++] = (move){.From = i, .To = to};
|
||||
moves[index++] = (move){.From = i, .To = to, .Promo = p};
|
||||
}
|
||||
|
||||
// right
|
||||
to = i + capRight;
|
||||
p = (promo & (1LL << to)) ? 'q' : 0;
|
||||
if (i % 8 < 7 && (to >= 0 && to < 64) && (enemy & (1LL << to))) {
|
||||
moves[index++] = (move){.From = i, .To = to};
|
||||
moves[index++] = (move){.From = i, .To = to, .Promo = p};
|
||||
}
|
||||
}
|
||||
return index;
|
||||
@ -77,7 +82,7 @@ int knightMove(game *g, move *moves) {
|
||||
if (occupied & destBit)
|
||||
continue;
|
||||
|
||||
moves[index++] = (move){.From = i, .To = to};
|
||||
moves[index++] = (move){.From = i, .To = to, .Promo=0};
|
||||
}
|
||||
}
|
||||
return index;
|
||||
@ -91,7 +96,7 @@ int rookScan(game *g, move *moves, long long w, long long b) {
|
||||
long long rooks = g->whiteToMove ? w : b;
|
||||
long long occupied = g->whiteToMove ? fullSet(&g->white) : fullSet(&g->black);
|
||||
long long occupiedE =
|
||||
!g->whiteToMove ? fullSet(&g->white) : fullSet(&g->black);
|
||||
!g->whiteToMove ? fullSet(&g->white) : fullSet(&g->black);
|
||||
int index = 0;
|
||||
|
||||
for (int i = 0; i < 64; i++) {
|
||||
@ -107,7 +112,7 @@ int rookScan(game *g, move *moves, long long w, long long b) {
|
||||
long long lbit = 1LL << to;
|
||||
if (occupied & lbit)
|
||||
break;
|
||||
moves[index++] = (move){.From = i, .To = to};
|
||||
moves[index++] = (move){.From = i, .To = to, .Promo=0};
|
||||
if (occupiedE & lbit)
|
||||
break;
|
||||
}
|
||||
@ -118,7 +123,7 @@ int rookScan(game *g, move *moves, long long w, long long b) {
|
||||
long long lbit = 1LL << to;
|
||||
if (occupied & lbit)
|
||||
break;
|
||||
moves[index++] = (move){.From = i, .To = to};
|
||||
moves[index++] = (move){.From = i, .To = to, .Promo=0};
|
||||
if (occupiedE & lbit)
|
||||
break;
|
||||
}
|
||||
@ -129,7 +134,7 @@ int rookScan(game *g, move *moves, long long w, long long b) {
|
||||
long long lbit = 1LL << to;
|
||||
if (occupied & lbit)
|
||||
break;
|
||||
moves[index++] = (move){.From = i, .To = to};
|
||||
moves[index++] = (move){.From = i, .To = to, .Promo=0};
|
||||
if (occupiedE & lbit)
|
||||
break;
|
||||
}
|
||||
@ -140,7 +145,7 @@ int rookScan(game *g, move *moves, long long w, long long b) {
|
||||
long long lbit = 1LL << to;
|
||||
if (occupied & lbit)
|
||||
break;
|
||||
moves[index++] = (move){.From = i, .To = to};
|
||||
moves[index++] = (move){.From = i, .To = to, .Promo=0};
|
||||
if (occupiedE & lbit)
|
||||
break;
|
||||
}
|
||||
@ -179,7 +184,7 @@ int bishopScan(game *g, move *moves, long long w, long long b) {
|
||||
|
||||
if (occupied & lbit)
|
||||
break;
|
||||
moves[index++] = (move){.From = i, .To = to};
|
||||
moves[index++] = (move){.From = i, .To = to, .Promo=0};
|
||||
if (occupiedE & lbit)
|
||||
break;
|
||||
}
|
||||
@ -196,7 +201,7 @@ int bishopScan(game *g, move *moves, long long w, long long b) {
|
||||
|
||||
if (occupied & lbit)
|
||||
break;
|
||||
moves[index++] = (move){.From = i, .To = to};
|
||||
moves[index++] = (move){.From = i, .To = to, .Promo=0};
|
||||
if (occupiedE & lbit)
|
||||
break;
|
||||
}
|
||||
@ -213,7 +218,7 @@ int bishopScan(game *g, move *moves, long long w, long long b) {
|
||||
|
||||
if (occupied & lbit)
|
||||
break;
|
||||
moves[index++] = (move){.From = i, .To = to};
|
||||
moves[index++] = (move){.From = i, .To = to, .Promo=0};
|
||||
if (occupiedE & lbit)
|
||||
break;
|
||||
}
|
||||
@ -230,7 +235,7 @@ int bishopScan(game *g, move *moves, long long w, long long b) {
|
||||
|
||||
if (occupied & lbit)
|
||||
break;
|
||||
moves[index++] = (move){.From = i, .To = to};
|
||||
moves[index++] = (move){.From = i, .To = to, .Promo=0};
|
||||
if (occupiedE & lbit)
|
||||
break;
|
||||
}
|
||||
@ -272,7 +277,7 @@ int kingMove(game *g, move *moves){
|
||||
|
||||
if (toX >= 0 && toX < 8 && toY >= 0 && toY < 8) {
|
||||
if (!(occupied & destBit)) {
|
||||
moves[index++] = (move){.From = i, .To = to};
|
||||
moves[index++] = (move){.From = i, .To = to, .Promo=0};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user