knightMove runtime should be working
All checks were successful
Verify build / verify_build (push) Successful in 1m15s
All checks were successful
Verify build / verify_build (push) Successful in 1m15s
This commit is contained in:
parent
ded1566f53
commit
94b501fd17
26
src/move.zig
26
src/move.zig
@ -59,6 +59,32 @@ pub fn charToSet(g: *types.game, chr: u8) *u64 {
|
||||
// pub fn pawnMove(arr: std.ArrayList(c.move)) void {
|
||||
// const move = c.move{ .From = 8, .To = 16, .Promo = 0 };
|
||||
// }
|
||||
|
||||
pub fn knightMove(g: *types.game, arr: *std.ArrayList(types.move)) void {
|
||||
const moveLut: [64]u64 = comptime blk: {
|
||||
var value: [64]u64 = undefined;
|
||||
for (0..64) |i| {
|
||||
value[i] = knightCalc(@truncate(i));
|
||||
}
|
||||
break :blk value;
|
||||
};
|
||||
const set = if (g.whiteToMove) &g.white.knights else &g.black.knights;
|
||||
const fset: u64 = if (g.whiteToMove) @as(u64, c.fullSet(@ptrCast(&g.white))) else @as(u64, c.fullSet(@ptrCast(&g.black)));
|
||||
var val = set.*; //local copy
|
||||
const n = @popCount(val);
|
||||
for (0..n) |_| {
|
||||
const pos = @ctz(val);
|
||||
const moves = moveLut[pos] & ~fset;
|
||||
val = val ^ (@as(u64, 1) << @truncate(pos));
|
||||
bitboardToMoves(pos, moves, arr);
|
||||
}
|
||||
}
|
||||
|
||||
fn knightCalc(index: u8) u64 {
|
||||
_ = index;
|
||||
return @as(u64,1)<<32;
|
||||
}
|
||||
|
||||
fn bitboardToMoves(start: u8, moves: u64, arr: *std.ArrayList(types.move)) void {
|
||||
var lmoves = moves;
|
||||
while (lmoves != 0) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user