Exemplo n.º 1
0
    def adjacent_railroad_moves(cls, spec, orig_position, position, corner):
        """Gets adjacent railroad moves and is used for traversing the
        railroad.

        To use this function correctly, you must know:
        - the type of a piece
        - which is at a specific position
        - that it can travel to some other position on the railroad
        - whether traveling to this other position consists of moving
          around a railroad corner

        These things correspond to the arguments to the function.

        The return value is a dict mapping Coord objects to either
        'RAILROAD' or 'RAILROAD_CORNER', depending on the move type.
        """
        def component_values(line):
            for position_component, line_component in zip(position, line):
                values = (position_component - 1, position_component,
                          position_component + 1)

                yield tuple(val for val in values if val in line_component)

        for line in cls.nonabsolute_railroad_lines():
            if (match_sequence(position, line)
                    and (not spec or spec.railroad_corners
                         or match_sequence(orig_position, line))):
                new_corner = corner
                if new_corner is False:
                    new_corner = not match_sequence(orig_position, line)

                for components in product(*component_values(line)):
                    if components != position:
                        yield components, new_corner
Exemplo n.º 2
0
    def position_match(cls, position, matchval):
        """Check whether a position matches a given matchval.

        This supports both match_sequence based matching and matching based
        on the Space object at the given position.
        """

        if isinstance(matchval, Space):
            return cls.position_spec(position) == matchval
        else:
            return match_sequence(position, matchval)
Exemplo n.º 3
0
    def position_match(cls, position, matchval):
        """Check whether a position matches a given matchval.

        This supports both match_sequence based matching and matching based
        on the Space object at the given position.
        """

        if isinstance(matchval, Space):
            return cls.position_spec(position) == matchval
        else:
            return match_sequence(position, matchval)
Exemplo n.º 4
0
    def adjacent_railroad_moves(cls, spec, orig_position, position, corner):
        def component_values(line):
            for position_component, line_component in zip(position, line):
                values = (position_component - 1,
                          position_component,
                          position_component + 1)

                yield tuple(val for val in values
                                if val in line_component)

        for line in cls.nonabsolute_railroad_lines():
            if (match_sequence(position, line) and
                (not spec or
                 spec.railroad_corners or
                 match_sequence(orig_position, line))):
                new_corner = corner
                if new_corner is False:
                    new_corner = not match_sequence(orig_position, line)

                for components in product(*component_values(line)):
                    if components != position:
                        yield components, new_corner
Exemplo n.º 5
0
    def adjacent_railroad_moves(cls, spec, orig_position, position, corner):
        """Gets adjacent railroad moves and is used for traversing the
        railroad.

        To use this function correctly, you must know:
        - the type of a piece
        - which is at a specific position
        - that it can travel to some other position on the railroad
        - whether traveling to this other position consists of moving
          around a railroad corner

        These things correspond to the arguments to the function.

        The return value is a dict mapping Coord objects to either
        'RAILROAD' or 'RAILROAD_CORNER', depending on the move type.
        """

        def component_values(line):
            for position_component, line_component in zip(position, line):
                values = (position_component - 1,
                          position_component,
                          position_component + 1)

                yield tuple(val for val in values
                                if val in line_component)

        for line in cls.nonabsolute_railroad_lines():
            if (match_sequence(position, line) and
                (not spec or
                 spec.railroad_corners or
                 match_sequence(orig_position, line))):
                new_corner = corner
                if new_corner is False:
                    new_corner = not match_sequence(orig_position, line)

                for components in product(*component_values(line)):
                    if components != position:
                        yield components, new_corner