bishop move + moves format
This commit is contained in:
parent
49befc72b6
commit
76c69dbf18
@ -4,4 +4,5 @@
|
|||||||
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);
|
int rookMove(game *g, move *moves);
|
||||||
|
int bishopMove(game *g, move *moves);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -59,6 +59,7 @@ int main() {
|
|||||||
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));
|
||||||
move *m = &mov[rand() % cnt];
|
move *m = &mov[rand() % cnt];
|
||||||
|
|
||||||
char *end = "";
|
char *end = "";
|
||||||
|
|||||||
150
src/moves.c
150
src/moves.c
@ -1,10 +1,11 @@
|
|||||||
#include "types.h"
|
|
||||||
#include "moves.h"
|
#include "moves.h"
|
||||||
#include "help.h"
|
#include "help.h"
|
||||||
|
#include "types.h"
|
||||||
#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 rookScan(game *g, move *moves, long long w, long long b);
|
||||||
|
int bishopScan(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;
|
||||||
@ -47,12 +48,7 @@ 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);
|
||||||
|
|
||||||
int kMoves[] = {
|
int kMoves[] = {-17, -15, -10, -6, 6, 10, 15, 17};
|
||||||
-17, -15,
|
|
||||||
-10, -6,
|
|
||||||
6, 10,
|
|
||||||
15, 17
|
|
||||||
};
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
||||||
for (int i = 0; i < 64; i++) {
|
for (int i = 0; i < 64; i++) {
|
||||||
@ -72,7 +68,8 @@ int knightMove(game *g, move *moves) {
|
|||||||
|
|
||||||
int fileDiff = abs(fromFile - toFile);
|
int fileDiff = abs(fromFile - toFile);
|
||||||
int rankDiff = abs(fromRank - toRank);
|
int rankDiff = abs(fromRank - toRank);
|
||||||
if (!((fileDiff == 1 && rankDiff == 2) || (fileDiff == 2 && rankDiff == 1)))
|
if (!((fileDiff == 1 && rankDiff == 2) ||
|
||||||
|
(fileDiff == 2 && rankDiff == 1)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
long long destBit = 1LL << to;
|
long long destBit = 1LL << to;
|
||||||
@ -85,68 +82,157 @@ int knightMove(game *g, move *moves) {
|
|||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int rookMove(game *g, move *moves) {
|
||||||
int rookMove(game *g, move *moves){
|
return rookScan(g, moves, g->white.rooks, g->black.rooks);
|
||||||
return rookScan(g,moves,g->white.rooks,g->black.rooks);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int rookScan(game *g, move *moves,long long w, long long b){
|
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 = !g->whiteToMove ? fullSet(&g->white) : fullSet(&g->black);
|
long long occupiedE =
|
||||||
|
!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++) {
|
||||||
long long bit = 1LL << i;
|
long long bit = 1LL << i;
|
||||||
int x = i % 8;
|
int x = i % 8;
|
||||||
int y = i / 8;
|
int y = i / 8;
|
||||||
if(!(rooks & bit))
|
if (!(rooks & bit))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
//fwd
|
// fwd
|
||||||
for(int j = y + 1; j < 8; j++){
|
for (int j = y + 1; j < 8; j++) {
|
||||||
int to = (j * 8) + x;
|
int to = (j * 8) + x;
|
||||||
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};
|
||||||
if(occupiedE & lbit)
|
if (occupiedE & lbit)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
//bck
|
// bck
|
||||||
for(int j = y - 1; j >= 0; j--){
|
for (int j = y - 1; j >= 0; j--) {
|
||||||
int to = (j * 8) + x;
|
int to = (j * 8) + x;
|
||||||
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};
|
||||||
if(occupiedE & lbit)
|
if (occupiedE & lbit)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
//rht
|
// rht
|
||||||
for(int j = x + 1; j < 8; j++){
|
for (int j = x + 1; j < 8; j++) {
|
||||||
int to = (y * 8) + j;
|
int to = (y * 8) + j;
|
||||||
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};
|
||||||
if(occupiedE & lbit)
|
if (occupiedE & lbit)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
//lft
|
// lft
|
||||||
for(int j = x - 1; j >= 0; j--){
|
for (int j = x - 1; j >= 0; j--) {
|
||||||
int to = (y * 8) + j;
|
int to = (y * 8) + j;
|
||||||
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};
|
||||||
if(occupiedE & lbit)
|
if (occupiedE & lbit)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int bishopMove(game *g, move *moves) {
|
||||||
|
return bishopScan(g, moves, g->white.bishops, g->black.bishops);
|
||||||
|
}
|
||||||
|
|
||||||
|
int bishopScan(game *g, move *moves, long long w, long long b) {
|
||||||
|
long long bishops = 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 (!(bishops & bit))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// ur
|
||||||
|
for (int j = 1;; j++) {
|
||||||
|
int xTo = x + j;
|
||||||
|
int yTo = y + j;
|
||||||
|
if (xTo >= 8 || yTo >= 8)
|
||||||
|
break;
|
||||||
|
|
||||||
|
int to = (yTo * 8) + xTo;
|
||||||
|
long long lbit = 1LL << to;
|
||||||
|
|
||||||
|
if (occupied & lbit)
|
||||||
|
break;
|
||||||
|
moves[index++] = (move){.From = i, .To = to};
|
||||||
|
if (occupiedE & lbit)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ul
|
||||||
|
for (int j = 1;; j++) {
|
||||||
|
int xTo = x - j;
|
||||||
|
int yTo = y + j;
|
||||||
|
if (xTo < 0 || yTo >= 8)
|
||||||
|
break;
|
||||||
|
|
||||||
|
int to = (yTo * 8) + xTo;
|
||||||
|
long long lbit = 1LL << to;
|
||||||
|
|
||||||
|
if (occupied & lbit)
|
||||||
|
break;
|
||||||
|
moves[index++] = (move){.From = i, .To = to};
|
||||||
|
if (occupiedE & lbit)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// dr
|
||||||
|
for (int j = 1;; j++) {
|
||||||
|
int xTo = x + j;
|
||||||
|
int yTo = y - j;
|
||||||
|
if (xTo >= 8 || yTo < 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
int to = (yTo * 8) + xTo;
|
||||||
|
long long lbit = 1LL << to;
|
||||||
|
|
||||||
|
if (occupied & lbit)
|
||||||
|
break;
|
||||||
|
moves[index++] = (move){.From = i, .To = to};
|
||||||
|
if (occupiedE & lbit)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// dl
|
||||||
|
for (int j = 1;; j++) {
|
||||||
|
int xTo = x - j;
|
||||||
|
int yTo = y - j;
|
||||||
|
if (xTo < 0 || yTo < 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
int to = (yTo * 8) + xTo;
|
||||||
|
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