def problem2_loop(inp, damage_dict, print_=False):
    grid = setup_inp(inp)
    rounds = 0
    while True:
        counts = count_characters(grid)
        seen = {}
        for (rowI, row) in enumerate(grid):
            for (colI, col) in enumerate(row):
                char = grid[rowI][colI]
                if isinstance(char, tuple):
                    if char[2]:
                        continue
                    (r, c) = (rowI, colI)
                    hero = char[0]
                    enemy = ('G' if (hero == 'E') else 'E')
                    counts[hero] -= 1
                    move_to = bfs_move(grid, rowI, colI, hero, enemy)
                    if move_to:
                        (r, c) = move_to
                        grid = move_character(grid, rowI, colI, r, c, char)
                    damage = damage_dict[hero]
                    (grid, death) = attack(grid, r, c, enemy, damage)
                    if (death and (enemy == 'E')):
                        return False
                    elif death:
                        current_counts = count_characters(grid)
                        game_over = any(((x == 0) for x in current_counts.values()))
                        if game_over:
                            if (counts[hero] > 0):
                                final_score = score_game(grid, rounds)
                            else:
                                rounds += 1
                                final_score = score_game(grid, rounds)
                            if print_:
                                print('GAME ENDED', rounds)
                                print_board(grid)
                            return final_score
        grid = reset_moved_bools(grid)
        rounds += 1
        if print_:
            print(rounds)
            print_board(grid)
def problem2_loop(inp, damage_dict, print_=False):
    grid = setup_inp(inp)
    rounds = 0
    while True:
        counts = count_characters(grid)
        seen = {}
        for (rowI, row) in enumerate(grid):
            for (colI, col) in enumerate(row):
                char = grid[rowI][colI]
                if isinstance(char, tuple):
                    if char[2]:
                        continue
                    (r, c) = (rowI, colI)
                    hero = char[0]
                    enemy = ('G' if (hero == 'E') else 'E')
                    counts[hero] -= 1
                    move_to = bfs_move(grid, rowI, colI, hero, enemy)
                    if move_to:
                        (r, c) = move_to
                        grid = move_character(grid, rowI, colI, r, c, char)
                    damage = damage_dict[hero]
                    (grid, death) = attack(grid, r, c, enemy, damage)
                    if (death and (enemy == 'E')):
                        return False
                    elif death:
                        current_counts = count_characters(grid)
                        game_over = any(((x == 0) for x in current_counts.values()))
                        if game_over:
                            if (counts[hero] > 0):
                                final_score = score_game(grid, rounds)
                            else:
                                rounds += 1
                                final_score = score_game(grid, rounds)
                            if print_:
                                print('GAME ENDED', rounds)
                                print_board(grid)
                            return final_score
        grid = reset_moved_bools(grid)
        rounds += 1
        if print_:
            print(rounds)
            print_board(grid)