示例#1
0
def subtest_search_point_next_sq(board, gen_pattern, color, own_sqs, defcon,
                                 start, end):
    for own_sq in own_sqs:
        test_sq = point_on_line(start, end, own_sq)
        expected_ns_matches = [(test_sq, (start, end))]

        for x in range(SIDE_LEN):
            for y in range(SIDE_LEN):
                point = (x, y)

                stored_val = board[test_sq]
                board[test_sq] = EMPTY
                ns_matches = search_point_next_sq(board, gen_pattern, color,
                                                  point)
                board[test_sq] = stored_val

                # We can only assert that naively expected matches are a subset of actual,
                # if the point lies on the segment of the pattern.
                if point_is_on_line(point, start, end, True):
                    assert_nb(
                        next_sq_matches_are_subset(expected_ns_matches,
                                                   ns_matches))
                elif point_is_on_line(point, start, end, False):
                    pass
                else:
                    # Doesn't apply to patterns having 2 or less OWN squares.
                    if WIN_LENGTH - defcon > 2:
                        assert_nb(len(ns_matches) == 0)

                # All matches must lie on the same line as the pattern.
                # Doesn't apply to patterns having 2 or less OWN squares.
                if WIN_LENGTH - defcon > 2:
                    for nsm in ns_matches:
                        assert_nb(point_is_on_line(nsm[0], start, end, False))
示例#2
0
def subtest_search_point(board, gen_pattern, color, start, end):
    expected_matches = [(start, end)]
    for x in range(SIDE_LEN):
        for y in range(SIDE_LEN):
            point = (x, y)
            matches = search_point(board, gen_pattern, color, point)

            if point_is_on_line(point, start, end, True):
                assert_nb(matches_are_equal(matches, expected_matches))
            else:
                assert_nb(len(matches) == 0)
示例#3
0
def subtest_search_board_next_sq(board, gen_pattern, color, own_sqs, defcon,
                                 start, end):
    for own_sq in own_sqs:
        test_sq = point_on_line(start, end, own_sq)
        expected_ns_matches = [(test_sq, (start, end))]

        stored_val = board[test_sq]
        board[test_sq] = EMPTY
        ns_matches = search_board_next_sq(board, gen_pattern, color)
        board[test_sq] = stored_val

        # We can only assert that naively expected matches are a subset of actual.
        assert_nb(next_sq_matches_are_subset(expected_ns_matches, ns_matches))

        # All matches must lie on the same line as the pattern.
        # Doesn't apply to patterns having 2 or less OWN squares.
        if WIN_LENGTH - defcon > 2:
            for nsm in ns_matches:
                assert_nb(point_is_on_line(nsm[0], start, end, False))