Ejemplo n.º 1
0
def run(sudoku, verbose=0):
    """
    :type sudoku: Sudoku
    :type verbose: int
    """
    changes = 0
    if verbose:
        Colors.blue("[*] Technique: PointingPairs".format(changes))
        sudoku.print()
    for _, row in sudoku.rows.items():
        changes += _pointing_pairs_test(sudoku, row, verbose)
        if changes:
            if verbose:
                Colors.green("[+] PointingPairs (Row) > Changes: {}".format(changes))
                # sudoku.print()
            return changes
    for _, col in sudoku.cols.items():
        changes += _pointing_pairs_test(sudoku, col, verbose)
        if changes:
            if verbose:
                Colors.green("[+] PointingPairs (Col) > Changes: {}".format(changes))
                # sudoku.print()
            return changes
    if verbose:
        Colors.red("[+] PointingPairs > No changes".format(changes))
        # sudoku.print()
    return changes
Ejemplo n.º 2
0
def run(sudoku, verbose=0):
    changes = 0
    if verbose:
        Colors.blue("[*] Technique: SimpleColouring".format(changes))
        # sudoku.print()
    all_doubles = _get_doubles(sudoku, verbose)
    for poss, doubles in all_doubles.items():
        changes += _colouring(sudoku, poss, doubles, verbose)
    return changes
Ejemplo n.º 3
0
def run(sudoku, verbose=0):
    changes = 0
    if verbose >= 2:
        Colors.blue("[*] Technique: Hidden Singles".format(changes))
        # sudoku.print()
    for _, region in sudoku.regions.items():
        changes += _hidden_singles_test(sudoku, region, verbose)
        if changes:
            if verbose >= 2:
                Colors.green("[+] Hidden Singles > Changes: {}".format(changes))
                # sudoku.print()
            return changes
    if verbose >= 2:
        Colors.red("[-] Hidden Singles > No change".format(changes))
        # sudoku.print()
    return changes
Ejemplo n.º 4
0
 def solve_current_puzzle_file(self, verbose=0, chucksize=42):
     changes = 0
     count = 0
     solved = 0
     start = time()
     middle_time = time()
     try:
         Colors.yellow(self.update.format(0, 0, 0, 0, 0), end="\r")
         while True:
             su = self.next_sudoku()
             count += 1
             if verbose >= 2:
                 Colors.blue("[*] Puzzle #{}".format(count))
             if verbose >= 4:
                 su.print()
             changes += self.solve_current_sudoku(verbose)
             if verbose >= 4:
                 su.print()
             if self.check_sudoku(su, verbose):
                 solved += 1
             if verbose == 1 and count % chucksize == 0:
                 total_duration = time() - start
                 duration = time() - middle_time
                 middle_time = time()
                 Colors.yellow(self.update.format(count,
                                                  changes,
                                                  (solved / count) * 100,
                                                  total_duration,
                                                  chucksize / duration),
                               end="\r")
             # input("Press Enter to continue...")
     except StopIteration:
         if verbose >= 2:
             Colors.blue("[*] End of puzzle file.")
         pass
     end = time()
     total_time = end - start
     status_message = self.status.format(self.current_puzzles,
                                         changes,
                                         solved,
                                         count,
                                         (solved / count) * 100,
                                         total_time,
                                         count / total_time)
     if verbose >= 2:
         print(status_message)
     return changes, solved, count, status_message
Ejemplo n.º 5
0
def run(sudoku, verbose=0):
    changes = 0
    if verbose >= 2:
        Colors.blue("[*] Technique: HiddenPairs".format(changes))
        # s.print()
    for tag, row in sudoku.rows.items():
        changes = _find_hidden_pairs(sudoku, row, verbose=verbose)
    for tag, col in sudoku.cols.items():
        changes = _find_hidden_pairs(sudoku, col, verbose=verbose)
    for tag, area in sudoku.areas.items():
        changes = _find_hidden_pairs(sudoku, area, verbose=verbose)
    if changes:
        if verbose >= 2:
            Colors.green("[+] HiddenPairs > Changes: {}".format(changes))
        if verbose >= 4:
            sudoku.print()
    return changes
Ejemplo n.º 6
0
def run(s, verbose=0):
    changes = 0
    if verbose >= 2:
        Colors.blue("[*] Technique: NakedSingles".format(changes))
    if verbose >= 4:
        s.print()
    for loc, poss in s.fields.items():
        if len(poss) == 1:
            changes += _eliminate_from_regions(s, loc, poss, verbose)
    if changes:
        if verbose >= 2:
            Colors.green("[+] NakedSingles > Changes: {}".format(changes))
        if verbose >= 4:
            s.print()
        return changes
    if verbose >= 2:
        Colors.red("[-] NakedSingles > No change".format(changes))
    if verbose >= 4:
        s.print()
    return changes