pub fn fen(&self) -> String {
        let mut res = String::new();

        for rank in (0..SIZE).rev() {
            let mut cur_empty_square: u8 = 0;
            for file in 0..SIZE {
                let sq = Sq::new(rank, file);
                if let Some(entity) = self.find(sq, None, None) {
                    if cur_empty_square > 0 {
                        res.push_str(&format!("{}", cur_empty_square));
                        cur_empty_square = 0;
                    }
                    let team_label: &str = entity.kind.into();
                    match entity.team {
                        Team::White => res.push_str(team_label),
                        Team::Black => res.push_str(&team_label.to_lowercase()),
                    };
                } else {
                    cur_empty_square += 1;
                }
            }
            if cur_empty_square > 0 {
                res.push_str(&format!("{}", cur_empty_square));
            }
            // Last row does not need a delimitor.
            if rank != 0 {
                res.push('/');
            }
        }
        res.push_str(&format!(
            " {} {} ",
            self.turn().abrev().to_lowercase(),
            self.castling.fen()
        ));

        match self.en_passant_target_square {
            None => res.push('-'),
            Some(sq) => res.push_str(&format!("{}", sq)),
        }

        res.push_str(&format!(" {} {}", self.halfmove, self.fullmove));
        res
    }
/// Generates a FEN for the given board position.
/// https://en.wikipedia.org/wiki/Forsyth%E2%80%93Edwards_Notation
Generates a FEN for the given board position.
Generates a FEN for the given board position .
pub fn fen(&self) -> String {
        let mut res = String::new();
        for rank in (0..SIZE).rev() {
            let mut cur_empty_square: u8 = 0;
            for file in 0..SIZE {
                let sq = Sq::new(rank, file);
                if let Some(entity) = self.find(sq, None, None) {
                    if cur_empty_square > 0 {
                        res.push_str(&format!("{}", cur_empty_square));
                        cur_empty_square = 0;
                    }
                    let team_label: &str = entity.kind.into();
                    match entity.team {
                        Team::White => res.push_str(team_label),
                        Team::Black => res.push_str(&team_label.to_lowercase()),
                    };
                } else {
                    cur_empty_square += 1;
                }
            }
            if cur_empty_square > 0 {
                res.push_str(&format!("{}", cur_empty_square));
            }
            // Last row does not need a delimitor.
            if rank != 0 {
                res.push('/');
            }
        }
        res.push_str(&format!(
            " {} {} ",
            self.turn().abrev().to_lowercase(),
            self.castling.fen()
        ));
        match self.en_passant_target_square {
            None => res.push('-'),
            Some(sq) => res.push_str(&format!("{}", sq)),
        }
        res.push_str(&format!(" {} {}", self.halfmove, self.fullmove));
        res
    }
pub fn fen ( & self ) -> String { let mut res = String :: new ( ) ; for rank in ( 0 .. SIZE ) . rev ( ) { let mut cur_empty_square : u8 = 0 ; for file in 0 .. SIZE { let sq = Sq :: new ( rank , file ) ; if let Some ( entity ) = self . find ( sq , None , None ) { if cur_empty_square > 0 { res . push_str ( & format ! ( " " cur_empty_square ) ) ; cur_empty_square = 0 ; } let team_label : & str = entity . kind . into ( ) ; match entity . team { Team :: White => res . push_str ( team_label ) , Team :: Black => res . push_str ( & team_label . to_lowercase ( ) ) , } ; } else { cur_empty_square += 1 ; } } if cur_empty_square > 0 { res . push_str ( & format ! ( " " cur_empty_square ) ) ; } // Last row does not need a delimitor. if rank != 0 { res . push ( '/' ) ; } } res . push_str ( & format ! ( " " self turn ( ) abrev ( ) to_lowercase ( ) self castling fen ( ) ) ) ; match self . en_passant_target_square { None => res . push ( '-' ) , Some ( sq ) => res . push_str ( & format ! ( " " sq ) ) , } res . push_str ( & format ! ( " " self halfmove self fullmove ) ) ; res }
Generates a FEN for the given board position.
Generates a FEN for the given board position .
&self
&self