Next / Previous / Contents / Shipman's homepage

34. Puzzle.whatSlots(): What slots intersect a given coordinate?

kkck
# - - -   P u z z l e . w h a t S l o t s

    def whatSlots ( self, coord ):
        '''Generate the slots that include a given location.
        '''

For the function that finds the Cell instance at a given location, see Section 32, “Puzzle.whatCell(): Is there a cell at a given coordinate?”. Each Cell instance contains a list of the slots that include it; see Section 51, “Cell.genSlots(): Generate the slots intersecting this cell”.

kkck
        #-- 1 --
        # [ if self has a cell at location (coord) ->
        #     cell  :=  that cell as a Cell instance
        #   else ->
        #     raise StopIteration ]
        cell = self.whatCell ( coord )
        if cell is None:
            raise StopIteration

        #-- 2 --
        for slot in cell.genSlots():
            yield slot

        #-- 3 --
        raise StopIteration