Exemplo n.º 1
0
def checkBoard(sudBoard, square):
    """
    Winnow the board's domains based on a placement in `square`,
    assuming the value has already been placed there.
    """
    row, col = square
    newValue = sudBoard.values[row][col]
    domainers = bookkeeping.affectedSquaresFor(square)
    for modSquare in domainers:
        row, col = modSquare
        sudBoard.domains[row][col].discard(newValue)
Exemplo n.º 2
0
def _trySquare(sudBoard, square, value):
    """ Checks constrainingness for a value of a square on its neighbors """
    # `allowance` is the count of all remaining neighboring
    # domain values after setting `value` in `square`.
    allowance = 0
    for testDomain in [sudBoard.domains[row][col] for row, col
                       in bookkeeping.affectedSquaresFor(square)]:
        discardDomain = testDomain.copy()
        discardDomain.discard(value)
        allowance += len(discardDomain)

    return allowance
Exemplo n.º 3
0
def _trySquare(sudBoard, square, value):
    """
    Checks the consistency of a particular board placement
    against every other applicable board square.
    
    """
    for testDomain in [sudBoard.domains[row][col] for row, col
                       in bookkeeping.affectedSquaresFor(square)]:
        if len(testDomain) == 1:
            discardDomain = testDomain.copy()
            discardDomain.discard(value)
            if len(discardDomain) == 0: return False

    return True