Next / Previous / Contents / Shipman's homepage

25. Puzzle.__buildSlotChoices(): Build the initial set of choices for one slot

kkck
# - - -   P u z z l e . _ _ b u i l d S l o t C h o i c e s

    def __buildSlotChoices ( self, slot ):
        '''Populate a slot with all its initial choices.

          [ slot is a Slot in self ->
              self.__wordBank  +:=  choices for slot that are
                  consistent with any clues in self.__cellMap ]
        '''

There are two constraints on the word choices for a slot. Clearly, the word must be the correct length; see Section 66, “WordBank.genCandidates(): What words have a given length?”. Also, if any initial clues are given in positions inside the slot, we may be able to use those characters to eliminate some of the choices.

kkck
        #-- 1 --
        # [ choiceList  :=  all the words from self.__wordBank
        #       of length len(slot), as a set of Word instances ]
        choiceList  =  set ( [ word
            for word in self.__wordBank.genCandidates(len(slot)) ] )

For the function that compares choices to a given clue, see Section 26, “Puzzle.__clueCheck(): Eliminate initial choices conflicting with clues”.

kkck
        #-- 2 --
        # [ choiceList  :=  choiceList - (any choices that
        #       conflict with clues that may exist in any of the
        #       Cell instances lying within slot) ]
        for k in range(len(slot)):
            #-- 2 body --
            # [ if the cell at slot[k] contains a clue letter ->
            #     choiceList  :=  choiceList - (any word not
            #         having that letter at position [k])
            #   else -> I ]
            self.__clueCheck ( choiceList, slot, k )

The choices that remain are recording using Section 67, “WordBank.mayBe(): Add one word choice to a slot”.

kkck
        #-- 3 --
        for choice in choiceList:
            self.__wordBank.mayBe ( slot, choice )

        if VERBOSE:
            print "    = %s: " % slot,
            for choice in sorted(list(choiceList)):
                print choice,
            print