Commit graph

29 commits

Author SHA1 Message Date
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
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
620701057d [board] Rehash BitBoard's std::ops implementations
Implement bitwise AND and OR for all permutations of BitBoard and &BitBoard.
Refer to the std::ops traits by fully-qualified path rather than requiring the
module to import those traits to implement them.

Implement bitwise AND and OR assignment (&= and |=) for BitBoard and &BitBoard.

Implement XOR and XOR assignment for BitBoards.
2024-01-21 09:14:02 -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
939fac80d7 [board] Implement Default for BitBoard and Color 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
e56b3259e2 [board] Implement FromIterator for BitBoard 2024-01-17 08:48:46 -08:00
81d544f0d5 [board] Rename BitBoard::has_piece_at → is_set 2024-01-15 17:42:27 -08:00
a6b98abb95 [board] Create a bitboard! macro and BitBoardBuilder
The Builder enables cleanly building a BitBoard out of squares.
The macro lets you create a BitBoard from a simple list of coordinates:

bitboard!(A1, B2, C3, D4, …)
2024-01-15 17:17:34 -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
6e483b412b [board] Refactor ray BitBoard lookups
Rearrange the generated ray bitboards into a 2D grid by square and direction.
Use the Direction vector for lookup.
2024-01-06 19:47:55 -08:00
2394afc210 [board] Implement a TrailingBitScanner
This bit scanner iterates populated bits in a BitBoard from the trailing (least-significant) end.

Rename BitScanner → LeadingBitScanner.
Factor implementation of these two into a macro.
Clean up iterator returned by BitBoard::occupied_squares
Implement BitBoard::occupied_squares_trailing
2024-01-06 19:46:09 -08:00
ff839db041 BitBoard changes
- Clean up operator traits: remove the & versions and make the macro do more with less input
- Implement From<Square> for BitBoards: simplify conversion of Squares to BitBoards
- Take BitBoards by value in several places
- Clean up unit tests
2024-01-06 16:21:40 -08:00
769886086c [board] Get king moves from the bitboard library 2024-01-02 08:42:47 -08:00
06bfc4ac57 [board] Implement a BitBoard MoveLibrary
This struct computes and stores piece moves per square to speed up computation
of move lists.

Initialize a `static mut` instance once via std::sync::Once, and return a static
reference to it. So far, it computes king and knight moves.

Make BitBoard::empty() and MoveLibrary::new() const functions, enabling static
construction of the MOVE_LIBRARY instance without needing to wrap it in an
Option.
2024-01-01 09:25:35 -08:00
af36b75df7 [board] Implement a pawn move generator
Holy heck I went on a *journey* here. Ultimately, I needed to implement my own
index-based iterator instead of using the Vec's Iterator.

This type establishes some patterns I want to carry forward to other move
generators.

1. The use of a Parameters struct to fully parameterize the move generation
   per-color. That lets these types only need a single color-based branch
2. A list of move lists, one list for each of captures, promotions, and quiet
   moves.
3. An index-based move iterator.
4. Separate impl for generating bitboard representations of these moves

Additional changes:

- Implement BitBoard::from_square()
- Implement a Square::e5() for tests

This class doesn't implement en passant yet. It also doesn't yet have tests for
the bitboard stuff.
2023-12-31 11:44:47 -08:00
1cc8b4520f [board] Return copies of rank and file bitboards from static lists 2023-12-31 09:26:20 -08:00
e30bcb3105 [board] Implement BitBoard::file and fmt::Display for BitBoard
BitBoard::file returns a BitBoard representing the 0-indexed file.
fmt::Display prints a grid of bits in the standard orientation (white on bottom, left to right)
Add asserts to the rank and file constructors to catch out of bounds arguments.
2023-12-30 10:26:37 -08:00
53dc80b6bb [board] Implement BitAndAssign and BitOrAssign on BitBoard 2023-12-29 16:34:11 -08:00
808222eef1 [board] Clean up the formatting of BitBoards
Use debug_tuple in the fmt::Debug implementation.
Implement fmt::Binary, fmt::UpperHex, and fmt::LowerHex by delegating to u64's version.
2023-12-29 15:37:38 -08:00
41421dddbb [board] Clean up interfaces of pieces and square structs 2023-12-29 09:17:33 -08:00
2296be23cc [board] Rename BitBoard::from_bit_field → ::new 2023-12-28 21:42:18 -07:00
4c9e6a51fc [board] Move all the BitBoard shift code to a new bitboard::shifts module 2023-12-28 12:14:30 -07:00
5a08a4477e [board] Implement BitBoard::shift_south 2023-12-28 12:10:39 -07:00
5e47d37aa3 [board] Add a negative test for BitBoard::is_empty()
Remove a stray println!
2023-12-27 10:28:44 -07:00
61448d437f [board] Implement a BitBoard::rank constructor
Also implement BitBoard::shift_north() to support rank().
2023-12-27 10:04:02 -07:00
51a265172b [board] Implement an infix_op! macro for generating BitBoard operator traits 2023-12-27 10:00:30 -07:00
9d0761f8c6 [board] Rename from_algebraic_string → from_algebraic_str 2023-12-26 13:28:25 -07:00
758a3d95fc [board] Reorganize bitboard and position modules and export some symbols from the crate
Move position.rs to the position module and create a mod.rs.
Do the same for bitboard.rs in the bitboard modules.
Export Color, Piece, Position, and Square and use crate::Thing directly instead of referring to the symbol in the nested modules.
2023-12-26 11:25:27 -07:00
Renamed from board/src/bitboard.rs (Browse further)