This function writes one row of the puzzle's state to
the given outFile. For the
overall output design, see Section 5.9, “SudokuSolver.write():
Output the state of the puzzle”.
# - - - S u d o k u S o l v e r . w r i t e R o w - - -
def writeRow ( self, outFile, rowx ):
"""Display one row in plain text.
[ (outFile is a writeable file) and
(rowx is in [0,MAT_L) ->
outFile +:= a representation of row rowx of self ]
"""
#-- 1 --
for colx in range(MAT_L):
#-- 1 body --
# [ sys.stdout +:= a representation of the cell at
# row rowx and column colx ]
#-- 1.1 --
# [ c := self's cell at (rowx,colx) in character
# form ]
cell = self.get ( rowx, colx )
if cell == 0: c = '.'
else: c = chr ( ord ( '0' ) + cell )
#-- 1.2 --
# [ sys.stdout +:= c ]
if ( ( colx > 0 ) and
( ( colx % SUBMAT_L ) == 0 ) ):
print >>outFile, " ",
print >>outFile, c,
Having written the line's contents, it is now our job to terminate it.
#-- 2 --
print >>outFile
For a discussion of the verification of this method, see
Section 7.5, “Inspection: SudokuSolver.writeRow()”.