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
//! Fast shogi legal move generation on [`shogi_core`] types.
//!
//! Everything [`Position`] generates is **fully legal**, pawn-drop mate
//! (打ち歩詰め) included, so a caller never filters what it is handed.
//!
//! [`Position::legal_moves`] is the convenient way to take them:
//!
//! ```
//! use shunsai::Position;
//!
//! let position = Position::startpos();
//! assert_eq!(position.legal_moves().len(), 30);
//! ```
//!
//! [`Position::generate_moves`] is the fast way. It yields one [`MoveSet`]
//! per origin, destinations still packed as a [`Bitboard`], so a caller that
//! only needs to count them never builds a [`Move`](shogi_core::Move) at all
//! — and can stop early by returning [`ControlFlow::Break`]:
//!
//! ```
//! use core::ops::ControlFlow;
//! use shunsai::Position;
//!
//! let position = Position::startpos();
//! let mut moves = 0;
//! let _ = position.generate_moves(|set| {
//! moves += set.len();
//! ControlFlow::Continue(())
//! });
//! assert_eq!(moves, 30);
//! ```
//!
//! Moves are played and taken back with [`Position::do_move`] and
//! [`Position::undo_move`], which maintain the Zobrist [`Position::key`]
//! incrementally.
//!
//! [`ControlFlow::Break`]: core::ops::ControlFlow::Break
pub use Bitboard;
pub use ;
pub use ;
pub use shogi_core;