The setup proceeds in this order: initialize the internal data structures; read the puzzle file; find the slots; and set up the initial choices for each slot.
# - - - P u z z l e . _ _ i n i t _ _
def __init__ ( self, inFile ):
'''Read and initialize the puzzle.
'''
#-- 1 --
self.inFile = inFile
self.size = Coord ( 0, 0 )
self.__cellMap = {}
self.__slotMap = {}
For the input logic, see Section 15, “Puzzle.__input(): Read the puzzle
file”.
#-- 2 --
# [ if inFile contains a valid puzzle file ->
# inFile := inFile advanced to end of file
# self.size[0] := max ( self.size[0], number of
# rows in the framework part of inFile )
# self.size[1] := max ( size[1], length of
# longest row in the framework part of inFile )
# self.__cellMap +:= entries mapping cell
# coordinates from inFile to new Cell instances
# self.__slotMap +:= entries mapping slot
# coordinates from inFile to new Slot instances
# self.__wordBank := a new WordBank instance
# representing the word list from inFile, with
# no initial slot choices
# else -> raise SyntaxError ]
self.__input ( inFile )
inFile.close()
For the logic that populates the slots with choices, see
Section 24, “Puzzle.__buildChoices(): Set up initial
word choices”.
#-- 3 --
# [ self.__wordBank +:= choices for slots in
# self.__slotMap that are consistent with any
# clues in self.__cellMap ]
self.__buildChoices()