Commit graph

10 commits

Author SHA1 Message Date
ca9ff94d2a [board] Rename the moves modules → move_generator
Update the imports.
Also update some references to crate symbols in move_generator macros to use $crate.
2024-01-17 08:40:09 -08:00
5961b1bcd5 [board] Export BitBoard directly off of the crate for internal use
Update all the imports to import from the crate directly.
2024-01-14 10:57:22 -08:00
d2ee9244c2 [board] Update Position::player_has_right_to_castle callsites 2024-01-11 08:37:22 -08:00
31e5771d30 [board] Implement all the bit twiddling to track whether castling is allowed for each player and side of the board 2024-01-10 11:01:19 -08:00
e2d93b8c3c [board] Replace implementations of the king and knight move generators with a more generic version
While implementing these move generators, I realized I was duplicating a lot of code. So, I started thinking about how to do less of that. I create a MoveGeneratorInternal trait that these move generators implement. This trait provides default implementations of several methods.

I also discovered that I needed a way to keep track of move sets per piece for each kind (shape) of piece. The new move generators, and the generators still to come, can now keep track of moves per piece separately in MoveSet instances.
2024-01-06 17:01:16 -08:00
14db74f212 Remove tests module 2024-01-06 16:45:13 -08:00
3b266cb94a Update king move generator tests 2024-01-06 16:40:21 -08:00
769886086c [board] Get king moves from the bitboard library 2024-01-02 08:42:47 -08:00
fb6fd27453 [board] Remove Iterator implementations form move generator types; replace it with an iter() method
I was given some guidance[1] on the Rust developer forums that my approach of
implementing Iterator on these types wasn't quite right.

> In general, iterators are distinct data structures than the primary struct
that owns the data, in part due to issues like this, but also due to concerns
around iterator invalidation and the need to carry around iteration state more
generally.

I took this to heart and replace the Iterator implementations with an iter()
method that returns an `impl Iterator<Item=Move>`. This works so much better and
lets me delete a bunch of code!

Additionally, the iter() methods on the piece-wise move generator types return
`impl Iterator<Item=&Move>`, and then the top-level Moves::iter() returns a
.cloned().

Overall I'm really happy with this!

[1]: https://users.rust-lang.org/t/tricky-lifetime-may-not-live-long-enough-error-on-an-iterator-wrapping-a-boxed-iterator/104650/3
2024-01-01 09:33:37 -08:00
4a54d8b877 [board] Implement KingMoveGenerator
Generate moves for kings.

This struct is trying out a different approach to iterators where the type
itself isn't one, but it has an iter() method that returns an iterator over all
the move lists.

This struct also builds all the moves up front, in new() before the new instance
is returned.
2023-12-31 16:35:34 -08:00