Commit graph

495 commits

Author SHA1 Message Date
b5d4069751 Make moves::castle::Parameters public
Rename this struct CastlingParameters → Parameters
Implement getter methods for private properties
2024-02-25 08:51:23 -08:00
b3e55f6dcd Split out some unchecked and check move build() methods
Unchecked are unsafe. Checked are safe.
2024-02-13 11:07:49 -07:00
047eb4fd77 Get en passant move building working (again?) 2024-02-13 11:05:02 -07:00
5d1ad73be6 In Move::capture_square, move the en passant check above the simple capture check 2024-02-13 11:04:21 -07:00
e172bfb5dd Remove the Copy trait from most move Styles and add Clone, Debug, Eq, and PartialEq to Promotion and Castle 2024-02-13 11:03:28 -07:00
f23967f4f3 Rename MoveGenerator::bitboard → _test_bitboard
This method is only used by tests. Mark it with cfg(test) and prefix it with _test
to indicate that fact.
2024-02-11 10:29:09 -07:00
a2865c87b0 Remove an unused Rank import from position.rs 2024-02-11 10:24:11 -07:00
c03a804c79 Rework the Pawn move generator to correctly compute en passant moves 2024-02-11 10:23:07 -07:00
3b8b6b36e3 Implement a basic Display for chessfriend_moves::Move 2024-02-11 10:23:07 -07:00
8724c3cdce Pad out the discriminants of Kind variants 2024-02-11 10:23:07 -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
c55b7c4877 Implement a whole new move crate 2024-02-11 10:23:07 -07:00
0bedf2aa9f Implement part of a new Builder using the type state pattern
The API for this is much easier to use.
2024-02-11 10:23:07 -07:00
f69c7d4c96 Move a bunch of stuff from the position::move module over to a new chessfriend_moves crate 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
e94819c79a Visual Studio Code workspace 2024-02-11 10:22:33 -07:00
41c3a2075c [position] Pass the PlacedPiece in move_set_for_piece() by reference to all the MoveGenerators 2024-02-11 10:17:09 -07:00
29eb56a5d7 [position] Remove some dead code from position::piece_sets 2024-02-11 09:58:18 -07:00
eb192e6dc4 [position] Fix the peterellisjones::en_passant_discovered_check test
This test was asserting that an e.p. move is included in the list of generated
moves. Actually, the position does NOT allow an e.p. move for black.
2024-02-11 09:58:18 -07:00
0201668563 [core] Move the Unicode piece table to a helper to_unicode() method on Piece 2024-02-11 09:58:18 -07: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
891b3ddbb9 [position] Remove the sight data from Position 2024-02-05 14:00:23 -08:00
a5e8f33afe [core] Implement Square::file_rank()
Returns a tuple of the square's file and rank.
2024-02-05 13:59:58 -08: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
4b35051deb [position] Derive several traits for CheckingPieces
Clone, Debug, Eq, and PartialEq.
2024-02-04 19:26:41 -08:00
17410936ab [position] Remove the rook_push_mask test from check.rs
This test now lives in move_generator::tests::peterellisjones
2024-02-04 19:26:11 -08:00
f4e57d7d6c [position] Implement all the example positions from Peter Ellis Jones' blog post
https://peterellisjones.com/posts/generating-legal-chess-moves-efficiently/
2024-02-03 15:16:00 -08:00
6c14851806 [position] Move whole-module move_generator tests to a tests/ module 2024-02-03 10:05:11 -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
63758a2edd Remove the move_generator crate from the Cargo workspace 2024-02-02 08:07:13 -08:00
efcc65d8d6 Merge branch 'checking-pieces-struct' 2024-02-02 08:06:17 -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
986758d011 [position] For non-King move generators, only generate moves if the push and captures masks aren't empty
Always generate King moves.
2024-02-02 08:03:51 -08:00
31903cb514 [position] Calculate push and capture masks on CheckingPieces 2024-02-02 07:53:50 -08:00
ac07a8d6cf [position] Implement SliderRayToSquareExt on Shape instead of PlacedPiece
Add an origin square argument to its one method ::ray_to_square(). Pushing this
implementation down a layer means I don't have to care about the color of the
piece.
2024-02-02 07:29:43 -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
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
7b97060ba2 [position] The KingMoveGenerator doesn't use push or capture masks
Mark these arguments with an _ so the linter stops complaining about it.
2024-02-01 08:43:49 -08:00
f1a05f33c9 [position] Factor out the update_moves_with_ray! as ray_in_direction!
This macro is implemented in every sight method. Factor it out, rename it, and
use it in all these macros.
2024-02-01 08:43:03 -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
cac13b4bc7 Cargo.lock changes 2024-01-30 08:53:15 -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
357b811518 [position] Add a fen! macro 2024-01-30 08:35:02 -08:00
8cdb9f13b4 [position] Apply capture and push masks to move generator results 2024-01-30 08:34:29 -08:00