Commit graph

28 commits

Author SHA1 Message Date
faca844733 [moves] Knight move generator and tests 2025-05-25 11:05:10 -07:00
3f3842c7c8 [moves] Add several macros to help with testing: ply! and assert_move_list!
ply! implements a small DSL for writing moves in code using a natural-ish
algebraic notation.

assert_move_list! takes a generator and an expected list of moves and asserts
that they're equal. This macro is mostly a copy from one I wrote earlier in the
position crate.
2025-05-25 11:04:49 -07:00
09bf17d66b [moves] Implement promotions and en passant in the PawnMoveGenerator
Add another sub-iterator to the PawnMoveGenerator that produces promotion pushes
or capture moves (depending on move_type) when a pawn moves to the back rank.

Also implement en passant moves.

Fix a bug in the Left and Right captures branches where the wrong neighbors used
to calculate origin squares.

Add a whole bunch of tests. Still missing several cases though.
2025-05-24 18:01:14 -07:00
574ab803dd [moves] Implement a move generator for pawns
I used Claude to help me figure this out. First time using AI for coding. It was
actually rather helpful!

Calculate BitBoards representing the various kinds of pawn moves when the move
generator is created, and then iterate through them.

En passant still isn't implemented here. This code has not been tested yet either.
2025-05-23 18:36:22 -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
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
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
091cc99cb3 WIP 2025-05-08 17:37:51 -07:00
b3c472fbce Fix some imports in the moves package
Castle and EnPassant moved to the board package. Reference these types there.
Add the board packages as a dependency to the moves package.
2024-04-26 09:50:42 -04:00
1d82d27f84 Move a whole bunch of stuff to the new chessfriend_board package 2024-04-25 13:28:24 -07:00
a65fcd6000 [position] Rename fields of EnPassant struct
Append _square to each one.
2024-03-01 15:24:20 -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
2a6b098cb8 Fix the pawn unit tests 2024-02-25 10:51:27 -08:00
9b7bf3a212 Implement some helpful testing types and traits in the moves package 2024-02-25 09:15:07 -08:00
d714374f35 Pass self by reference to move builder methods where possible 2024-02-25 08:57:16 -08:00
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
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
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