Skip to content

Commit

Permalink
Add BitBoard::to_matrix_and_offset Python method
Browse files Browse the repository at this point in the history
  • Loading branch information
nnmm committed Jul 26, 2024
1 parent 091f432 commit 2e757ac
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion gomori/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@

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).

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.
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.

## Debugging

This crate includes a handful of `debug_assert!` calls, so if something is not working right, it is worth compiling in debug mode.
11 changes: 11 additions & 0 deletions gomori/src/board/bitboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,17 @@ mod python {
fn __bool__(&self) -> bool {
!self.is_empty()
}

// Python exclusive
fn to_matrix_and_offset(&self) -> ([[bool; 7]; 7], (i8, i8)) {
let arr = std::array::from_fn(|i_local| {
std::array::from_fn(|j_local| {
let idx = i_local * 7 + j_local;
self.bits & (1u64 << idx) != 0
})
});
(arr, self.offset())
}
}
}

Expand Down

0 comments on commit 2e757ac

Please sign in to comment.