Commit graph

47 commits

Author SHA1 Message Date
4b148529a1 [bitboard] Fix the warning about shared references to mutable static data
I've lived with this warning for a long time because I didn't really understand
it.

```
warning: `chessfriend_core` (lib) generated 1 warning (run `cargo fix --lib -p chessfriend_core` to apply 1 suggestion)
warning: creating a shared reference to mutable static is discouraged
  --> bitboard/src/library.rs:66:9
```

I was able to fix this by creating a new type with a single OnceLock attribute.
The OnceLock acts as a cell, making it mutable, even if self is not. So, you can
declare the MoveLibraryWrapper non-mutable static, but still initialize the
library inside the Cell.
2025-06-08 17:34:42 -07:00
bba910090c [bitboard] Specify array lengths with ::NUM values from core types
These were static bare integer values. Use ::NUM properties of various core types
instead.
2025-06-07 20:53:41 -07:00
f005d94fc2 [bitboard, board, core, moves] Implement SliderMoveGenerator
This generator produces moves for slider pieces: bishops, rooks, and queens. All
of these pieces behave identically, though with different sets of rays that
emanate from the origin square. Claude helped me significantly with the
implementation and unit testing. All the unit tests that took advantage of Claude
for implementation are marked as such with an _ai_claude suffix to the test name.

One unique aspect of this move generator that Claude suggested to me was to use
loop { } instead of a recursive call to next() when the internal iterators expire.
I may try to port this to the other move generators in the future.

To support this move generator, implement a Slider enum in core that represents
one of the three slider pieces.

Add Board::bishops(), Board::rooks() and Board::queens() to return BitBoards of
those pieces. These are analogous to the pawns() and knights() methods that return
their corresponding pieces.

Also in the board create, replace the separate sight method implementations with
a macro. These are all the same, but with a different sight method called under
the hood.

Finally, derive Clone and Debug for the bit_scanner types.
2025-05-26 17:41:43 -07:00
c02f0170b9 [bitboard] Export the bit_scanner module
Clients can access TrailingBitScanner and LeadingBitScanner directly now.
2025-05-23 18:38:15 -07:00
3684e9b425 [board, core, bitboard] Clean up casts between Rank, File and BitBoard
Let BitBoard::rank and BitBoard::file take a Rank and File directly, instead of a
u8 by reference. And then make the Rank/File::as_index const and return a value
rather than a reference.

All this allows you to convert between Rank, File, and BitBoard at compile tile
(i.e. as a const method) rather than needing to do runtime stuff.
2025-05-23 18:32:18 -07:00
9943224ee0 [bitboard] Add separators to the NOT_A_FILE and NOT_H_FILE constants
This is a clippy suggestion.
2025-05-16 07:44:59 -07:00
e5a5367864 [bitboard] Remove leading underscore from leading_zeros and trailing_zeros methods
This is a clippy suggestion.
2025-05-16 07:44:37 -07:00
184e81a7c8 [bitboard] Remove #[must_use] from method calls; add it to BitBoard type 2025-05-16 07:44:05 -07:00
091cc99cb3 WIP 2025-05-08 17:37:51 -07:00
d5cdf273c8 [bitboard] Fix some random clippy issues 2025-05-03 16:03:18 -07:00
7b0469d689 [bitboard] Replace separate methods for leading and trailing iteration
Add chessfriend_bitboard::IterationDirection
Make BitBoard::occupied_squares() take an IterationDirection and return an iterator
corresponding to the direction.
Do the same for ::first_occupied_square().
2025-05-02 14:28:31 -07:00
9f62996175 [bitboard] Return a copy of a BitBoard from BitBoard::ray() 2025-05-02 14:28:31 -07:00
53c637f424 [bitboard] Make BitBoard::EMPTY and BitBoard::FULL private; export BitBoard::full() 2025-05-02 14:23:29 -07:00
ee51a13870 Rename Square::from_index → from_index_unchecked 2024-07-13 08:10:21 -07:00
7e45e49502 [BitBoard] Build out the documentation 2024-07-13 07:20:18 -07:00
daf5c86792 [BitBoard] Clean up the API; implement some traits
Clean up the BitBoard API by renaming methods with simpler names.
run-help Redo
Redo the implementation of a couple methods to be more succinct.
2024-07-13 07:19:47 -07:00
480a009e63 [BitBoard] Address a bunch of rust-analyzer suggestions
Add #[must_use] to many methods
2024-07-13 07:17:43 -07:00
14ab669763 Clean up BitBoard's bit ops impl macros
Declare the `forward_ref` crate as a dependency (my first external dependency!)
and use it to clean up the infix, assign, and unary op impls. This crate
automatically implements A+&B, &A+B, and &A+&B for me.
2024-07-13 07:08:18 -07:00
2480ef25e9 Remove BitBoardBuilder
It's unused except for the macro, and BitBoard itself can be declared mutable,
and implements Copy and Clone. So, I don't think having a separate Builder type
helps much.
2024-07-13 07:05:57 -07:00
1b63f56042 [bitboard, core] Make library getters const; parameterize Library attributes
- Add chessfriend_core::Color::NUM
- All the library getters can be const.
- Use the constants from the core library to define the length of the slices in
  the Library struct.
2024-04-25 07:59:39 -07:00
cad040e454 [bitboard] Fix some warnings and clippy suggestions in library.rs
- Add allow(dead_code) to LIGHT_SQUARES and DARK_SQUARES. These aren't used yet
  but I have a feeling they'll come in handy.
- Add some separators to long numeric literals.
- Lightly reformat BitBoard -> Bitboard in the module documentation
2024-04-25 07:23:59 -07:00
27a36565f3 [bitboard,core,position] Address a bunch of clippy warnings 2024-03-14 17:00:46 -07:00
3f6ffef9f3 [bitboard] Write some documentation; mark some methods const
- Implement BitBoard::is_populated(), the opposite of ::is_empty()
- Write a bit of documentation for the BitBoard Library and for some methods on BitBoard
- Mark a few methods as const
2024-03-08 08:15:45 -08:00
349d82304d [bitboard] Implement From<Option<Square>> for BitBoard
Return an empty BitBoard if the input is None.
2024-03-01 15:25:33 -08:00
742b00119a [bitboard] Implement From<File>, From<Rank> for BitBoard and TryFrom<BitBoard> for Square 2024-02-11 09:58:06 -07:00
997621eea7 [bitboard] Make a few tweaks to some definitions in BitBoard
Use u64::MIN and u64::MAX to define the empty and full bitboards
Write From<Square> as `1u64 << sq as u32`
Write a doc test for BitBoard::is_single_square()
Make library::RANKS and library::FILES pub(crate) instead of pub(super)
2024-02-11 09:58:06 -07:00
a8034c79aa [bitboard] Use a OnceLock to hold the global BitBoard library instance
Thread safe and a single object instead of two!
2024-02-05 13:59:26 -08:00
032fabe072 [bitboard] Return BitBoard::EMPTY from BitBoard's Default impl 2024-02-01 08:45:10 -08:00
ca861df9c4 [bitboard] Use TrailingBitScanner in occupied_squares_trailing
This was an oversight.
2024-02-01 08:44:53 -08:00
deea23352b [bitboard] Implement BitBoard::population_count()
Uses u64::count_ones() to return the population count of the BitBoard.
2024-02-01 08:44:25 -08:00
722a90b860 [position] Implement a SliderRayToSquare trait
This trait declares ray_to_square() which should return a BitBoard representing
a ray from a Square to another Square. The ray should include the target Square.

PlacedPiece implements this trait.
2024-02-01 08:42:19 -08:00
b93f8684fa [position] Plumb capture mask and push mask arguments through all move generators
These masks will help when generating moves that address checks.
Create BitBoard::EMPTY and BitBoard::FULL.
2024-01-29 20:12:12 -08:00
3239f288d7 [bitboard] Bitboards for kingside and queenside per color
Add two small BitBoard slices that represent kingside and queenside squares per
color.

Add doc comments to DARK_SQUARES and LIGHT_SQUARES.
Add getters on BitBoard for getting a boardside bitboard.
Clean up imports. Import the whole library module and refer to library things in
BitBoard by path.
2024-01-29 15:00:53 -08:00
cb48413ce7 [bitboard] Implement BitBoard::is_single_square()
Returns true if there's only one square set in the bitboard.
2024-01-29 14:46:16 -08:00
0f664f6c80 [bitboard] Implement BitBoard::as_bits; let rank and file take &u8 instead of usize 2024-01-29 14:46:16 -08:00
ea74b214da [position] Implement generating pawn moves by looking up bitboards in the Library
This enables a bunch of clean up! Remove the MoveGenerationParameters and MoveList
types from move_generator::pawn.

Implement BitBoard::pawn_pushes to look up pawn pushes by square and color.
2024-01-28 10:25:01 -08:00
66d03d3514 [board] Clean up a bunch of imports 2024-01-28 09:46:38 -08:00
1f873879bb [bitboard] Add pawn attacks bitboards to the Library 2024-01-28 09:08:57 -08:00
3cec64d686 [bitboard] Make the bitboard crate more crate-like
Export symbols needed to use BitBoard and BitBoardBuilder.
Fix build errors.
2024-01-24 09:16:21 -08:00
b0b22048a8 [core] Rename (once again) chess_core → chessfriend_core 2024-01-24 08:48:19 -08:00
625bfb2446 [bitboard] Move everything in board::bitboard to the bitboard crate 2024-01-24 08:35:28 -08:00
32100b9553 [bitboard] Make an empty chess_bitboard crate
This crate lives in bitboard/
2024-01-24 08:34:23 -08:00
d776bd18e2 [board] Move bitboard lib to "board" 2023-12-20 11:45:55 -08:00
ab55a7994c [bitboard] Implement a Square type; fix all the build issues after adding a mod line to lib.rs 2023-12-20 11:45:12 -08:00
567cb8d787 [bitboard] Commit the lock file 2023-12-19 11:13:20 -08:00
ebed5c05ed [bitboard] Add a BitBoard and a Position struct 2023-12-19 11:13:06 -08:00
8fd01e4f11 Add bitboard Rust library 2023-12-19 10:32:26 -08:00