Esempio n. 1
0
def test4 () :
    game = sudoku.Game(sys.argv[1])
    before = game.display()
    while game.iterate() : pass
    after = game.display()
    print "\n        Before                    After"
    print sideBySide([before,after])
    if game.valid() and not game.finished() :
        print "This partial yet valid game splits into"
        kids = game.split()
        print sideBySide([after]+map(lambda x: x.display(), kids))
    if not game.valid() :
        print "This game is not valid and cannot be completed"
Esempio n. 2
0
def test4():
    game = sudoku.Game(sys.argv[1])
    before = game.display()
    while game.iterate():
        pass
    after = game.display()
    print "\n        Before                    After"
    print sideBySide([before, after])
    if game.valid() and not game.finished():
        print "This partial yet valid game splits into"
        kids = game.split()
        print sideBySide([after] + map(lambda x: x.display(), kids))
    if not game.valid():
        print "This game is not valid and cannot be completed"
Esempio n. 3
0
def test1 () :
    "Set up a dual set and show effects"
    game = Game(sys.argv[1])
    before = game.display()
    tagged = game.getTagged()
    tags = tagged.keys(); tags.sort()
    for tag in tags :
        cell = tagged[tag]
        for other in game.cells :
            if other.inx in cell.sameRow : other.val="r"
            if other.inx in cell.sameCol : other.val="c"
            if other.inx in cell.sameBox : other.val="b"

    after = game.display()
    print sideBySide([before,after])
Esempio n. 4
0
def test2 () :
    "Set up a dual set and show effects"
    game = Game(sys.argv[1])
    tagged = game.getTagged()
    tags=tagged.keys(); tags.sort()
    before = game.display()
    for tag in tags :
        cell = tagged[tag]
        print " ", tag, cell, cell.pvals
        cell.update_pvals(game.cells)
        print " ", tag, cell, cell.pvals

    after = game.display()
    print "\n        Before                    After"
    print sideBySide([before,after])
Esempio n. 5
0
def test1():
    "Set up a dual set and show effects"
    game = Game(sys.argv[1])
    before = game.display()
    tagged = game.getTagged()
    tags = tagged.keys()
    tags.sort()
    for tag in tags:
        cell = tagged[tag]
        for other in game.cells:
            if other.inx in cell.sameRow: other.val = "r"
            if other.inx in cell.sameCol: other.val = "c"
            if other.inx in cell.sameBox: other.val = "b"

    after = game.display()
    print sideBySide([before, after])
Esempio n. 6
0
def test3 () :
    game = sudoku.Game(sys.argv[1])
    before = game.display()
    for iter in range(10) :
        changed = error = False
        for cell in game.cells[:] :
            earlier = cell.pvals.copy()
            if not cell.update_pvals(game.cells) :
                print cell, cell.error
                error = True
                break
            if cell.pvals != earlier :
                changed = True
        if not changed : break
        after = game.display()
        print "  Iteration", iter+1
        print "\n        Before                    After"
        print sideBySide([before,after])
        before = after
        if error : break
Esempio n. 7
0
def explore (game) :
    before = game.display()
    while game.iterate() : pass
    after = game.display()
    if not game.valid() :
        print "\n        Before                    After   (Invalid)"
        print sideBySide([before,after])
        bad = [cell for cell in game.cells if cell.error > ""]
        print bad[0], bad[0].error
        return
    elif game.finished() :
        print "\n        Before                    After   (Finished)"
        print sideBySide([before,after])
        return
    else : 
        message = "Partial game splits"
        kids = game.split()
        displays = [kid.display() for kid in kids]
        print "\n        Before                    After   (Splits into .... )"
        print sideBySide([after]+displays)
        for kid in kids :
            explore(kid)
Esempio n. 8
0
def explore(game):
    before = game.display()
    while game.iterate():
        pass
    after = game.display()
    if not game.valid():
        print "\n        Before                    After   (Invalid)"
        print sideBySide([before, after])
        bad = [cell for cell in game.cells if cell.error > ""]
        print bad[0], bad[0].error
        return
    elif game.finished():
        print "\n        Before                    After   (Finished)"
        print sideBySide([before, after])
        return
    else:
        message = "Partial game splits"
        kids = game.split()
        displays = [kid.display() for kid in kids]
        print "\n        Before                    After   (Splits into .... )"
        print sideBySide([after] + displays)
        for kid in kids:
            explore(kid)