pgn_read/core/game.py
def generate_fen_for_position(pieces,
                              active_color,
                              castling_availability,
                              en_passant_target_square,
                              halfmove_clock,
                              fullmove_number):
    """Return Forsyth English Notation (FEN) string for Game position."""
    rank = 0
    file = -1
    chars = []
    for p in sorted(pieces):
        pr = RANK_NAMES.index(p.square.rank)
        pf = FILE_NAMES.index(p.square.file)
        if pr != rank:
            if file != 7:
                chars.append(str(7 - file))
            chars.append('/')
            while True:
                rank += 1
                if pr == rank:
                    file = -1
                    break
                chars.append('8/')
            else:
                continue
        if pf != file:
            if pf - file > 1:
                chars.append(str(pf - file - 1))
            chars.append(p.name)
            file = pf
        else:
            chars.append(p.name)
    if file != 7:
        chars.append(str(7 - file))
    while True:
        if rank == 7:
            break
        chars.append('/8')
        rank += 1
    fen = ' '.join((''.join(chars),
                    active_color,
                    castling_availability,
                    en_passant_target_square,
                    str(halfmove_clock),
                    str(fullmove_number)))
    return fen
Return Forsyth English Notation (FEN) string for Game position.
Return Forsyth English Notation (FEN) string for Game position.
Return Forsyth English Notation ( FEN ) string for Game position .
def generate_fen_for_position(pieces,
                              active_color,
                              castling_availability,
                              en_passant_target_square,
                              halfmove_clock,
                              fullmove_number):
    rank = 0
    file = -1
    chars = []
    for p in sorted(pieces):
        pr = RANK_NAMES.index(p.square.rank)
        pf = FILE_NAMES.index(p.square.file)
        if pr != rank:
            if file != 7:
                chars.append(str(7 - file))
            chars.append('/')
            while True:
                rank += 1
                if pr == rank:
                    file = -1
                    break
                chars.append('8/')
            else:
                continue
        if pf != file:
            if pf - file > 1:
                chars.append(str(pf - file - 1))
            chars.append(p.name)
            file = pf
        else:
            chars.append(p.name)
    if file != 7:
        chars.append(str(7 - file))
    while True:
        if rank == 7:
            break
        chars.append('/8')
        rank += 1
    fen = ' '.join((''.join(chars),
                    active_color,
                    castling_availability,
                    en_passant_target_square,
                    str(halfmove_clock),
                    str(fullmove_number)))
    return fen
def generate_fen_for_position ( pieces , active_color , castling_availability , en_passant_target_square , halfmove_clock , fullmove_number ) : rank = 0 file = - 1 chars = [ ] for p in sorted ( pieces ) : pr = RANK_NAMES . index ( p . square . rank ) pf = FILE_NAMES . index ( p . square . file ) if pr != rank : if file != 7 : chars . append ( str ( 7 - file ) ) chars . append ( '/' ) while True : rank += 1 if pr == rank : file = - 1 break chars . append ( '8/' ) else : continue if pf != file : if pf - file > 1 : chars . append ( str ( pf - file - 1 ) ) chars . append ( p . name ) file = pf else : chars . append ( p . name ) if file != 7 : chars . append ( str ( 7 - file ) ) while True : if rank == 7 : break chars . append ( '/8' ) rank += 1 fen = ' ' . join ( ( '' . join ( chars ) , active_color , castling_availability , en_passant_target_square , str ( halfmove_clock ) , str ( fullmove_number ) ) ) return fen
Return Forsyth English Notation (FEN) string for Game position.
Return Forsyth English Notation ( FEN ) string for Game position .
"""Return Forsyth English Notation (FEN) string for Game position."""
pieces
active_color
castling_availability
en_passant_target_square
halfmove_clock
fullmove_number