working in zig build

This commit is contained in:
k
2025-07-01 02:16:44 -04:00
parent 89e00df712
commit fc32b56a2f
11 changed files with 185 additions and 46 deletions

View File

@@ -56,20 +56,20 @@ int evaluateBoard(game *game) {
}
void makeMove(game *g, move* m) {
long long from_bit = 1LL << m->From;
long long to_bit = 1LL << m->To;
unsigned long long from_bit = 1ULL << m->From;
unsigned long long to_bit = 1ULL << m->To;
long long *set = findSet(g, from_bit);
unsigned long long *set = findSet(g, from_bit);
if (!set)
return;
*set &= ~from_bit;
long long *captured = findSet(g, to_bit);
unsigned long long *captured = findSet(g, to_bit);
if (captured) *captured &= ~to_bit;
if (m->Promo) {
char promoChar = g->whiteToMove ? toupper(m->Promo) : m->Promo;
long long *newSet = charToSet(g, promoChar);
unsigned long long *newSet = charToSet(g, promoChar);
if (newSet)
*newSet |= to_bit;
} else {

View File

@@ -18,7 +18,7 @@ void playMoves(game *g, char *moves);
long long *findSet(game *g, long long bit);
long long *charToSet(game *g, char c);
int main() {
int cmain() {
setbuf(stdin, NULL);
setbuf(stdout, NULL);
game *g = NULL;
@@ -112,7 +112,7 @@ game *fenGame(char *str) {
continue;
}
long long bit = 1LL << (rank * 8 + file);
long long bit = 1ULL << (rank * 8 + file);
long long *set = charToSet(g, *str);
if (set)
*set |= bit;

8
src/main.zig Normal file
View File

@@ -0,0 +1,8 @@
const std = @import("std");
const c = @cImport({
@cInclude("main.h");
});
pub fn main() !void {
_ = c.cmain();
}

View File

@@ -12,7 +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);
long long promo = (0xFFULL) << (g->whiteToMove ? 56 : 0);
int movdir = g->whiteToMove ? 8 : -8;
int capLeft = g->whiteToMove ? 7 : -9;
@@ -21,29 +21,29 @@ int pawnMove(game *g, move *moves) {
size_t index = 0;
for (int i = 0; i < 64; ++i) {
long long bit = 1LL << i;
long long bit = 1ULL << 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))) {
p = (promo & (1ULL << to)) ? 'q' : 0;
if (to >= 0 && to < 64 && !(occupied & (1ULL << 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))) {
p = (promo & (1ULL << to)) ? 'q' : 0;
if (i % 8 > 0 && (to >= 0 && to < 64) && (enemy & (1ULL << 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))) {
p = (promo & (1ULL << to)) ? 'q' : 0;
if (i % 8 < 7 && (to >= 0 && to < 64) && (enemy & (1ULL << to))) {
moves[index++] = (move){.From = i, .To = to, .Promo = p};
}
}
@@ -58,7 +58,7 @@ int knightMove(game *g, move *moves) {
int index = 0;
for (int i = 0; i < 64; i++) {
long long bit = 1LL << i;
long long bit = 1ULL << i;
if (!(knights & bit))
continue;
@@ -78,7 +78,7 @@ int knightMove(game *g, move *moves) {
(fileDiff == 2 && rankDiff == 1)))
continue;
long long destBit = 1LL << to;
long long destBit = 1ULL << to;
if (occupied & destBit)
continue;
@@ -100,7 +100,7 @@ int rookScan(game *g, move *moves, long long w, long long b) {
int index = 0;
for (int i = 0; i < 64; i++) {
long long bit = 1LL << i;
long long bit = 1ULL << i;
int x = i % 8;
int y = i / 8;
if (!(rooks & bit))
@@ -109,7 +109,7 @@ int rookScan(game *g, move *moves, long long w, long long b) {
// fwd
for (int j = y + 1; j < 8; j++) {
int to = (j * 8) + x;
long long lbit = 1LL << to;
long long lbit = 1ULL << to;
if (occupied & lbit)
break;
moves[index++] = (move){.From = i, .To = to, .Promo=0};
@@ -120,7 +120,7 @@ int rookScan(game *g, move *moves, long long w, long long b) {
// bck
for (int j = y - 1; j >= 0; j--) {
int to = (j * 8) + x;
long long lbit = 1LL << to;
long long lbit = 1ULL << to;
if (occupied & lbit)
break;
moves[index++] = (move){.From = i, .To = to, .Promo=0};
@@ -131,7 +131,7 @@ int rookScan(game *g, move *moves, long long w, long long b) {
// rht
for (int j = x + 1; j < 8; j++) {
int to = (y * 8) + j;
long long lbit = 1LL << to;
long long lbit = 1ULL << to;
if (occupied & lbit)
break;
moves[index++] = (move){.From = i, .To = to, .Promo=0};
@@ -142,7 +142,7 @@ int rookScan(game *g, move *moves, long long w, long long b) {
// lft
for (int j = x - 1; j >= 0; j--) {
int to = (y * 8) + j;
long long lbit = 1LL << to;
long long lbit = 1ULL << to;
if (occupied & lbit)
break;
moves[index++] = (move){.From = i, .To = to, .Promo=0};
@@ -158,14 +158,14 @@ int bishopMove(game *g, move *moves) {
}
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 =
unsigned long long bishops = g->whiteToMove ? w : b;
unsigned long long occupied = g->whiteToMove ? fullSet(&g->white) : fullSet(&g->black);
unsigned 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;
unsigned long long bit = 1ULL << i;
int x = i % 8;
int y = i / 8;
@@ -180,7 +180,7 @@ int bishopScan(game *g, move *moves, long long w, long long b) {
break;
int to = (yTo * 8) + xTo;
long long lbit = 1LL << to;
unsigned long long lbit = 1ULL << to;
if (occupied & lbit)
break;
@@ -197,7 +197,7 @@ int bishopScan(game *g, move *moves, long long w, long long b) {
break;
int to = (yTo * 8) + xTo;
long long lbit = 1LL << to;
unsigned long long lbit = 1ULL << to;
if (occupied & lbit)
break;
@@ -214,7 +214,7 @@ int bishopScan(game *g, move *moves, long long w, long long b) {
break;
int to = (yTo * 8) + xTo;
long long lbit = 1LL << to;
unsigned long long lbit = 1ULL << to;
if (occupied & lbit)
break;
@@ -231,7 +231,7 @@ int bishopScan(game *g, move *moves, long long w, long long b) {
break;
int to = (yTo * 8) + xTo;
long long lbit = 1LL << to;
unsigned long long lbit = 1ULL << to;
if (occupied & lbit)
break;
@@ -245,7 +245,7 @@ int bishopScan(game *g, move *moves, long long w, long long b) {
int queenMove(game *g, move *moves){
int size = 0;
long long w,b;
unsigned long long w,b;
w = g->white.queen;
b = g->black.queen;
size += rookScan(g,moves,w,b);
@@ -255,12 +255,12 @@ int queenMove(game *g, move *moves){
int kingMove(game *g, move *moves){
long long king = g->whiteToMove ? g->white.king : g->black.king;
long long occupied = g->whiteToMove ? fullSet(&g->white) : fullSet(&g->black);
unsigned long long king = g->whiteToMove ? g->white.king : g->black.king;
unsigned 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;
unsigned long long bit = 1ULL << i;
int x = i % 8;
int y = i / 8;
int movesX[] = {-1, 0, 1, -1, 1, -1, 0, 1};
@@ -273,7 +273,9 @@ int kingMove(game *g, move *moves){
int toX = x + movesX[j];
int toY = y + movesY[j];
int to = (toY * 8) + toX;
long long destBit = 1LL << to;
if(to > 63 || to < 1)
continue;
unsigned long long destBit = 1ULL << to;
if (toX >= 0 && toX < 8 && toY >= 0 && toY < 8) {
if (!(occupied & destBit)) {