added helper functions for move
Some checks failed
Verify build / verify_build (push) Failing after 1m5s
Some checks failed
Verify build / verify_build (push) Failing after 1m5s
This commit is contained in:
parent
7cded275f2
commit
1d41b76fa8
30
src/move.zig
30
src/move.zig
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user