Commit graph

507 commits

Author SHA1 Message Date
9a4fa827f9 [position] Add two new negative tests for making pawn moves
- Ensure you cannot move a pawn to the last rank without a promotion move.
- Ensure a pawn cannot make an illegal move, and that the board state remains
  as it was before the move was attempted.
2025-05-21 09:51:16 -07:00
10ba21f7e3 [explorer] Remove the unused starting command; add aliases to make (m) and place (p) 2025-05-21 08:27:15 -07:00
85c1a395c4 [position] Streamline the implementation of castling_{king,rook}
Instead of using .and_then with an if/else, use .filter and pass the predicate.
Saves a few lines.
2025-05-21 08:26:34 -07:00
feaa81bbd8 [position, moves] Implement some castling tests
Add white castling for both wings. Found some bugs in how king sight is computed
while writing these.

In order for the king to perform the castle, the Movement bitboard needs to return
the two squares the king can castle to. That means anytime movement is calculated
for the king, the (relatively expensive) castling evaluation needs to happen.

Write two new helper static functions to create a Move for castling and promotion
moves. Since structs cannot have any functions with the same name, the two methods
that return properties related to those moves (Move::castle and Move::promotion)
need to be renamed. They're now called Move::castle_wing and Move::promotion_shape.
2025-05-21 08:25:49 -07:00
7c9c5484ba [position, board] Remove a bunch of dead code 2025-05-20 19:29:39 -07:00
039fd2b080 [position, board, core, moves] Implement a bunch of make_move code
Implement making double push and promotion moves. Then write several tests to
exercise these. Add convenient static functions to the Move struct to build moves
quickly, without using the Builder.

Add a is_promotable_rank() method to Rank to check that a rank can be used for
promotion moves.

The tests found and fixed a bug in pawn movement where the en passant square was
being discarded when deciding whether an e.p. move can be made.
2025-05-20 19:29:02 -07:00
6591619e32 [position] Misc changes
- Add a captures list to the Position struct
- Implement ToFenStr
- Update the imports list, which has been sorely out-of-date in the tree for many commits now.
2025-05-19 17:00:48 -07:00
97552302cb [position] Move castle evaluation code to its own submodule of position
Move the tests too.
2025-05-19 16:59:13 -07:00
54ac88aaf7 [board] Remove some old PlacedPiece code 2025-05-19 16:50:44 -07:00
0c1863acb9 [board, core, moves, position] Implement castling
Implement a new method on Position that evaluates whether the active color can castle
on a given wing of the board. Then, implement making a castling move in the position.

Make a new Wing enum in the core crate to specify kingside or queenside. Replace the
Castle enum from the board crate with this one. This caused a lot of churn...

Along the way fix a bunch of tests.

Note: there's still no way to actually make a castling move in explorer.
2025-05-19 16:50:30 -07:00
6816e350eb [moves] Clean up implementation of Move and export Kind enum 2025-05-19 14:19:05 -07:00
9010f1e9c2 [explorer, moves, core] Improve error handling in explorer
Implement thiserror::Error for a bunch of error types, and remove string errors
from the implementation of the command handler in explorer.

Clean up parsing of basic types all over the place.

Update Cargo files to include thiserror and anyhow.
2025-05-19 14:18:31 -07:00
72eeba84ba [explorer] Specify the chessfriend_board dependency 2025-05-19 08:42:53 -07:00
39ca74459d [explorer] Implement a reset command
Resets the board to an empty or starting state, or to a position specified by a FEN string.
2025-05-19 08:42:34 -07:00
d67c2cfb99 [explorer] A bunch of random changes to this binary
Too many changes mixed up together to tease apart.
2025-05-19 08:41:48 -07:00
00c4aa38f0 [explorer] make command no longer requires specifying a piece 2025-05-19 08:38:52 -07:00
6e0e33b5f9 [board] Remove the FromIterator<PlacedPiece> impl for PieceSet 2025-05-19 08:37:04 -07:00
67448b44d7 [board] Clean up variables names in piece_sets.rs so creating an error is a little more succinct 2025-05-19 08:36:44 -07:00
c7be0e3e2b [board] Remove the PlacedPiece import from fen.rs 2025-05-19 08:35:56 -07:00
cd3efa61c9 [core] Fix the coordinate tests
Use symbols instead of magic numbers.
2025-05-19 08:35:35 -07:00
b229049e27 [board, core] Update error types to use thiserror::Error 2025-05-19 08:34:32 -07:00
539b1fca6e [expolorer] Add two new commands for showing available moves and sight of a piece on a square 2025-05-19 08:28:23 -07:00
a78526befa [position] Move make_move to its own module: position::make_move
Rework sight.rs and add a new module, movement.rs, to calculate piece sight and
movement. I discovered during this process that "sight" and "movement" are different
because pawns (in particular) can move in ways that don't follow their sight lines.
The routines in the movement module account for this, but also pass through to the
sight routines for other pieces.
2025-05-18 08:12:10 -07:00
669a7c00ec [position] Add thiserror dependency 2025-05-18 08:07:12 -07:00
5553bab659 [board] Teach DiagramFormatter how to highlight and mark squares
Add two BitBoard attributes to the struct that mark squares that should be marked
or highlighted.

Empty marked squares are shown with an asterisk (*). Marked squares with a piece
don't have any change of appearance. (Something I'm still thinking about.)

Highlighted squares are shown with the ANSI escape sequence for Reverse Video.
2025-05-16 07:49:09 -07:00
3b5b2f16a3 [board] Add occupancy methods that return BitBoards 2025-05-16 07:47:28 -07:00
9943224ee0 [bitboard] Add separators to the NOT_A_FILE and NOT_H_FILE constants
This is a clippy suggestion.
2025-05-16 07:44:59 -07:00
e5a5367864 [bitboard] Remove leading underscore from leading_zeros and trailing_zeros methods
This is a clippy suggestion.
2025-05-16 07:44:37 -07:00
184e81a7c8 [bitboard] Remove #[must_use] from method calls; add it to BitBoard type 2025-05-16 07:44:05 -07:00
f1431ea4e9 [position] Move postion/mod.rs -> position.rs 2025-05-08 17:54:49 -07:00
424d348b2d WIP 2025-05-08 17:37:59 -07:00
091cc99cb3 WIP 2025-05-08 17:37:51 -07:00
d5cdf273c8 [bitboard] Fix some random clippy issues 2025-05-03 16:03:18 -07:00
867deafd13 [board] A ton of API refinements 2025-05-03 16:02:56 -07:00
99dd2d1be2 [board] Remove the Builder 2025-05-03 15:48:06 -07:00
b0c4039920 [board] Remove Board::new() 2025-05-02 15:42:06 -07:00
bb8d5a6aa3 [board] Replace Flags with castle::Rights 2025-05-02 15:41:45 -07:00
cd60a453aa [board] Replace active player and move properties on Board with MoveCounter instance 2025-05-02 15:18:37 -07:00
58cbe07136 [board] Implement PieceSet::mailbox() method to return a reference to its Mailbox 2025-05-02 15:05:39 -07:00
bf535f876a [board] Update call to BitBoard::occupied_squares to take an IterationDirection 2025-05-02 15:05:05 -07:00
0b100d5f14 [board] Remove Flags struct, replace it with Castle and supporting structs
Encapsulate castling rights within a small module. Castle provides the API to the
rest of the board package. Rights encodes the castling rights for each player.
Parameters defines castling parameters for each player.
2025-05-02 15:03:48 -07:00
9f2bfc0457 [board] Replace the length of the Builder::kings array with Color::NUM instead of constant 2 2025-05-02 14:49:16 -07:00
46b19ff616 [board] Implement Mailbox::from_iter as a reduce (aka fold) over the incoming iterator 2025-05-02 14:48:37 -07:00
72fd938238 [board] Implement Copy for Mailbox struct 2025-05-02 14:48:01 -07:00
c733342fca [board] Add MoveCounter struct to track current color, half move counter, and full move counter 2025-05-02 14:42:31 -07:00
7b0469d689 [bitboard] Replace separate methods for leading and trailing iteration
Add chessfriend_bitboard::IterationDirection
Make BitBoard::occupied_squares() take an IterationDirection and return an iterator
corresponding to the direction.
Do the same for ::first_occupied_square().
2025-05-02 14:28:31 -07:00
9f62996175 [bitboard] Return a copy of a BitBoard from BitBoard::ray() 2025-05-02 14:28:31 -07:00
53c637f424 [bitboard] Make BitBoard::EMPTY and BitBoard::FULL private; export BitBoard::full() 2025-05-02 14:23:29 -07:00
90657e3818 [position] Rewrite sight methods in terms of Board and pass BitBoard arguments by value 2024-07-13 12:08:20 -07:00
30188d478e [board] Convert &BitBoard to BitBoard for several Board methods
I don't think passing by reference buys much for BitBoard. So simplify the
logic and borrowing semantics to make these easier to work with.
2024-07-13 12:03:19 -07:00