visualize.py 748 B

1234567891011121314151617
  1. from PySudoku import play
  2. def visualize_assignments(assignments):
  3. """ Visualizes the set of assignments created by the Sudoku AI"""
  4. last_assignment = None
  5. filtered_assignments = []
  6. for i in range(len(assignments)):
  7. if last_assignment:
  8. last_assignment_items = [item for item in last_assignment.items() if len(item[1]) == 1]
  9. current_assignment_items = [item for item in assignments[i].items() if len(item[1]) == 1]
  10. shared_items = set(last_assignment_items) & set(current_assignment_items)
  11. if len(shared_items) < len(current_assignment_items):
  12. filtered_assignments.append(assignments[i])
  13. last_assignment = assignments[i]
  14. play(filtered_assignments)