Next / Previous / Contents / Shipman's homepage

30. Puzzle.__showRow(): Show one row of the puzzle

kkck
# - - -   P u z z l e . _ _ s h o w R o w

    def __showRow ( self, rowList, rowx ):
        '''Display the [rowx]th row of the puzzle's state
        '''

This method requires that the slots have been set up with choices, that is, Section 24, “Puzzle.__buildChoices(): Set up initial word choices” has already been called. We interrogate Section 72, “WordBank.cellChoices(): What characters are choices at a given coordinate?” for the content of each location. That method returns a space for empty locations, or a string containing all remaining choices here. If this string is a single character, we display that character. If the string has multiple choices, we display the UNK_CELL character because this cell has not yet been solved.

kkck
        #-- 1 --
        # [ L  :=  a list containing the row label ]
        L = [ '%02d|' % rowx ]

        #-- 2 --
        # [ L  +:=  characters illustrating the puzzle's state
        #           in row (rowx) ]
        for colx in range(self.size[1]):
            #-- 2 body --
            # [ if puzzle is empty at (rowx, colx) ->
            #     L  +:=  one space
            #   else if puzzle has a single choice at (rowx, colx) ->
            #     L  +:=  that character
            #   else ->
            #     L  +:=  UNK_CELL ]
            textSet = self.__wordBank.cellChoices ( Coord(rowx, colx) )
            text = ''.join(list(textSet))
            if len(text) == 1:
                L.append ( text )
            else:
                L.append ( UNK_CELL )
            L.append (' ')

        #-- 3 --
        L.pop()
        L.append ( "|")

        #-- 4 --
        rowList.append ( ''.join(L) )