pub struct MoveByMoveDecoder<'a> { /* private fields */ }Expand description
Iterator to decode a game move by move, rather than all at once.
This allows for more fine-grained processing than decode_game.
§Examples
let encoded = encode_pgn("1. e4 c5 2. Nf3 e6 3. c3 d5 4. exd5")?;
let mut capture_count = 0;
let mut decoder = MoveByMoveDecoder::new(&encoded);
for d in decoder.into_iter_moves_and_positions() {
let (mv, _) = d?;
if mv.is_capture() {
capture_count += 1;
}
}
assert_eq!(capture_count, 1);Implementations§
Source§impl<'a> MoveByMoveDecoder<'a>
impl<'a> MoveByMoveDecoder<'a>
Sourcepub fn new(encoded: &'a EncodedGame) -> Self
pub fn new(encoded: &'a EncodedGame) -> Self
Construct a new MoveByMoveDecoder from an EncodedGame.
Source§impl MoveByMoveDecoder<'_>
impl MoveByMoveDecoder<'_>
Sourcepub fn next_move(&mut self) -> Option<DecodeResult<Move>>
pub fn next_move(&mut self) -> Option<DecodeResult<Move>>
Returns the next move.
Sourcepub fn next_position(&mut self) -> Option<DecodeResult<&Chess>>
pub fn next_position(&mut self) -> Option<DecodeResult<&Chess>>
Returns the resulting position when the next move is played.
Sourcepub fn next_move_and_position(&mut self) -> Option<DecodeResult<(Move, &Chess)>>
pub fn next_move_and_position(&mut self) -> Option<DecodeResult<(Move, &Chess)>>
Returns the next move and the resulting position when the move is played.
Sourcepub fn into_iter_moves(self) -> impl Iterator<Item = DecodeResult<Move>>
pub fn into_iter_moves(self) -> impl Iterator<Item = DecodeResult<Move>>
Turns the decoder into an iterator over the moves in the chess game.
As soon as an error is encountered, all subsequent iterations yield the same error.
Sourcepub fn into_iter_positions(self) -> impl Iterator<Item = DecodeResult<Chess>>
pub fn into_iter_positions(self) -> impl Iterator<Item = DecodeResult<Chess>>
Turns the decoder into an iterator over the positions in the chess game. The first yielded position is the position after the first move.
As soon as an error is encountered, all subsequent iterations yield the same error.
Sourcepub fn into_iter_moves_and_positions(
self,
) -> impl Iterator<Item = DecodeResult<(Move, Chess)>>
pub fn into_iter_moves_and_positions( self, ) -> impl Iterator<Item = DecodeResult<(Move, Chess)>>
Turns the decoder into an iterator over the moves and positions in the chess game. The yielded position is the position after the move.
As soon as an error is encountered, all subsequent iterations yield the same error.