Skip to content

Commit 2e757ac

Browse files
committed
Add BitBoard::to_matrix_and_offset Python method
1 parent 091f432 commit 2e757ac

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

gomori/README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@
22

33
Game logic and tools for writing gomori bots. There is also a crate that implements the main loop for you: [gomori_bot_utils](../gomori_bot_utils).
44

5-
See `cargo doc --open` for documentation. There is also an [online version](https://nnmm.github.io/docs/gomori) (+ for [gomori_bot_utils](https://nnmm.github.io/docs/gomori_bot_utils)), but it is not automatically updated, so might get outdated.
5+
See `cargo doc --open` for documentation. There is also an [online version](https://nnmm.github.io/docs/gomori) (+ for [gomori_bot_utils](https://nnmm.github.io/docs/gomori_bot_utils)), but it is not automatically updated, so might get outdated.
6+
7+
## Debugging
8+
9+
This crate includes a handful of `debug_assert!` calls, so if something is not working right, it is worth compiling in debug mode.

gomori/src/board/bitboard.rs

+11
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,17 @@ mod python {
457457
fn __bool__(&self) -> bool {
458458
!self.is_empty()
459459
}
460+
461+
// Python exclusive
462+
fn to_matrix_and_offset(&self) -> ([[bool; 7]; 7], (i8, i8)) {
463+
let arr = std::array::from_fn(|i_local| {
464+
std::array::from_fn(|j_local| {
465+
let idx = i_local * 7 + j_local;
466+
self.bits & (1u64 << idx) != 0
467+
})
468+
});
469+
(arr, self.offset())
470+
}
460471
}
461472
}
462473

0 commit comments

Comments
 (0)