示例#1
0
def test_find_impossible_moves_2():
    state = [((i, i), 0 if i % 2 == 0 else i) for i in range(9)]
    moves = find_impossible_moves(state)

    assert len(moves) == 5
    for i, m in enumerate(moves):
        assert m[0] == (2 * i, 2 * i)
        assert m[1] == [1, 3, 5, 7]
示例#2
0
def test_find_impossible_moves_1():
    # the first item, with value 0, is 'missing'. find_impossible_moves will tell us it cannot be [1,2,3,4,5,6,7,8].
    state = [((i, i), i) for i in range(9)]
    moves = find_impossible_moves(state)

    assert len(moves) == 1
    assert moves[0][0] == (0, 0)
    assert moves[0][1] == [1, 2, 3, 4, 5, 6, 7, 8]
示例#3
0
def test_find_impossible_moves_3():
    state = [((i, i), 0) for i in range(9)]
    moves = find_impossible_moves(state)

    assert len(moves) == 9
    for i, m in enumerate(moves):
        assert m[0] == (i, i)
        # there are no impossible moves in this case
        assert m[1] == []
示例#4
0
def test_resolve_game_2():
    board = numpy.loadtxt('games/008.txt')
    possible_moves = []
    impossible_moves = []
    for moveset in sets(board):
        possible_moves.append(find_possible_moves(moveset))
        impossible_moves.append(find_impossible_moves(moveset))

    resolved_moves = resolve_moves(possible_moves)
    assert len(resolved_moves) > 1
示例#5
0
def test_flatten_impossible_moves_1():
    board = numpy.loadtxt('games/008.txt')
    impossible_moves = []
    for moveset in sets(board):
        impossible_moves.append(find_impossible_moves(moveset))

    flat_moves = flatten_impossible_moves(impossible_moves)
    print(flat_moves)
    assert 39 == len(flat_moves)

    d = dict(flat_moves)
    # spot check some for validation
    assert d[(4, 0)] == set([2, 1, 4, 5, 7, 8, 9])
    assert d[(4, 3)] == set([1, 2, 4, 6, 9])
    assert d[(7, 2)] == set([1, 2, 4, 5, 6, 7, 8, 9])
示例#6
0
def play_single_gaps(board):
    """
    completes 9-value sets (rows, cols, boxes) with one missing value by putting the missing value into the empty space    
    returns (was_move_made, possible_moves) 
    was_move_made is True if a move was made
    possible moves is a list of potentially valid moves within each 9-item set
    impossible_moves is a list of invalid moves within each 9-item set

    both possible & impossible return empty is a move was made
    """
    possible_moves = []
    impossible_moves = []
    result = False
    for moveset in sets(board):
        moves = find_possible_moves(moveset)
        impossible_moves.append(find_impossible_moves(moveset))
        if moves is None or len(moves) == 0:
            continue
        elif len(moves) == 1:
            make_move(board, moves[0])
            return True, [], []
        else:
            possible_moves += [moves]
    return False, possible_moves, flatten_impossible_moves(impossible_moves)