Rook movement
This commit is contained in:
parent
bfe9335515
commit
49befc72b6
@ -3,4 +3,5 @@
|
|||||||
#include "types.h"
|
#include "types.h"
|
||||||
int pawnMove(game *g, move *moves);
|
int pawnMove(game *g, move *moves);
|
||||||
int knightMove(game *g, move* moves);
|
int knightMove(game *g, move* moves);
|
||||||
|
int rookMove(game *g, move *moves);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -58,6 +58,7 @@ int main() {
|
|||||||
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));
|
||||||
move *m = &mov[rand() % cnt];
|
move *m = &mov[rand() % cnt];
|
||||||
|
|
||||||
char *end = "";
|
char *end = "";
|
||||||
|
|||||||
71
src/moves.c
71
src/moves.c
@ -4,6 +4,8 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
int rookScan(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;
|
||||||
long long enemy = g->whiteToMove ? fullSet(&g->black) : fullSet(&g->white);
|
long long enemy = g->whiteToMove ? fullSet(&g->black) : fullSet(&g->white);
|
||||||
@ -41,7 +43,6 @@ int pawnMove(game *g, move *moves) {
|
|||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int knightMove(game *g, move *moves) {
|
int knightMove(game *g, move *moves) {
|
||||||
long long knights = g->whiteToMove ? g->white.knights : g->black.knights;
|
long long knights = g->whiteToMove ? g->white.knights : g->black.knights;
|
||||||
long long occupied = g->whiteToMove ? fullSet(&g->white) : fullSet(&g->black);
|
long long occupied = g->whiteToMove ? fullSet(&g->white) : fullSet(&g->black);
|
||||||
@ -75,7 +76,7 @@ int knightMove(game *g, move *moves) {
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
long long destBit = 1LL << to;
|
long long destBit = 1LL << to;
|
||||||
if (occupied & destBit) // Skip if destination has friendly piece
|
if (occupied & destBit)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
moves[index++] = (move){.From = i, .To = to};
|
moves[index++] = (move){.From = i, .To = to};
|
||||||
@ -83,3 +84,69 @@ int knightMove(game *g, move *moves) {
|
|||||||
}
|
}
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int rookMove(game *g, move *moves){
|
||||||
|
return rookScan(g,moves,g->white.rooks,g->black.rooks);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
int index = 0;
|
||||||
|
|
||||||
|
for(int i = 0; i < 64; i++){
|
||||||
|
long long bit = 1LL << i;
|
||||||
|
int x = i % 8;
|
||||||
|
int y = i / 8;
|
||||||
|
if(!(rooks & bit))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
//fwd
|
||||||
|
for(int j = y + 1; j < 8; j++){
|
||||||
|
int to = (j * 8) + x;
|
||||||
|
long long lbit = 1LL << to;
|
||||||
|
if(occupied & lbit)
|
||||||
|
break;
|
||||||
|
moves[index++] = (move){.From = i, .To = to};
|
||||||
|
if(occupiedE & lbit)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
//bck
|
||||||
|
for(int j = y - 1; j >= 0; j--){
|
||||||
|
int to = (j * 8) + x;
|
||||||
|
long long lbit = 1LL << to;
|
||||||
|
if(occupied & lbit)
|
||||||
|
break;
|
||||||
|
moves[index++] = (move){.From = i, .To = to};
|
||||||
|
if(occupiedE & lbit)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
//rht
|
||||||
|
for(int j = x + 1; j < 8; j++){
|
||||||
|
int to = (y * 8) + j;
|
||||||
|
long long lbit = 1LL << to;
|
||||||
|
if(occupied & lbit)
|
||||||
|
break;
|
||||||
|
moves[index++] = (move){.From = i, .To = to};
|
||||||
|
if(occupiedE & lbit)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
//lft
|
||||||
|
for(int j = x - 1; j >= 0; j--){
|
||||||
|
int to = (y * 8) + j;
|
||||||
|
long long lbit = 1LL << to;
|
||||||
|
if(occupied & lbit)
|
||||||
|
break;
|
||||||
|
moves[index++] = (move){.From = i, .To = to};
|
||||||
|
if(occupiedE & lbit)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user