Commit graph

30 commits

Author SHA1 Message Date
f1431ea4e9 [position] Move postion/mod.rs -> position.rs 2025-05-08 17:54:49 -07:00
091cc99cb3 WIP 2025-05-08 17:37:51 -07:00
1f3c90ff35 [position] Print the chess board diagram with box drawing characters 2024-03-25 10:38:02 -07:00
21b58a6422 [position] Update the danger_squares unit test to use assert_eq_bitboards!() 2024-03-14 17:01:28 -07:00
27a36565f3 [bitboard,core,position] Address a bunch of clippy warnings 2024-03-14 17:00:46 -07:00
d0abbd8f93 [position] Rever the const-ness of Position's initializers
Apparently you can't actually do that. :( You can't call trait methods in const
contexts.
2024-03-10 09:18:08 -07:00
a65c0c8ef1 [position] Make the Position initializer methods const
Position::empty() and Position::starting can both be const. Neat!
2024-03-08 08:18:49 -08:00
f0b9681cef [position] Add a doc comment to PieceBitBoards::all_pieces; remove unused empty_squares 2024-03-01 15:26:01 -08:00
5f1fce6cc2 Fix the remaining tests
Well… all the tests except the Peter Ellis Jones tests.

Pass around whole EnPassant types instead of pulling out just the e.p. square.
Make sure that Castling moves have their target and origin squares populated.
Add a color field to the Castle move style to make this possible.
2024-02-25 12:38:55 -08:00
d668091d0d Replace uses of types in r#move with types from the moves package types 2024-02-25 09:52:40 -08:00
aaad991899 Replace crate::r#move::castle::Castle with moves::Castle 2024-02-25 09:46:59 -08:00
a2865c87b0 Remove an unused Rank import from position.rs 2024-02-11 10:24:11 -07:00
e6a9b7f8c4 Return a chessfriend_moves::EnPassant from a new Position::en_passant()
Replace Position's en_passant_target_square() and en_passant_capture_square()
with a single en_passant() method that returns a new EnPassant struct that has
the target and capture squares for the en passant move.
2024-02-11 10:23:07 -07:00
cc23ee2d90 Rename en passant square method on Position and implement a getter for the capture square
Position::en_passant_square → en_passant_target_square
Position::en_passant_capture_square
2024-02-11 10:23:07 -07:00
1958c1a50e [position] Address a few warnings in Position
Build Position::sight_of_piece() and ::is_king_in_check() for cfg(test) only.
Expand the doc comment for ::king_danger() slightly.
Remove an unused Rank import.

# Conflicts:
#	position/src/position/position.rs
2024-02-11 10:22:57 -07:00
29eb56a5d7 [position] Remove some dead code from position::piece_sets 2024-02-11 09:58:18 -07:00
891b3ddbb9 [position] Remove the sight data from Position 2024-02-05 14:00:23 -08:00
4a601c2b81 [position] Fix all the unit tests
The pawn move generator only generated pushes for white pawns.
The is_king_in_check returned an inverted flag.
MoveSet needed a couple more validation methods: can_move_to_square and can_castle.
The MakeMoveBuilder also needed a little more move validation using the above methods.
2024-02-03 10:04:41 -08:00
942c758e15 [position] Calculate legal moves based on whether the king is in check
Use CheckingPieces to determine which and how many pieces check the king.

- If there are no checks, proceed with move generation as normal.
- If there is one checking piece, calculate push and capture masks and use those
   to generate legal moves.
- If there are more than one checking pieces, the only legal moves are king
  moves. Indicate this by setting the push and capture masks to EMPTY.
2024-02-02 08:05:37 -08:00
c8faad799e [position] Clean up Position's construction scheme
Position::default specifies the defaults for all field. Then, ::new() and
::starting() can use ..Default::default() in their implementations to avoid
having to specify empty values for all the internal structures.
2024-02-02 07:28:12 -08:00
f09376f5dc [position] Make the checking_piece! macro handle specifying the path to the piece constructor 2024-02-02 07:25:59 -08:00
8aa5dacfc8 Initial implementation of CheckingPieces and Position::checking_pieces() 2024-01-30 08:53:13 -08:00
26aedd8899 [position] Implement Position::king_bitboard to easily get the king bitboard for a player
Rewrite king_square() and is_king_in_check() in terms of king_bitboard().
2024-01-30 08:36:03 -08:00
98c8ef6e24 [position] Remove the unused Position::move_is_legal 2024-01-29 20:12:41 -08:00
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
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
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
220da08727 Directly rename board -> position 2024-01-28 09:56:57 -08:00