Commit graph

31 commits

Author SHA1 Message Date
a30553503f [board, explorer, position] Clean up naming of sight and movement methods
These methods have a prefix, either `sight` or `movement`, and then follow the conventions
for other "trio" clusters where there's an un-suffixed method that takes an
Option<Color>, a _active method that uses the active color, and a _unwrapped
method that takes a bare Color.
2025-06-29 09:23:20 -07:00
f84319272c [explorer, position] Make Position.board private to the crate
Export a Position::board() method that returns a reference to the internal Board.
2025-06-21 21:07:26 -07:00
0f5a538f0a [explorer, perft, position] Move node count into a new PerftCounters struct 2025-06-19 11:34:59 -07:00
4ce7e89cdb [board, explorer, moves] Clean up the castling rights API
Reorganize castling rights API on Board into methods named according to
conventions applied to other API.

Board::has_castling_right
Board::has_castling_right_active
Board::has_castling_right_unwrapped

    These all check if a color has the right to castle on a particular side
    (wing) of the board. The first takes an Option<Color>, the latter two
    operate on bare Colors: the active color, or an explicit Color.

Board::grant_castling_right
Board::grant_castling_right_active
Board::grant_castling_right_unwrapped

    Grant castling rights to a color. Color arguments follow the pattern above.

Board::revoke_castling_right
Board::revoke_castling_right_active
Board::revoke_castling_right_unwrapped

    Revoke castling rights from a color. Color arguments follow the pattern
    above.

The latter two groups of methods take a new CastleRightsOption type that
specifies either a single Wing or All.

Rework the implementation of CastleRights to take a CastleRightsOption. Update
the unit tests and make sure everything builds.
2025-06-18 23:44:40 +00:00
bf17017694 [explorer] Add several commands to help with debugging
flags
: Print flags for the current board position. This prints the castling rights
and whether the player can castle (regardless of whether they have the right).

make
: Finally reimplement the make command. Change the format so it takes a move in
the UCI long algebraic style.

perft
: Run perft to a given depth on the current board position.
2025-06-18 08:21:31 -07:00
0e61598937 [explorer] Remove make_command module 2025-06-16 13:49:53 -07:00
45037d6fc1 [explorer, moves, perft] A few rustfmt changes that reorder imports 2025-06-16 13:49:29 -07:00
9815a63ebb [explorer] Print some question marks if a move is generated without target/origin squares
The move I observed in my testing was a castling move, which doesn't set target
and origin squares because those are provided by the castling parameters struct
from the board crate.

Fix the missing squares on castle moves by looking up castling parameters and
populating them. This requires Move::castle() to take a Color in addition to the
Wing. Update all the call sites.
2025-06-11 08:15:06 -07:00
651544fdd9 [explorer, moves, position] Remove unused MoveBuilder
This thing isn't used by any of the "modern" code I've written. It was difficult
to write, but kinda neat architecturally. It made a lot of invalid configurations
of moves into build-time errors. Anyway…

Remove several of the tests that relied on it, but that hadn't been updated to
use the newer code either.
2025-06-08 17:16:23 -07:00
634876822b [explorer] Add a load command
Loads a board position from a FEN string.

Plumb through setting the Zobrist state on an existing board. Rebuild the hash
when setting the state.
2025-06-08 16:57:36 -07:00
6b5a54f6b4 [explorer] Remove unused MakeMove import 2025-06-07 08:55:54 -07:00
fb8a8d6110 [explorer] Add zobrist command
It prints the hash of the board!
2025-06-07 08:09:36 -07:00
d7f426697d [board, position] Implement Zobrist hashing
This change builds on several previous changes to implement Zobrist hashing of the
board. This hash can be updated incrementally as changes are made to the board.
In order to do that, various properties of the Board struct had to made internal.
In the setters and various mutating members of Board, the hash is updated as
state changes.

The entire hashing mechanism is optional. If no ZobristState is provided when the
Board is created, the hash is never computed.

Plumb the Zobrist state through Position as well so that clients of Position (the
ultimate interface for interacting with the chess engine) can provide global
state to the whole engine.

The explorer crate gives an example of how this works. Some global state is
computed during initialization and then passed to the Position when it's created.
2025-06-05 08:22:34 -07:00
eaab34587c [board, explorer, moves] Make Board::active_color private
Make the struct attribute private, and export two new methods. A getter, active_color(),
and a setter, set_active_color().

Update all references to the attribute to use the methods.
2025-06-02 17:29:52 -07:00
8f42a4c94e [explorer, moves, position] Implement bespoke make_move and unmake_move methods on Position
Instead of inheriting the MakeMove and UnmakeMove traits by being a BoardProvider,
implement bespoke versions of these two methods. This gives Position a chance to
do some of its own work (tracking captures, move records, etc) when making a move.

Pass the move record by reference to the unmake_move() method. Saves a copy.

Export the Result types for MakeMove and UnmakeMove.
2025-06-01 19:02:53 -07:00
942d9fe47b [explorer, moves, position] Implement a moves command in explorer
The moves command writes all possible moves to the terminal.

Move the previous implementation of the moves command, which marked squares that
a piece could move to, to a 'movement' command.
2025-05-28 16:25:55 -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
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
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
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
f1cd36952b Fix build errors in explorer 2024-02-25 09:52:49 -08:00
569693bda9 Merge branch 'main' into rename-board-crate
# Conflicts:
#	explorer/src/main.rs
2024-01-28 09:55:53 -08:00
8eb180df67 [explorer] Add fen and make commands
Clean up the implementation of the place command.

Track state with a State struct that contains a position and a builder. The place
command will place a new piece and then regenerate the position.

The make command makes a move. The syntax is:

    make [color:w|b] [shape] [from square] [to square]

The fen command prints a FEN string representing the position.
2024-01-28 09:50:39 -08:00
66d03d3514 [board] Clean up a bunch of imports 2024-01-28 09:46:38 -08:00
76ac719418 [position] Rename the board crate → chessfriend_position in Cargo.toml
Rename the crate, but don't move any files.
2024-01-28 09:40:45 -08:00
a73355c769 [explorer] Track result of command with a CommandResult type, and overall state with a State type 2024-01-24 17:16:33 -08:00
d901be53d2 [explorer] Depends on core 2024-01-24 09:15:18 -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
f340578cf2 [explorer] A REPL-style command line app to fiddle with chess boards
Build a REPL that enables placing pieces on a chess board. Nothing else so far!
2023-12-28 15:09:15 -07:00