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