Commit graph

394 commits

Author SHA1 Message Date
13e166e059 [position] Remove an unnecessary type annotation 2024-01-29 20:12:26 -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
9c4360c886 [position] Remove move_generator::MoveListSet 2024-01-29 19:02:02 -08:00
8aa44e56f2 [position] Fix a few warnings related to imports; make position::Flags public 2024-01-29 19:01:44 -08:00
52b19b87d8 [position] Implement FromFen for Position, Piece, and Color
I can now create Positions from FEN strings!
2024-01-29 16:10:08 -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
d6bd6aec0f [position] Lazily build move lists in MoveGenerator structs
Merge branch 'lazily-build-move-lists'
2024-01-29 14:47:25 -08:00
1d7dada987 [bitboard, core, position] Implement proper castle move generation
Add a field to MoveSet called special that flags special moves that should be
generated in the iter() method. This field is a u8. It only tracks castles in
the first and second bits (kingside and queenside, respectively). The move iterator
chains two maps over Option<()> that produce the kingside and queenside castle
moves.

With that done, finish the implementation of Position::player_can_castle by
adding checks for whether the squares between the rook and king are clear, and
that the king would not pass through a check. This is done with BitBoards!

Finally, implement some logic in PositionBuilder that updates the position's
castling flags based on the positions of king and rooks.

Supporting changes:
- Add Color:ALL and iterate on that slice
- Add Castle::ALL and iterator on that slice
- Add a CastlingParameters struct that contains BitBoard properties that describe
  squares that should be clear of pieces and squares that should not be attacked.
2024-01-29 14:46:41 -08:00
83a4e47e56 MoveGenerator::iter() returns an iterator of moves-by-value 2024-01-29 14:46:41 -08:00
ea22f7c5c7 Clean up some test imports 2024-01-29 14:46:41 -08:00
2d5710ccb1 Clean up Pawn::pushes a little bit 2024-01-29 14:46:41 -08:00
296a57d7ac Remove move list arguments from king and pawn move set constuction
These are harder.
2024-01-29 14:46:41 -08:00
5e3ef9d21e Remove the move lists from bishop, knight, queen, and rook move set construction
These are the easy ones.
2024-01-29 14:46:41 -08:00
cd3cb82192 Add an assert_move_list! macro to help with verifying move lists 2024-01-29 14:46:41 -08:00
d910ff708e Remove the move list argument from MoveList::quiet_moves and capture_moves
Produce an iterator of Moves in MoveList::moves
2024-01-29 14:46:41 -08:00
c558800385 [position] Fix a bug in the pawn pushes move generator 2024-01-29 14:46:22 -08:00
1f78d4811a [core] Declare Rank::PAWN_STARTING_RANKS
This is a slice that declares the pawn starting ranks for each color.
2024-01-29 14:46:16 -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
21c81f237a [core] Implement as_index() for range_bound_struct 2024-01-29 14:46:16 -08:00
dab787170c [position] Clean up rook unit tests
Use test_position! instead of position!
Spell out the PlacedPiece constructor in the test_position! macro.
2024-01-28 10:28:01 -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
77f419ad3b [position] Rename FenError → ToFenError
Add an associated type called Error to the ToFen trait. This mirrors the try_from
any try_into traits.
2024-01-28 10:05:51 -08:00
808526f8f7 [position] Rename the board crate -> position
Merge the 'rename-board-crate' branch to 'main'.
2024-01-28 09:59:11 -08:00
ed55eda901 Update the Cargo.toml files 2024-01-28 09:58:50 -08:00
220da08727 Directly rename board -> position 2024-01-28 09:56:57 -08:00
569693bda9 Merge branch 'main' into rename-board-crate
# Conflicts:
#	explorer/src/main.rs
2024-01-28 09:55:53 -08:00
8eb180df67 [explorer] Add fen and make commands
Clean up the implementation of the place command.

Track state with a State struct that contains a position and a builder. The place
command will place a new piece and then regenerate the position.

The make command makes a move. The syntax is:

    make [color:w|b] [shape] [from square] [to square]

The fen command prints a FEN string representing the position.
2024-01-28 09:50:39 -08:00
6bd3787a24 [board] Write test_position!({starting,empty}) macros
These produce starting and empty positions, respectively, and then print the
position.
2024-01-28 09:47:25 -08:00
66d03d3514 [board] Clean up a bunch of imports 2024-01-28 09:46:38 -08:00
1e77bc5ebb [board] Test to verify the king can't move into or stay in check
Write a test on the king move generator to verify the king can't move to a
square where it would still be in check.
2024-01-28 09:45:13 -08:00
76ac719418 [position] Rename the board crate → chessfriend_position in Cargo.toml
Rename the crate, but don't move any files.
2024-01-28 09:40:45 -08:00
b002442b42 [board] Implement a custom PartialEq on Position
We don't need to compare cached data. The load-bearing parts of a Position are:
player to move, position of all pieces, flags, and en passant status.

Inspiration for this implementation came from the FEN spec. It specifies all
these in the string.
2024-01-28 09:16:22 -08:00
1f873879bb [bitboard] Add pawn attacks bitboards to the Library 2024-01-28 09:08:57 -08:00
164fe94bc0 [board] Implement danger squares for the current player
This concept comes from [1]. Danger squares are the squares a king cannot move to
because it would permit the opposing player to capture the king on their next
turn.

[1]: https://peterellisjones.com/posts/generating-legal-chess-moves-efficiently/
2024-01-28 09:08:22 -08:00
654e4094d9 [board] Restructure the move_generator module
Move mod.rs to ../move_generator.rs. This is the new style.
Move the contents of move_generator::move_generator to the top of move_generator.
2024-01-27 14:25:38 -08:00
9d25414b97 [board] Directly use PlacedPiece in the position! macro
Avoids having to also import the piece! macro to use position!.
2024-01-27 13:04:22 -08:00
e8d7f15a7f [board] Simplify the piece placement strategy logic
Check whether the strategy is PreserveExisting before checking if the piece is
already placed.
2024-01-27 13:03:18 -08:00
bea6dd67c8 [board] Remove the position reference from move generator structs
Simplifies the lifetime calculations, and makes it possible to cache a Moves
object on Position.
2024-01-27 13:02:43 -08:00
d3ab477795 [board] Remove a stray space in move_generator/mod.rs 2024-01-26 12:59:23 -08:00
6292421b1c [board] Clean up imports in fen.rs 2024-01-26 12:59:05 -08:00
f08a4c66a1 [core] Use TryFromCharError in TryFrom<char> for Color 2024-01-26 12:58:51 -08:00
54c94a93aa [board] Rewrite the pawn move generator
I wrote it before I made the MoveGeneratorInternal trait.
Found a few bugs in there too.
2024-01-26 08:38:01 -08:00
a73355c769 [explorer] Track result of command with a CommandResult type, and overall state with a State type 2024-01-24 17:16:33 -08:00
d27c455ce4 Merge branch 'many-crates' 2024-01-24 17:14:30 -08:00
3e1675f87e Specify resolver=2 in the Cargo workspace 2024-01-24 17:10:44 -08:00
88c0638d83 [board] Check that move is in sight of piece
If it's not, return an error from MoveBuilder::make()
2024-01-24 17:10:10 -08:00
1b5319c702 [board] Pass a Color to Position::king_square
Now it can return either color's king.
2024-01-24 17:09:15 -08:00
8b2a3926b3 [core,board] Move board::piece to core
Break up types in core into finer grained modules.
Update all the imports.
2024-01-24 17:08:27 -08:00
3c71687838 Merge branch 'many-crates'
# Conflicts:
#	Cargo.toml
#	core/Cargo.toml
2024-01-24 09:23:35 -08:00