예제 #1
0
def test_uniform_noise_4_bots_no_noise_manhattan():
    test_layout = (""" ##################
        # #.  .  # . 2   #
        # #####    #####3#
        #  0  . #  .  .#1#
        ################## """)
    parsed = parse_layout(test_layout)

    expected_0 = [(1, 1), (3, 1), (4, 1), (5, 1), (6, 1), (1, 2), (1, 3),
                  (2, 3), (3, 3), (4, 3), (5, 3), (6, 3), (7, 3), (7, 2)]
    position_bucket_0 = collections.defaultdict(int)

    expected_2 = [(13, 1)]
    position_bucket_2 = {(13, 1): 0}

    for i in range(200):
        noised = gf.noiser(walls=parsed['walls'],
                           bot_position=parsed['bots'][1],
                           enemy_positions=parsed['bots'][0::2])

        assert noised['is_noisy'] == [True, False]
        position_bucket_0[noised['enemy_positions'][0]] += 1
        position_bucket_2[noised['enemy_positions'][1]] += 1
    assert 200 == sum(position_bucket_0.values())
    assert 200 == sum(position_bucket_2.values())
    # Since this is a randomized algorithm we need to be a bit lenient with
    # our tests. We check that each position was selected at least once.
    assert set(position_bucket_0.keys()) == set(expected_0)
    assert set(position_bucket_2.keys()) == set(expected_2)
예제 #2
0
def test_uniform_noise_manhattan(noise_radius, expected, test_layout=None):
    # Test how bot 1 observes bot 0
    if not test_layout:
        test_layout = (""" ##################
            # #.  .  # .     #
            # #####    ##### #
            #  0  . #  .  .#1#
            ################## """)
    parsed = parse_layout(test_layout)

    position_bucket = collections.defaultdict(int)
    for i in range(200):
        noised = gf.noiser(walls=parsed['walls'],
                           bot_position=parsed['bots'][1],
                           enemy_positions=[parsed['bots'][0]],
                           noise_radius=noise_radius)
        if noise_radius == 0:
            assert noised['is_noisy'] == [False]
        else:
            assert noised['is_noisy'] == [True]

        noised_pos = noised['enemy_positions'][0]
        position_bucket[noised_pos] += 1
    assert 200 == sum(position_bucket.values())
    # Since this is a randomized algorithm we need to be a bit lenient with
    # our tests. We check that each position was selected at least once.
    assert set(position_bucket.keys()) == set(expected)
예제 #3
0
def test_noiser_noising_at_noise_radius_extreme(ii):
    """ It is the any team's turn, and the noiser should
    still noise within confines of maze, despite extreme radius """

    gamestate = make_gamestate()
    gamestate["turn"] = random.randint(0, 3)
    team_id = gamestate["turn"] % 2
    old_bots = gamestate["bots"]
    team_bots = old_bots[team_id::2]
    enemy_bots = old_bots[1 - team_id::2]
    noised = gf.noiser(walls=gamestate["walls"],
                       shape=gamestate["shape"],
                       bot_position=gamestate["bots"][gamestate["turn"]],
                       enemy_positions=enemy_bots,
                       noise_radius=50,
                       sight_distance=5,
                       rnd=None)

    assert all(noised["is_noisy"])

    for noised_pos in noised["enemy_positions"]:
        # check that the noised position is legal
        assert noised_pos not in gamestate["walls"]
        assert 0 <= noised_pos[0] < max(gamestate["walls"])[0]
        assert 0 <= noised_pos[1] < max(gamestate["walls"])[1]
예제 #4
0
def test_noiser_no_negative_coordinates(bot_id):

    gamestate = make_gamestate()
    old_bots = gamestate["bots"][:]
    walls = gamestate['walls']
    bot_position = gamestate['bots'][bot_id]
    enemy_group = 1 - (bot_id // 2)
    enemy_positions = gamestate['bots'][enemy_group::2]
    noised = gf.noiser(walls,
                       bot_position=bot_position,
                       enemy_positions=enemy_positions,
                       noise_radius=5,
                       sight_distance=5,
                       rnd=None)
    new_bots = noised["enemy_positions"]
    print(noised)
    test_1 = all(item[0] > 0 for item in new_bots)
    test_2 = all(item[1] > 0 for item in new_bots)

    assert test_1 and test_2
예제 #5
0
def test_noise_manhattan_failure():
    test_layout = (""" ##################
        ########## . 2   #
        ########## #####3#
        ###0###### .  . 1#
        ################## """)
    # we test what bot 1 sees
    # bot 0 should not be noised
    # bot 2 should not be noised
    parsed = parse_layout(test_layout)
    expected = parsed['food'] + [parsed['bots'][0]]

    position_bucket = collections.defaultdict(int)
    # check a few times
    for i in range(5):
        noised = gf.noiser(walls=parsed['walls'],
                           bot_position=parsed['bots'][1],
                           enemy_positions=parsed['bots'][0::2])

        assert noised['is_noisy'] == [False, False]
        noised_pos = noised['enemy_positions']
        assert noised_pos == parsed['bots'][0::2]
예제 #6
0
def test_uniform_noise_manhattan_graphical_distance(test_layout, is_noisy):
    # Test how bot 1 observes bot 0
    # the expected locations are where the food is placed
    parsed = parse_layout(test_layout)
    expected = parsed['food'] + [parsed['bots'][0]]

    position_bucket = collections.defaultdict(int)
    NUM_TESTS = 400
    for i in range(NUM_TESTS):
        noised = gf.noiser(walls=parsed['walls'],
                           bot_position=parsed['bots'][1],
                           enemy_positions=[parsed['bots'][0]])
        # use default values for radius and distance
        # noise_radius=5, sight_distance=5
        assert noised['is_noisy'] == [is_noisy]

        noised_pos = noised['enemy_positions'][0]
        position_bucket[noised_pos] += 1
    assert NUM_TESTS == sum(position_bucket.values())
    # Since this is a randomized algorithm we need to be a bit lenient with
    # our tests. We check that each position was selected at least once.
    assert set(position_bucket.keys()) == set(expected)