nozaq / shogi-rs

A Bitboard-based shogi library in Rust. Board representation, move generation/validation and time control utilities.
https://docs.rs/shogi/latest/shogi/
MIT License
46 stars 3 forks source link

Incorrect parsing of SFEN with 10 or more pieces of the same type in hands #24

Closed na2hiro closed 3 years ago

na2hiro commented 3 years ago

I found that parsing of pieces in hands doesn't properly handle the case when the number of pieces are 10 (2 digit number) or more. In this example, White should have 17 Pawns, but it results in 7:

use shogi::{Move, Position, Color, Piece, Square};
use shogi::bitboard::Factory as BBFactory;
use shogi::piece_type::PieceType;

fn main() {
    BBFactory::init();
    let mut pos = Position::new();

    let sfen = "7k1/9/7P1/9/9/9/9/9/9 b G2r2b3g4s4n4l17p 1";
    pos.set_sfen(sfen).unwrap();
    assert_eq!(pos.hand(Piece{piece_type: PieceType::Pawn, color: Color::White}), 17, "pawn count");
}
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `7`,
 right: `17`: pawn count', src/main.rs:15:5

parse_sfen_hand seems to omit leading digits.