(self, epd)
return operations
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 ply. Otherwise `0` and `1` are used.

        :return: A dictionary of parsed operations. Values can be strings,
                 integers, floats or move objects.

        :raises ValueError: If the EPD string is invalid.
Parses the given EPD string and uses it to set the position.
Parses the given EPD string and uses it to set the position .
def set_epd(self, epd):
        """
        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 ply. Otherwise `0` and `1` are used.

        :return: A dictionary of parsed operations. Values can be strings,
                 integers, floats or move objects.

        :raises ValueError: If the EPD string is invalid.
        """
        # Split into 4 or 5 parts.
        parts = epd.strip().rstrip(";").split(None, 4)
        if len(parts) < 4:
            raise ValueError("EPD should consist of at least 4 parts.")

        operations = { }

        # Parse the operations.
        if len(parts) > 4:
            operation_part = parts.pop()
            operation_part += ";"

            opcode = ""
            operand = ""
            in_operand = False
            in_quotes = False
            escape = False

            position = None

            for c in operation_part:
                if not in_operand:
                    if c == ";":
                        operations[opcode] = None
                        opcode = ""
                    elif c == " ":
                        if opcode:
                            in_operand = True
                    else:
                        opcode += c
                else:
                    if c == "\"":
                        if not operand and not in_quotes:
                            in_quotes = True
                        elif escape:
                            operand += c
                    elif c == "\\":
                        if escape:
                            operand += c
                        else:
                            escape = True
                    elif c == "s":
                        if escape:
                            operand += ";"
                        else:
                            operand += c
                    elif c == ";":
                        if escape:
                            operand += "\\"

                        if in_quotes:
                            operations[opcode] = operand
                        else:
                            try:
                                operations[opcode] = int(operand)
                            except ValueError:
                                try:
                                    operations[opcode] = float(operand)
                                except ValueError:
                                    if position is None:
                                        position = self.__class__(" ".join(parts + ["0", "1"]))

                                    operations[opcode] = position.parse_san(operand)

                        opcode = ""
                        operand = ""
                        in_operand = False
                        in_quotes = False
                        escape = False
                    else:
                        operand += c

        # Create a full FEN and parse it.
        parts.append(str(operations["hmvc"]) if "hmvc" in operations else "0")
        parts.append(str(operations["fmvn"]) if "fmvn" in operations else "1")
        self.set_fen(" ".join(parts))

        return operations
def set_epd ( self , epd ) : # Split into 4 or 5 parts. parts = epd . strip ( ) . rstrip ( ";" ) . split ( None , 4 ) if len ( parts ) < 4 : raise ValueError ( "EPD should consist of at least 4 parts." ) operations = { } # Parse the operations. if len ( parts ) > 4 : operation_part = parts . pop ( ) operation_part += ";" opcode = "" operand = "" in_operand = False in_quotes = False escape = False position = None for c in operation_part : if not in_operand : if c == ";" : operations [ opcode ] = None opcode = "" elif c == " " : if opcode : in_operand = True else : opcode += c else : if c == "\"" : if not operand and not in_quotes : in_quotes = True elif escape : operand += c elif c == "\\" : if escape : operand += c else : escape = True elif c == "s" : if escape : operand += ";" else : operand += c elif c == ";" : if escape : operand += "\\" if in_quotes : operations [ opcode ] = operand else : try : operations [ opcode ] = int ( operand ) except ValueError : try : operations [ opcode ] = float ( operand ) except ValueError : if position is None : position = self . __class__ ( " " . join ( parts + [ "0" , "1" ] ) ) operations [ opcode ] = position . parse_san ( operand ) opcode = "" operand = "" in_operand = False in_quotes = False escape = False else : operand += c # Create a full FEN and parse it. parts . append ( str ( operations [ "hmvc" ] ) if "hmvc" in operations else "0" ) parts . append ( str ( operations [ "fmvn" ] ) if "fmvn" in operations else "1" ) self . set_fen ( " " . join ( parts ) ) return operations