lib/chess/epd.rb
###
# Parses the given EPD string and uses it to set the position.
#
# If present the `hmvc` and the `fmvn` are used to set the half move
# clock and the fullmove number. Otherwise `0` and `1` are used.
#
# Returns a dictionary of parsed operations. Values can be strings,
# integers, floats or move objects.
#
# Raises `ArgumentError` if the EPD string is invalid.
###
Parses the given EPD string and uses it to set the position.
If present the `hmvc` and the `fmvn` are used to set the half move
clock and the fullmove number. Otherwise `0` and `1` are used.

Returns a dictionary of parsed operations. Values can be strings,
integers, floats or move objects.

Raises `ArgumentError` if the EPD string is invalid.
Parses the given EPD string and uses it to set the position . If present the ` hmvc ` and the ` fmvn ` are used to set the half move clock and the fullmove number . Otherwise ` 0 ` and ` 1 ` are used . Returns a dictionary of parsed operations . Values can be strings integers floats or move objects . Raises ` ArgumentError ` if the EPD string is invalid .
def epd(operations)
       EPD operations can be given as keyword arguments. Supported operands
       are strings, integers, floats and moves. All other operands are
       converted to strings.
       `hmvc` and `fmvc` are *not* included by default. You can use:
       >>> board.epd(hmvc=board.halfmove_clock, fmvc=board.fullmove_number)
       'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - hmvc 0; fmvc 1;'
      epd   = []
      empty = 0
       Position part.
      Board::SQUARES_180.each do |square|
        piece = get(square)
        if !piece
          empty += 1
        else
          if empty
            epd.push(empty.to_s)
            empty = 0
          end
          epd << piece.symbol
        end
        if Board::BB_SQUARES[square] & BB_FILE_H != 0
          if empty
            epd << empty.to_s
            empty = 0
          end
          if square != H1
            epd << '/'
          end
        end
      end
      epd << ' '
       Side to move.
      if @turn == Board::WHITE
        epd.push('w')
      else
        epd.push('b')
      end
      epd.push(' ')
       Castling rights.
      if !(castling_rights != 0)
        epd.push('-')
      else
        if castling_rights & Board::CASTLING_WHITE_KINGSIDE != 0
          epd.push('K')
        end
        if castling_rights & Board::CASTLING_WHITE_QUEENSIDE != 0
          epd.push('Q')
        end
        if castling_rights & Board::CASTLING_BLACK_KINGSIDE != 0
          epd.push('k')
        end
        if castling_rights & Board::CASTLING_BLACK_QUEENSIDE != 0
          epd.push('q')
        end
      end
      epd.push(' ')
       En-passant square.
      if ep_square
        epd.push(Board::SQUARE_NAMES[ep_square.to_sym])
      else
        epd.push('-')
      end
       Append operations.
      operations.items.each do |opcode, operand|
        epd.push(' ')
        epd.push(opcode)
        if operand.include?('from_square') && operand.include?('to_square')
           Append SAN for moves.
          epd.push(' ')
          epd.push(san(operand))
        elsif operand.is_numeric?
           Append integer or float.
          epd.push(' ')
          epd.push(operand.to_s)
        elsif operand
           Append as escaped string.
          epd.push('"')
          epd.push(operand.to_s.gsub("\r", "").gsub("\n", " ").gsub("\\", "\\\\").gsub(";", "\\s"))
          epd.push('"')
        end
        epd.push(';')
      end
      return epd.join('')
    end
def epd ( operations ) epd = [ ] empty = 0 Board :: SQUARES_180 . each do | square | piece = get ( square ) if ! piece empty += 1 else if empty epd . push ( empty . to_s ) empty = 0 end epd << piece . symbol end if Board :: BB_SQUARES [ square ] & BB_FILE_H != 0 if empty epd << empty . to_s empty = 0 end if square != H1 epd << '/' end end end epd << ' ' if @turn == Board :: WHITE epd . push ( 'w' ) else epd . push ( 'b' ) end epd . push ( ' ' ) if ! ( castling_rights != 0 ) epd . push ( '-' ) else if castling_rights & Board :: CASTLING_WHITE_KINGSIDE != 0 epd . push ( 'K' ) end if castling_rights & Board :: CASTLING_WHITE_QUEENSIDE != 0 epd . push ( 'Q' ) end if castling_rights & Board :: CASTLING_BLACK_KINGSIDE != 0 epd . push ( 'k' ) end if castling_rights & Board :: CASTLING_BLACK_QUEENSIDE != 0 epd . push ( 'q' ) end end epd . push ( ' ' ) if ep_square epd . push ( Board :: SQUARE_NAMES [ ep_square . to_sym ] ) else epd . push ( '-' ) end operations . items . each do | opcode , operand | epd . push ( ' ' ) epd . push ( opcode ) if operand . include? ( 'from_square' ) && operand . include? ( 'to_square' ) epd . push ( ' ' ) epd . push ( san ( operand ) ) elsif operand . is_numeric? epd . push ( ' ' ) epd . push ( operand . to_s ) elsif operand epd . push ( '"' ) epd . push ( operand . to_s . gsub ( "\r" , "" ) . gsub ( "\n" , " " ) . gsub ( "\\" , "\\\\" ) . gsub ( ";" , "\\s" ) ) epd . push ( '"' ) end epd . push ( ';' ) end return epd . join ( '' ) end
Parses the given EPD string and uses it to set the position.
Parses the given EPD string and uses it to set the position .
### # Gets an EPD representation of the current position. # # EPD operations can be given as keyword arguments. Supported operands # are strings, integers, floats and moves. All other operands are # converted to strings. # # `hmvc` and `fmvc` are *not* included by default. You can use: # # >>> board.epd(hmvc=board.halfmove_clock, fmvc=board.fullmove_number) # 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - hmvc 0; fmvc 1;' ### # Position part. # Side to move. # Castling rights. # En-passant square. # Append operations. # Append SAN for moves. # Append integer or float. # Append as escaped string.
operations
<not_specific>