added helper functions for move
Some checks failed
Verify build / verify_build (push) Failing after 1m5s

This commit is contained in:
k 2025-10-21 19:18:41 -04:00
parent 7cded275f2
commit 1d41b76fa8

View File

@ -35,6 +35,36 @@ pub fn playMoves(game: *types.game, str: []const u8) *types.game {
return game;
}
pub fn charToSet(g: *types.game, chr: u8) *u64 {
return switch (chr) {
'P' => &g.white.pawns,
'N' => &g.white.knights,
'B' => &g.white.bishops,
'R' => &g.white.rooks,
'Q' => &g.white.queen,
'K' => &g.white.king,
'p' => &g.black.pawns,
'n' => &g.black.knights,
'b' => &g.black.bishops,
'r' => &g.black.rooks,
'q' => &g.black.queen,
'k' => &g.black.king,
else => {
std.log.err("you should not be here ${c}$", .{chr});
unreachable;
},
};
}
// pub fn pawnMove(arr: std.ArrayList(c.move)) void {
// const move = c.move{ .From = 8, .To = 16, .Promo = 0 };
// }
fn bitboardToMoves(start: u8, moves: u64, arr: *std.ArrayList(types.move)) void {
var lmoves = moves;
while (lmoves != 0) {
const pos = @ctz(lmoves);
const m: types.move = .{ .From = start, .Promo = 0, .To = pos };
lmoves = lmoves & ~@as(u64, 1) << @truncate(pos);
arr.append(m) catch unreachable;
}
}