Print stuff in backtracking module only; clean up the \r stuff
This commit is contained in:
		
							parent
							
								
									3b380b17d2
								
							
						
					
					
						commit
						a7dda24015
					
				
					 2 changed files with 6 additions and 4 deletions
				
			
		|  | @ -162,7 +162,6 @@ class Sudoku: | |||
|         if idx in self._clues: | ||||
|             raise SquareIsClue('Cannot set clue square ({},{})'.format(x, y)) | ||||
|         self._board[idx] = value | ||||
|         print('({},{}) <- {} {!r}'.format(x, y, value, self)) | ||||
| 
 | ||||
|     def _xy_to_idx(self, x, y): | ||||
|         return y * self.row_size + x | ||||
|  |  | |||
|  | @ -26,8 +26,10 @@ def _solve_square(sudoku, x, y): | |||
|             continue | ||||
|         except NoPossibleValues: | ||||
|             # Need to backtrack. | ||||
|             sudoku.unset(x, y) | ||||
|             raise Backtrack() | ||||
|             should_backtrack = True | ||||
|             break | ||||
| 
 | ||||
|         print('\r{!r}'.format(sudoku), end='', flush=True) | ||||
| 
 | ||||
|         next_coord = _next_coord(sudoku, x, y) | ||||
|         if not next_coord: | ||||
|  | @ -40,13 +42,14 @@ def _solve_square(sudoku, x, y): | |||
|             continue | ||||
| 
 | ||||
|     if should_backtrack: | ||||
|         # Unhandled backtrack. Pop out of this one too. | ||||
|         try: | ||||
|             sudoku.unset(x, y) | ||||
|         except SquareIsClue: | ||||
|             pass | ||||
|         raise Backtrack() | ||||
| 
 | ||||
|     print() | ||||
| 
 | ||||
|     return sudoku | ||||
| 
 | ||||
| def _next_coord(sudoku, x, y): | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue