Skip to content

Commit ca44575

Browse files
committed
Feat: add bitboard print
1 parent 448330b commit ca44575

File tree

4 files changed

+28
-9
lines changed

4 files changed

+28
-9
lines changed

justfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ zig-fmt:
44
run: zig-fmt
55
zig build run
66

7-
run-test: zig-fmt
8-
zig build test --verbose
7+
test: zig-fmt
8+
zig build test --summary all

src/bitboard.zig

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
const std = @import("std");
2-
2+
const util = @import("util.zig");
33
pub fn print_board(bitboard: u64) !void {
44
for (0..8) |rank| {
5+
std.debug.print(" {} ", .{8 - rank});
56
for (0..8) |file| {
67
const square = rank * 8 + file;
8+
const squareEnum = util.Square.fromInt(square);
9+
10+
if (util.get_bit(bitboard, squareEnum)) {
11+
std.debug.print(" 1", .{});
12+
} else {
13+
std.debug.print(" 0", .{});
14+
}
715

8-
std.debug.print("{d}", .{(bitboard >> @enumFromInt(square)) & 1});
16+
std.debug.print(" {d}", .{square});
917
}
1018

1119
std.debug.print("\n", .{});
1220
}
21+
22+
std.debug.print("\n a b c d e f g h\n\n", .{});
23+
std.debug.print(" Bitboard: 0x{0x}\n", .{bitboard});
24+
std.debug.print(" Bitboard: 0b{b}\n\n", .{bitboard});
1325
}

src/main.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const types = @import("types.zig");
44

55
pub fn main() !void {
66
std.debug.print("Hello NeroSpeed.\n", .{});
7-
var bitboard_1: u64 = 1;
8-
bitboard_1 |= 1 << 7;
7+
const bitboard_1: u64 = 0;
8+
std.debug.print("{d}", .{bitboard_1});
99
try bitboard.print_board(bitboard_1);
1010
}

src/util.zig

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
pub inline fn get_bit(bitboard: u64, square: Square) bool {
2-
const mask = @as(u64, 1) << square.toU6();
3-
return (bitboard & mask) != 0;
1+
const std = @import("std");
2+
3+
pub fn get_bit(bitboard: u64, square: u16) bool {
4+
return (bitboard & (1 << square)) != 0;
45
}
6+
7+
pub const Square = enum(u7) {
8+
pub inline fn fromInt(square: usize) Square {
9+
return @enumFromInt(square);
10+
}
11+
};

0 commit comments

Comments
 (0)