Commit graph

21 commits

Author SHA1 Message Date
481ae70698 [core] Directly index the array of Squares with a given index
In Square::from_index_unchecked, instead of using TryFrom to convert the index
to a square, just index directly into the Square::ALL array. This function is
already marked unsafe.
2025-06-19 14:32:07 -07:00
f0b6cb5f08 [core] Do a little cleanup in core::coordinates
Import std::fmt and remove some commented out code.
2025-06-16 08:58:22 -07:00
e2ce778247 [core, moves] Improve bounds checking of Square::neighbor
Remove the <n> argument from this method. I think it was a bad idea to begin with
but at the time I was looking for an expedient solution for getting neighbor
squares 2 squares away.

Overhaul bounds checking in this method so horizontal (west and east) bounds are
checked in addition to vertical (north and south) bounds. For the diagonal
directions in particular, it was easy to generate some bogus neighbor squares
because this method didn't check for wrapping when calculating horizontal
neighbors.
2025-06-07 20:06:14 -07:00
af2bff348f [core] Add an Option<i8> argument to Square::neighbor
This argument allows computing the neighbor n squares away along the direction.
Technically, squares n>1 are not neighbors… but this is a convenient calculation.
2025-05-23 18:34:19 -07:00
3684e9b425 [board, core, bitboard] Clean up casts between Rank, File and BitBoard
Let BitBoard::rank and BitBoard::file take a Rank and File directly, instead of a
u8 by reference. And then make the Rank/File::as_index const and return a value
rather than a reference.

All this allows you to convert between Rank, File, and BitBoard at compile tile
(i.e. as a const method) rather than needing to do runtime stuff.
2025-05-23 18:32:18 -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
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
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
091cc99cb3 WIP 2025-05-08 17:37:51 -07:00
ee51a13870 Rename Square::from_index → from_index_unchecked 2024-07-13 08:10:21 -07:00
534c022981 [core] Add #[must_use] to several methods in coordinates 2024-07-13 07:21:21 -07:00
a2d0c638d0 [core] Address clippy suggestions; clean up unit tests
In coordinates.rs:

- Add some [must_use] decorators to some getters
- Rewrite some unit tests to remove the .expect() and use ? instead
2024-04-25 08:05:07 -07:00
89802be53d [core] Address some clippy linter errors in core/coordinate.rs 2024-03-10 09:16:21 -07:00
82aa7a2b01 [core] Rewrite Direction as a coordinate_enum!
- Order the values of Direction in a clockwise fashion
- Implement Direction::opposite() to return the opposing direction
- Make some small changes to the macros in this file to improve readability, maybe.
2024-03-08 08:17:54 -08:00
2a6b098cb8 Fix the pawn unit tests 2024-02-25 10:51:27 -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
1f78d4811a [core] Declare Rank::PAWN_STARTING_RANKS
This is a slice that declares the pawn starting ranks for each color.
2024-01-29 14:46:16 -08:00
21c81f237a [core] Implement as_index() for range_bound_struct 2024-01-29 14:46:16 -08:00
025ceb2694 [core] Move the contents of board::square to core::cordinates
Export Square, Direction, Rank, and File from the core crate.
2024-01-23 17:18:48 -08:00