Commit graph

139 commits

Author SHA1 Message Date
Bruno BELANYI 3fa56b36a4 Check for invalid pawns in 'ChessBoard::is_valid' 2024-04-01 22:20:39 +01:00
Bruno BELANYI 52772167a6 Pre-generate the magic bitboard seeds
My naive RNG implementation takes about ~40 seconds to generate the
magic bitboards for both bishops and rooks (or ~1 second in release
mode).

If we pre-generate the seeds, we can instead make it ~instantaneous.

The self-modifying code is inspired by matklad [1].

[1]: https://matklad.github.io/2022/03/26/self-modifying-code.html
2024-04-01 22:20:39 +01:00
Bruno BELANYI 9dea85054d Add 'ChessBoard::checkers' 2024-04-01 22:20:39 +01:00
Bruno BELANYI f582a76e70 Test for opponent being in check during validation 2024-04-01 22:20:39 +01:00
Bruno BELANYI 58d8743106 Use 'ChessBoard::occupancy' 2024-04-01 22:20:39 +01:00
Bruno BELANYI d9e4f16ec8 Add 'ChessBoard::occupancy' 2024-04-01 22:20:39 +01:00
Bruno BELANYI 08ce3787df Check kings' position in 'ChessBoard::is_valid' 2024-04-01 22:20:39 +01:00
Bruno BELANYI 6976c60fe6 Add 'TryInto<Square>' for 'Bitboard' 2024-04-01 22:20:39 +01:00
Bruno BELANYI bc67ee3e9a Test 'ChessBoard::{do,undo}_move' machinery 2024-04-01 22:20:39 +01:00
Bruno BELANYI c1419f0e44 Add FEN board parsing
Unfortunately, given that I *don't* want to expose all the `ChessBoard`
fields to the rest of the crate, this implementation will have to live
alongside its module instead of inside `crate::fen`...
2024-04-01 22:20:39 +01:00
Bruno BELANYI 3cd2601f07 Add 'ChessBoard::is_valid' 2024-04-01 22:20:39 +01:00
Bruno BELANYI ddcef6f9c0 Add 'FenError::InvalidPosition' variant 2024-04-01 22:20:39 +01:00
Bruno BELANYI c112ddc4cd Implement 'Default' for 'ChessBoard' 2024-04-01 22:20:39 +01:00
Bruno BELANYI ce3ebf05ee Add 'ChessBoard::{,un}do_move' 2024-04-01 22:20:39 +01:00
Bruno BELANYI d44461e35c Add 'ChessBoard' 2024-04-01 22:20:39 +01:00
Bruno BELANYI 64e93b39fd Add FEN castling rights parsing 2024-04-01 22:20:39 +01:00
Bruno BELANYI 7c896d5dba Add FEN piece type parsing 2024-04-01 22:20:39 +01:00
Bruno BELANYI b5365f8a82 Add FEN en-passant target square parsing 2024-04-01 22:20:39 +01:00
Bruno BELANYI 3c2a5a412e Add FEN side to move parsing 2024-04-01 22:20:39 +01:00
Bruno BELANYI bd662fdd27 Introduce 'FenError' enum 2024-04-01 22:20:39 +01:00
Bruno BELANYI 0fd9766db0 Add 'FromFen' trait 2024-04-01 22:20:39 +01:00
Bruno BELANYI 4d69d34fa0 Add 'Move' 2024-04-01 22:20:39 +01:00
Bruno BELANYI 0b9318cdf3 Add 'Bitboard::has_more_than_one' 2024-04-01 22:20:39 +01:00
Bruno BELANYI e673e20a63 Add 'Color::third_rank' 2024-04-01 22:20:39 +01:00
Bruno BELANYI 0cc1fcf912 Add 'CastleRights::with_{king,queen}_side' 2024-04-01 22:20:39 +01:00
Bruno BELANYI 072a1ea13c Add '*Assign' operators to 'Bitboard' 2024-04-01 22:20:39 +01:00
Bruno BELANYI 02768b6d96 Remove all useless 'allow(unused)' 2024-04-01 22:20:39 +01:00
Bruno BELANYI af421a9452 Tighten item visibilities 2024-04-01 22:20:39 +01:00
Bruno BELANYI 3b1735da79 Add 'BitboardIterator::new' 2024-04-01 22:20:39 +01:00
Bruno BELANYI 06087358de Add bitboard-based move generation 2024-04-01 22:20:39 +01:00
Bruno BELANYI 459b878342 Expose magic bitboard generation to parent module 2024-04-01 22:20:39 +01:00
Bruno BELANYI 2bdfbbf467 Add 'MagicMoves' 2024-04-01 22:20:39 +01:00
Bruno BELANYI d519cfb817 Make 'Magic' 'pub(crate)' 2024-04-01 22:20:39 +01:00
Bruno BELANYI 25494700d7 Add missing derives to 'Magic' 2024-04-01 22:20:39 +01:00
Bruno BELANYI 028c4543e7 Move 'Magic' to 'wizardry' submodule 2024-04-01 22:20:39 +01:00
Bruno BELANYI 868edda9d7 Move naive move generation into sub-module 2024-04-01 22:20:39 +01:00
Bruno BELANYI 23d01d4d3f Make all modules at least 'pub(crate)' 2024-04-01 22:20:39 +01:00
Bruno BELANYI bd9238d686 Add 'Color::iter' 2024-04-01 22:20:39 +01:00
Bruno BELANYI 066d442823 Add magic bitboard generation 2024-04-01 22:20:39 +01:00
Bruno BELANYI 5ef3737b98 Make 'Magic' fields 'pub(crate)' 2024-04-01 22:20:39 +01:00
Bruno BELANYI 1951db0720 Add magic mask generation 2024-04-01 22:20:39 +01:00
Bruno BELANYI 2601abdc76 Add 'Magic' type 2024-04-01 22:20:39 +01:00
Bruno BELANYI d3a84750f5 Add naive pawn move generation 2024-04-01 22:20:39 +01:00
Bruno BELANYI bf23d0eaae Add naive rook move generation 2024-04-01 22:20:39 +01:00
Bruno BELANYI 8ff47231a0 Add naive bishop move generation 2024-04-01 22:20:39 +01:00
Bruno BELANYI f0847a4e49 Add naive knight move generation 2024-04-01 22:20:39 +01:00
Bruno BELANYI d91f63b5ed Add naive king move generation 2024-04-01 22:20:39 +01:00
Bruno BELANYI bed7ec3be2 Remove spurious links in 'Square' documentation 2024-04-01 22:20:39 +01:00
Bruno BELANYI 4491e5be00 Remove spurious links in 'Bitboard' documentation 2024-04-01 22:20:39 +01:00
Bruno BELANYI 8d03242e83 Add 'Bitboard::iter_powerset' 2024-04-01 22:20:39 +01:00
Bruno BELANYI a3a9f64213 Add 'Piece' enum 2024-04-01 22:20:39 +01:00
Bruno BELANYI d919b956ed Add 'NUM_VARIANTS' constant to all 'board' enums 2024-04-01 22:20:39 +01:00
Bruno BELANYI 407f85c19b Consistently use 'Self' type in 'impl' blocks 2024-04-01 22:20:39 +01:00
Bruno BELANYI b68dd132e8 Fix typo in 'board::Color' documentation 2024-04-01 22:20:39 +01:00
Bruno BELANYI 2c1142324c Add 'Color::slide_board_with_blockers' 2024-04-01 22:20:39 +01:00
Bruno BELANYI 0315e2fb51 Improve 'board::BitboardIterator'
* Accurate 'size_hint'.
* Exact size.
* Fused iterator (keeps returning 'None' after returning 'None' once).
2024-04-01 22:20:39 +01:00
Bruno BELANYI f3a83065da Add 'Color::{forward,backward}_direction' 2024-04-01 22:20:39 +01:00
Bruno BELANYI 0812d916ff Add 'CastleRights::unmoved_rooks' 2024-04-01 22:20:39 +01:00
Bruno BELANYI e84ec552fe Add 'CastleRights::without_{king,queen}_side' 2024-04-01 22:20:39 +01:00
Bruno BELANYI a21841c0ad Add 'CastleRights::has_{king,queen}_side' 2024-04-01 22:20:39 +01:00
Bruno BELANYI 88e74d5fff Add 'CastleRights' enum 2024-04-01 22:20:39 +01:00
Bruno BELANYI f351f056a9 Add 'Color' enum 2024-04-01 22:20:39 +01:00
Bruno BELANYI 042f5dbc4d Rename 'board::direction{s,}' 2024-04-01 22:20:39 +01:00
Bruno BELANYI 585c127381 Statically assert zero-cost invariants
Since some or all of those invariants will come in handy to ensure we
use as little memory as possible, to maximize the speed of the move
generation later on.
2024-04-01 22:20:39 +01:00
Bruno BELANYI d51d72377e Add 'static_assert' macro 2024-04-01 22:20:39 +01:00
Bruno BELANYI 643b688384 Add 'Bitboard::{LIGHT,DARK}_SQUARES 2024-04-01 22:20:39 +01:00
Bruno BELANYI 659e3f1c9a Make use of 'Bitboard::is_empty' 2024-04-01 22:20:39 +01:00
Bruno BELANYI f66b0276d8 Add 'Bitboard::is_empty' 2024-04-01 22:20:39 +01:00
Bruno BELANYI 9ef600c1bb Add 'Direction::slide_{square,board}' 2024-04-01 22:20:39 +01:00
Bruno BELANYI dc974ec0e9 Add 'Bitboard::{ANTI_,}DIAGONAL' 2024-04-01 22:20:39 +01:00
Bruno BELANYI 251c10cbc7 Add 'Direction::move_square' 2024-04-01 22:20:39 +01:00
Bruno BELANYI 1ab024fce8 Add 'Direction::iter_{rook,bishop,royalty,knight}' 2024-04-01 22:20:39 +01:00
Bruno BELANYI 924689ec02 Add 'Direction::move_board'
Encapsulates the way to move a piece on a board, avoiding the need to
mask and shift by hand.
2024-04-01 22:20:39 +01:00
Bruno BELANYI b840bfc570 Add 'board::Direction' enum 2024-04-01 22:20:39 +01:00
Bruno BELANYI c177d13b75 Use 'Square::index' in 'Square::{file,rank}_index' 2024-04-01 22:20:39 +01:00
Bruno BELANYI 281c79556a Add 'Square::index' 2024-04-01 22:20:39 +01:00
Bruno BELANYI 8261b0c06b Add 'Bitboard::count' 2024-04-01 22:20:39 +01:00
Bruno BELANYI 7a7e7f3665 Add 'Rank::{up,down}' 2024-04-01 22:20:39 +01:00
Bruno BELANYI 2b4797ec47 Add 'File::{left,right}' 2024-04-01 22:20:39 +01:00
Bruno BELANYI 6501466d3e Add 'Square' constructor from 'File', 'Rank' 2024-04-01 22:20:39 +01:00
Bruno BELANYI c3c3684150 Don't return 'Bitboard' from 'Square::{file,rank}' 2024-04-01 22:20:39 +01:00
Bruno BELANYI ef15da41ea Add 'File' enum 2024-04-01 22:20:39 +01:00
Bruno BELANYI 54d7f0d69f Add 'Rank' enum 2024-04-01 22:20:39 +01:00
Bruno BELANYI 47b1854669 Introduce 'Bitboard::ALL' 2024-04-01 22:20:39 +01:00
Bruno BELANYI a0fcf3285c Add bitboard iteration
Introduce 'BitboardIterator', use it to implement 'IntoIterator' for
'Bitboard'.
2024-04-01 22:20:39 +01:00
Bruno BELANYI f4a92c0681 Move 'board::bitboard' into folder module
I will be adding a 'BitboardIterator' type, and it makes more sense to
use a folder for this module at this point.
2024-04-01 22:20:39 +01:00
Bruno BELANYI 015485a4c5 Add 'Bitboard' and 'Square' definitions 2024-04-01 22:20:39 +01:00
Bruno BELANYI 44eb79f35b Move binary crate into 'bin' folder 2024-04-01 22:20:39 +01:00
Bruno BELANYI 3677040e03 Bootstrap project 2024-04-01 22:20:39 +01:00