1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
//! # Unmoved Rooks
//!
//! Tracks which rooks have not yet moved from their original starting squares.
//! This information is critical for determining castling rights.
//!
//! ### Castling Eligibility
//! In chess, a player can only castle if:
//! 1. The king has never moved.
//! 2. The chosen rook has never moved.
//!
//! While the king's movement is often tracked separately (or by checking if any
//! unmoved rooks remain for that color), [`UnmovedRooks`] specifically maintains
//! a bitmask of squares that currently contain a rook that has never left its
//! initial position.
//!
//! ---
//!
//! ## How it Works
//!
//! [`UnmovedRooks`] is a specialized [`Bitboard`] wrapper. It starts with bits
//! set at the four corners of the board (A1, H1, A8, and H8). Whenever a move
//! occurs, the bits corresponding to both the **origin** and **destination**
//! squares are cleared.
//!
//! - **Origin:** If a rook moves, it is no longer "unmoved".
//! - **Destination:** If an unmoved rook is captured, it is removed from the board,
//! and thus can no longer be used for castling.
//!
//! ## Example
//!
//! ```
//! # use ruchess::unmoved_rooks::UnmovedRooks;
//! # use ruchess::square;
//! # use ruchess::mve::Move;
//! # use ruchess::board::Board;
//! # use ruchess::piece::Piece;
//! # use ruchess::role::Role;
//! # use ruchess::color::Color;
//! let mut ur = UnmovedRooks::standard();
//!
//! // Initially, all four rooks are "unmoved"
//! assert!(ur.contains(square::A1));
//! assert!(ur.contains(square::H1));
//! assert!(ur.contains(square::A8));
//! assert!(ur.contains(square::H8));
//!
//! // Suppose white moves the rook from A1 to A3
//! # let board = Board::new();
//! # let m = Move::quiet(
//! # Piece { role: Role::Rook, color: Color::White },
//! # square::A1,
//! # square::A3,
//! # board,
//! # );
//! ur = ur.update(&m);
//!
//! assert!(!ur.contains(square::A1)); // No longer unmoved
//! assert!(ur.contains(square::H1)); // H1 rook is still unmoved
//! ```
use crate::;
/// A bitmask of squares that contain rooks that have never moved.
///
/// This structure is used to track castling rights by maintaining a [`Bitboard`]
/// of original rook squares that have not been the origin or destination of any move.
;