def test_expire_venus_flowers_when_there_are_no_healthy_flowers(): game = GameState(game_params=DEFAULT_GAME_PARAMETERS, game_id=sentinel.game_id, boards=1, board_width=10, board_height=10, hives=[sentinel.hives], flowers=[[ VenusBeeTrap(sentinel.x1, sentinel.y1, DEFAULT_GAME_PARAMETERS, sentinel.potency, sentinel.visits, expires=100), VenusBeeTrap(sentinel.x2, sentinel.y2, DEFAULT_GAME_PARAMETERS, sentinel.potency, sentinel.visits, expires=200) ]], turn_num=100, game_length=sentinel.game_length) game.remove_dead_flowers() assert game.boards[0].flowers == (VenusBeeTrap(sentinel.x2, sentinel.y2, DEFAULT_GAME_PARAMETERS, sentinel.potency, sentinel.visits, expires=200), )
def test_only_expired_flowers_removed_from_mixed_bunch(): game = GameState(game_params=DEFAULT_GAME_PARAMETERS, game_id=sentinel.game_id, boards=1, board_width=10, board_height=10, hives=[sentinel.hives], flowers=[[ Flower(sentinel.x1, sentinel.y1, DEFAULT_GAME_PARAMETERS, sentinel.potency1, sentinel.visits1, expires=10), Flower(sentinel.x2, sentinel.y2, DEFAULT_GAME_PARAMETERS, sentinel.potency2, sentinel.visits2, expires=50), Flower(sentinel.x3, sentinel.y3, DEFAULT_GAME_PARAMETERS, sentinel.potency3, sentinel.visits3, expires=100), VenusBeeTrap(sentinel.x3, sentinel.y3, DEFAULT_GAME_PARAMETERS, sentinel.potency3, sentinel.visits3, expires=50), VenusBeeTrap(sentinel.x3, sentinel.y3, DEFAULT_GAME_PARAMETERS, sentinel.potency3, sentinel.visits3, expires=100), ]], turn_num=75, game_length=sentinel.game_length) game.remove_dead_flowers() assert game.boards[0].flowers == ( Flower(sentinel.x3, sentinel.y3, DEFAULT_GAME_PARAMETERS, sentinel.potency3, sentinel.visits3, expires=100), VenusBeeTrap(sentinel.x3, sentinel.y3, DEFAULT_GAME_PARAMETERS, sentinel.potency3, sentinel.visits3, expires=100), )
def test_trapseed_becomes_venus_after_10_moves_on_top_of_a_hive(): turn_num = 12345 game = GameState(game_params=DEFAULT_GAME_PARAMETERS, game_id=sentinel.game_id, boards=1, board_width=10, board_height=10, hives=(( Hive(9, 5), Hive(5, 5), ), ), flowers=((), ), turn_num=turn_num, game_length=sentinel.game_length) game.boards[0].inflight[sentinel.seed_1] = TrapSeed( 9, 8, 0, mock_game_params.trap_seed_lifespan) for _ in range(DEFAULT_GAME_PARAMETERS.trap_seed_lifespan + 1): game.turn([None]) assert not [(_, volant) for (_, volant) in game.boards[0].inflight.items() if isinstance(volant, TrapSeed)] assert game.boards[0].flowers == ((VenusBeeTrap( 9, 5, DEFAULT_GAME_PARAMETERS, expires=turn_num + DEFAULT_GAME_PARAMETERS.trap_seed_lifespan + DEFAULT_GAME_PARAMETERS.flower_lifespan)), ) assert game.boards[0].hives == (Hive(5, 5), )
def test_keep_one_healthy_flower_if_all_expired(): healthy_flower = Flower(sentinel.x, sentinel.y, DEFAULT_GAME_PARAMETERS, sentinel.potency, sentinel.visits, expires=99) venus = VenusBeeTrap(sentinel.x, sentinel.y, DEFAULT_GAME_PARAMETERS, sentinel.potency, sentinel.visits, expires=99) flowers = [healthy_flower, venus] game = GameState(game_params=DEFAULT_GAME_PARAMETERS, game_id=sentinel.game_id, boards=1, board_width=10, board_height=10, hives=[sentinel.hives], flowers=[flowers], turn_num=100, game_length=sentinel.game_length) game.remove_dead_flowers() assert len(game.boards[0].flowers) == 1 assert game.boards[0].flowers[0] == healthy_flower
def test_apply_venus_command_over_existing_flower(): game = GameState(game_params=DEFAULT_GAME_PARAMETERS, game_id=sentinel.game_id, boards=1, board_width=10, board_height=10, hives=((Hive(9, 9), ), ), flowers=((Flower(0, 0, DEFAULT_GAME_PARAMETERS, sentinel.potency, sentinel.visits), Flower(9, 9, DEFAULT_GAME_PARAMETERS, sentinel.potency, sentinel.visits)), ), turn_num=12345, game_length=sentinel.game_length) game.boards[0].inflight[sentinel.seed_1] = TrapSeed( 0, 0, 0, DEFAULT_GAME_PARAMETERS.trap_seed_lifespan) game.apply_commands([dict(entity=sentinel.seed_1, command="flower")]) assert game.boards[0].inflight == {} assert sorted(map(str, game.boards[0].flowers)) == sorted( map(str, (VenusBeeTrap( 0, 0, DEFAULT_GAME_PARAMETERS, 1, 0, expires=12345 + DEFAULT_GAME_PARAMETERS.flower_lifespan), Flower(9, 9, DEFAULT_GAME_PARAMETERS, sentinel.potency, sentinel.visits)))) assert game.boards[0].hives == (Hive(9, 9), )
def test_venus_remain_if_unexpired(): game = GameState(game_params=DEFAULT_GAME_PARAMETERS, game_id=sentinel.game_id, boards=1, board_width=10, board_height=10, hives=[sentinel.hives], flowers=[[ Flower(sentinel.x, sentinel.y, DEFAULT_GAME_PARAMETERS, sentinel.potency, sentinel.visits, expires=100), VenusBeeTrap(sentinel.x, sentinel.y, DEFAULT_GAME_PARAMETERS, sentinel.potency, sentinel.visits, expires=100) ]], turn_num=0, game_length=sentinel.game_length) game.remove_dead_flowers() assert game.boards[0].flowers == ( Flower(sentinel.x, sentinel.y, DEFAULT_GAME_PARAMETERS, sentinel.potency, sentinel.visits, expires=100), VenusBeeTrap(sentinel.x, sentinel.y, DEFAULT_GAME_PARAMETERS, sentinel.potency, sentinel.visits, expires=100), )
def test_flowers_and_venus_removed_if_expired(): flowers = [ Flower(sentinel.x, sentinel.y, DEFAULT_GAME_PARAMETERS, sentinel.potency, sentinel.visits, expires=99), Flower(sentinel.x, sentinel.y, DEFAULT_GAME_PARAMETERS, sentinel.potency, sentinel.visits, expires=102), VenusBeeTrap(sentinel.x, sentinel.y, DEFAULT_GAME_PARAMETERS, sentinel.potency, sentinel.visits, expires=99), VenusBeeTrap(sentinel.x, sentinel.y, DEFAULT_GAME_PARAMETERS, sentinel.potency, sentinel.visits, expires=102) ] game = GameState(game_params=DEFAULT_GAME_PARAMETERS, game_id=sentinel.game_id, boards=1, board_width=10, board_height=10, hives=[sentinel.hives], flowers=[flowers], turn_num=100, game_length=sentinel.game_length) game.remove_dead_flowers() assert game.boards[0].flowers == (flowers[1], flowers[3])
def test_apply_venus_command_empty_tile(): game = GameState(game_params=DEFAULT_GAME_PARAMETERS, game_id=sentinel.game_id, boards=1, board_width=10, board_height=10, hives=((Hive(9, 9), ), ), flowers=((Flower(0, 0, DEFAULT_GAME_PARAMETERS), ), ), turn_num=12345, game_length=sentinel.game_length) game.boards[0].inflight[sentinel.seed_1] = TrapSeed( 4, 5, 0, DEFAULT_GAME_PARAMETERS.trap_seed_lifespan) game.apply_commands([dict(entity=sentinel.seed_1, command="flower")]) assert game.boards[0].inflight == {} assert game.boards[0].flowers == (Flower(0, 0, DEFAULT_GAME_PARAMETERS), VenusBeeTrap(4, 5, DEFAULT_GAME_PARAMETERS, expires=12645)) assert game.boards[0].hives == (Hive(9, 9), )
def test_repr_venus_bee_trap(): assert (repr(VenusBeeTrap(1337, 2000, DEFAULT_GAME_PARAMETERS, 54321, 1234, 3000)) == "VenusBeeTrap(1337, 2000, %s, 54321, 1234, 3000)" % DEFAULT_GAME_PARAMETERS._asdict())
def test_detect_crashes(bee_types, crash_board, noncrash_board, crashing_volant_specs, noncrash_volant_specs): game = GameState(game_params=DEFAULT_GAME_PARAMETERS, game_id=sentinel.game_id, boards=2, board_width=sentinel.board_width, board_height=sentinel.board_height, hives=[[Hive(0, 0, 0)]] * 2, flowers=[[VenusBeeTrap(9, 9, DEFAULT_GAME_PARAMETERS)]] * 2, game_length=sentinel.game_length) def apply_bee_type_to_specs(bees_specs): """ Create bee instances from the specs in the test cases which are tuples if not, return the spec as is (will probably be a seed)""" def create_bee_or_seed(id, spec): if type(spec) is tuple: x, y, h, e, n = spec return bee_types[id % 10](x, y, h, e, DEFAULT_GAME_PARAMETERS, n) else: return spec return { bee_id: create_bee_or_seed(bee_id, bee) for bee_id, bee in bees_specs.items() } crashing_volants = { crash_type: apply_bee_type_to_specs(volants) for crash_type, volants in crashing_volant_specs.items() } noncrash_volants = apply_bee_type_to_specs(noncrash_volant_specs) crashing_volants_summary = { volant_id: volant for volants in crashing_volants.values() for volant_id, volant in volants.items() } crashing_bees_summary = { bee_id: bee for bee_id, bee in crashing_volants_summary.items() if isinstance(bee, Bee) } crashing_volants.setdefault("collided", {}) crashing_volants.setdefault("exhausted", {}) crashing_volants.setdefault("headon", {}) crashing_volants.setdefault("gobbled", {}) crashing_volants.setdefault("seeds", {}) for board, volants in ((crash_board, crashing_volants_summary), (noncrash_board, noncrash_volants)): for bee_id, bee_details in volants.items(): game.boards[board].inflight[bee_id] = bee_details assert all( board.calculate_score() == DEFAULT_GAME_PARAMETERS.hive_score_factor + DEFAULT_GAME_PARAMETERS.venus_score_factor for board in game.boards) crashes = game.detect_crashes() assert all( board.calculate_score() == DEFAULT_GAME_PARAMETERS.hive_score_factor + DEFAULT_GAME_PARAMETERS.venus_score_factor for i, board in enumerate(game.boards) if i != crash_board) assert (game.boards[crash_board].calculate_score() == DEFAULT_GAME_PARAMETERS.hive_score_factor + DEFAULT_GAME_PARAMETERS.venus_score_factor + DEFAULT_GAME_PARAMETERS.dead_bee_score_factor * len(crashing_bees_summary)) for board, crashed_bees in enumerate(crashes): if board == crash_board: assert crashed_bees == crashing_volants else: assert crashed_bees == dict(collided={}, headon={}, exhausted={}, gobbled={}, seeds={})