Commit graph

67 commits

Author SHA1 Message Date
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
6f85305912 [board] Clean up a bunch of build errors
Fix imports to refer to core and bitboard crates.
Fix some API use errors.
2024-01-24 09:18:12 -08:00
b0b22048a8 [core] Rename (once again) chess_core → chessfriend_core 2024-01-24 08:48:19 -08:00
106800bcb3 [core,board] Update all use imports referring to Square, Rank, and File 2024-01-24 08:32:09 -08:00
9a8380573b [board] Move MakeMoveBuilder::new() to an impl that specifies NoMove
I can build these now without having to specify a type for M.
2024-01-22 08:18:19 -08:00
bf2bccbc7d [board] Implement PositionBuilder::from_position
Create a PositionBuilder from a Position.
2024-01-22 08:12:55 -08:00
c1008ef672 [board] Put a cached Moves object into a OnceCell on Position
Cache move generation so we don't have to remake it every time.
2024-01-22 08:12:28 -08:00
dbbf2d4c46 [board] Implement ply and full move counters on Position
Pipe these numbers through the Builders
2024-01-21 15:10:04 -08:00
829d9af52c [board] Fix some bugs in the starting position
Turns out I was doing the starting position really wrong. In an upcoming commit,
I will implement FEN output for Positions. While doing that work, I found several
issues that were causing the output of the FEN formatter to return garbage.

Implement a handful of unit tests to track down the errors.

Rename Shape::_ascii_representation() → Shape::to_ascii.
Implement to_ascii() on Piece.
2024-01-21 14:56:03 -08:00
84c9c43a7d [board] Add a few comments in position::position
One TODO
And one doc comment.
2024-01-21 13:07:07 -08:00
3c699b0b3d [board] Remove the intermediate String when building a diagram representation of a Position
Also ignore the tests in position::diagram_formatter::tests. These don't assert
anything; they're just there for visual spot check.
2024-01-21 13:02:06 -08:00
f90ea2d1be [board] Add a test for capturing en passant; fix the bugs
I wrote a test for capturing en passant that revealed some bugs. Cool!

Implement the missing part of move validation that checks for an en passant move.
Implement PositionBuilder::to_move() to set player_to_move.

The most difficult part of this fix was finding the logic error in
Move::is_en_passant(). Instead of checking for non-zero, check for equality against
the en passant flag value. Checking for non-zero was causing this method to return
true in the double push case.
2024-01-21 11:21:37 -08:00
683d89b726 [board] Convert a few more Piece and PlacedPiece to pass by ref 2024-01-21 10:39:57 -08:00
8835d8b40e [board] Add position::tests::rook_for_castle 2024-01-21 10:39:24 -08:00
fa1c6b452e [board] Remove BoardSide enum; use Castle everywhere
Move Castle to a castle module inside the move module.
Implement into_index() on Castle to turn it into a usize.
2024-01-21 10:38:50 -08:00
21b5266789 [board] Implement position::builders::MoveBuilder
This builder takes a Position and a Move, validates the move, and makes the move
in that position. Its build() method returns a new Position with the move made.
2024-01-21 09:23:39 -08:00
4a5ae8ec59 [board] Move position builders into a builders module
Move PositionBuilder to position_builder.rs and export it from the builders module.
2024-01-21 09:20:03 -08:00
1a907844d6 [board] Update a bunch of methods to take &Piece instead of plain Piece 2024-01-21 09:18:16 -08:00
918b68f300 [board] Use Castle as the interface type for methods related to castling
Use BoardSide as an internal type for looking up generated bitboards, target squares, etc.
2024-01-21 09:05:42 -08:00
7071f6a742 [board] Cave to pressure and implement fmt::Display for Position
It prints a nice diagram!

Now I can make the position module private.
2024-01-19 18:12:28 -08:00
24cce95a88 [board] Implement a PositionBuilder; refactor piece bitboards into a PieceBitBoards struct
This makes Position immutable, even if declared mut. I think this will also make
it easier to build positions going forward.

Moving to a PieceBitBoards struct also required a lot of places that return owned
BitBoards to return refs. This is basically fine except for adding a few more &
here and there.

This was a huge refactoring project. All the move generators and a bunch of
BitBoard stuff needed to be updated.
2024-01-19 18:09:05 -08:00
c413db0bf1 [board] Clean up Display and Debug implementations on BitBoard, Flags, Position, and PlacedPiece 2024-01-19 18:09:05 -08:00
2269df2ed9 [board] Move piece! and position! macros to a new macros.rs module 2024-01-19 18:09:05 -08:00
f337b8053d [board] Break getting the square the king is on into a separate helper method
Implement Position::king_square() and use it in is_king_in_check()
2024-01-17 08:48:23 -08:00
71e93925b9 [board] Clean up a handful of things in position.rs
- Remove unused std::fmt::Write import
- Refer to the piece! macro with $crate (I didn't know this was legal??)
- Remove the doc comments on Position::flags
- Remove {set,clear}_player_has_right_to_castle_flag
- Remove an extraneous local variable from Position::place_piece()
2024-01-17 08:46:41 -08:00
3ba6722697 [board] Implement a bunch of sight tests 2024-01-17 08:44:27 -08:00
2174bcf009 [board] Update all the move generator submodules to use MoveBuilder instead of Move
Along the way update "manual" piece creation to use the macros instead.
2024-01-17 08:43:48 -08:00
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
2d4ad70994 [board] Refer to Position with $crate in the position! macro 2024-01-17 08:36:00 -08:00
c8db5a430d [board] Fix a silly build error in position.rs
An extra closing brace.
2024-01-17 08:35:42 -08:00
3a15fca10a [board] Remove the intermediate string in the Debug implementation for Position 2024-01-17 08:24:53 -08:00
177a4e32da [board] Implement a u16 based Move
Replace building a Move with the Move struct itself with a MoveBuilder that
builds a Move and returns it.

Update the tests and move formatter.
2024-01-16 18:03:27 -08:00
96b04379a4 [board] Implement Position::is_king_in_check()
Returns true if the king of the current player is in check.
2024-01-15 20:10:58 -08:00
81d544f0d5 [board] Rename BitBoard::has_piece_at → is_set 2024-01-15 17:42:27 -08:00
9ef53b76f5 [board] Rename BitBoard::place_piece_at and BitBoard::remove_piece_at
→ set_square
→ clear_square
2024-01-15 17:16:14 -08:00
3ecc263701 [board] Implement piece sight algorithms
Add a new Sight trait, implemented by PlacedPiece. The implementation of this
trait produces a BitBoard representing the squares visible to the placed piece.
2024-01-15 16:03:06 -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
e56d256812 [board] Fix two build errors 2024-01-14 10:26:36 -08:00
284b3b68a0 [board] Add another test to the position flags 2024-01-14 10:19:20 -08:00
953c2f1522 [board] Move position flags to a Flags struct in its own module 2024-01-13 11:15:09 -08:00
7c80c61690 [board] Implement a position! macro for creating Positions
For example:

```
let position = position![
    White King on E4,
    Black Rook on E8,
];
```
2024-01-12 22:30:00 -08:00
caef0af244 [board] Implement Default for Position
Default returns an empty position.
2024-01-11 08:18:31 -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
359bab9173 [board] Implement rook::ClassicalMoveGenerator
Implement a rook move generator using the "classical" approach.
This approach walks each ray to find blockers and then masks out friendly pieces.
This is not efficient compared to other approaches, but it's much easier to implement.
2024-01-06 19:51:06 -08:00
14db74f212 Remove tests module 2024-01-06 16:45:13 -08:00
c79c05ddb6 Fix Pieces unit tests 2024-01-06 16:34:05 -08:00
c3e3ebfa97 Iterate by Rank and File when building a diagram 2024-01-06 16:25:03 -08:00
aac1a85507 In Position::place_piece, take piece and square by value
Use values for BitBoards and other things too.
2024-01-06 16:24:46 -08:00
750b16970f [board] Create const arrays for Shape that return &'static to its enum cases 2023-12-31 11:44:47 -08:00
878d771d86 [board] Replace Moves' separate properties with a Vec of Iterators
This makes iteration easier. Move to the next iterator if the current one returns None.
No tests for Moves yet though.
2023-12-31 11:44:47 -08:00