def test_apply_move_resets_bot_was_killed(bot_to_move, bot_was_killed_flags): """ Check that `prepare_bot_state` sees the proper bot_was_killed flag and that `apply_move` will reset the flag to False. """ team_id = bot_to_move % 2 other_bot = (bot_to_move + 2) % 4 other_team_id = 1 - team_id # specify which bot should move test_state = setup_random_basic_gamestate(turn=bot_to_move) bot_was_killed_flags = list(bot_was_killed_flags) # needs to be a list test_state[ 'bot_was_killed'] = bot_was_killed_flags[:] # copy to avoid reference issues # create bot state for current turn current_bot_position = test_state['bots'][bot_to_move] bot_state = game.prepare_bot_state(test_state) # bot state should have proper bot_was_killed flag assert bot_state['team']['bot_was_killed'] == bot_was_killed_flags[ team_id::2] # apply a dummy move that should reset bot_was_killed for the current bot new_test_state = game.apply_move(test_state, current_bot_position) # the bot_was_killed flag should be False again assert test_state['bot_was_killed'][bot_to_move] == False # the bot_was_killed flags for other bot should still be as before assert test_state['bot_was_killed'][other_bot] == bot_was_killed_flags[ other_bot] # all bot_was_killed flags for other team should still be as before assert test_state['bot_was_killed'][ other_team_id::2] == bot_was_killed_flags[other_team_id::2]
def test_noiser_not_noising_at_noise_radius0(): """ It is the any team's turn, and the noiser should not do anything, because noise radius is 0 """ test_collect = [] for tt in range(4): gamestate = make_gamestate() old_bots = gamestate["bots"] gamestate["turn"] = tt gamestate["noise_radius"] = 0 new_gamestate = prepare_bot_state(gamestate) new_team_bots = new_gamestate['team']['bot_positions'] new_enemy_bots = new_gamestate['enemy']['bot_positions'] if tt % 2 == 0: # team 0 assert old_bots[0] == new_team_bots[0] assert old_bots[1] == new_enemy_bots[0] assert old_bots[2] == new_team_bots[1] assert old_bots[3] == new_enemy_bots[1] else: # team 1 assert old_bots[0] == new_enemy_bots[0] assert old_bots[1] == new_team_bots[0] assert old_bots[2] == new_enemy_bots[1] assert old_bots[3] == new_team_bots[1]
def test_noiser_not_noising_own_team_even2(): """ It is the even team's turn, and the noiser should not work on own bots """ gamestate = make_gamestate() gamestate["turn"] = 2 old_bots = gamestate["bots"] new_gamestate = prepare_bot_state(gamestate) new_bots = new_gamestate['team']['bot_positions'] test_bot0 = old_bots[0] == new_bots[0] test_bot2 = old_bots[2] == new_bots[1] assert test_bot0 or test_bot2
def test_noiser_not_noising_own_team_odd3(): """ It is the odd team's turn, and the noiser should not work on own bots """ gamestate = make_gamestate() gamestate["turn"] = 3 old_bots = gamestate["bots"] new_gamestate = prepare_bot_state(gamestate) new_bots = new_gamestate['team']['bot_positions'] test_bot1 = old_bots[1] == new_bots[0] test_bot3 = old_bots[3] == new_bots[1] assert test_bot1 or test_bot3
def test_noiser_noising_even_turn2(): """ It is the even team's turn, and the noiser should work on odd bots """ test_collect_bot1 = [] test_collect_bot3 = [] for ii in range(10): # we let it run 10 times because it could return the original position, # but in most cases it should return a different pos (due to noise) gamestate = make_gamestate() gamestate["turn"] = 2 old_bots = gamestate["bots"] new_gamestate = prepare_bot_state(gamestate) new_bots = new_gamestate['enemy']['bot_positions'] test_collect_bot1.append((not old_bots[1] == new_bots[0])) test_collect_bot3.append((not old_bots[3] == new_bots[1])) assert any(test_collect_bot1) or any(test_collect_bot3)