# Path: src/dp_screenshot.py
# def take_screenshot():
# 
# Path: src/helper.py
# def validate_function_key(slot_key):
# def get_output_folder():
# def get_models_folder():
# def get_dataset_folder():
# def get_home_folder():
# def pickle_object(data, name, directory=get_output_folder()):
# def generate_img_key(image):
# def get_tensor(image):
# def get_output_vector(presses):
# def get_key_state_from_vector(vector):
# 
# Path: src/mk_downsampler.py
# class Downsampler:
#     def __init__(self, game_name, blur_size=25, intermediate_dim=300, final_dim=10):
#     def downsample_dir(self, save_imgs=False, clean_data=False):
#     def downsample(self, file_path, output_name=None, save_img=False, clean_data=False):
#     def save_image(self, img, output_name):
# 
# Path: src/key2pad.py
# class KeyPadMap:
#     def __init__(self):
#     def update(self, keys):
#     def convert_key(self, key, is_press):


import collections
import logging
import os
import time
import torch
from src import dp_screenshot, helper, mk_downsampler, key2pad
logger = logging.getLogger(__name__)


class MarioKartNN:
    """ Class implementing a neural network Mario Kart AI agent """
    game_name = "NABE01"

    def __init__(self, pickled_model_path, history_length=1, delay=0.2):
        """ Create a MarioKart Agent instance.
        Args:
            pickled_model_path: Path to the neural network model file.
        """
        self.model = torch.load(pickled_model_path)

        self.frame_delay = delay
        self.screenshot_dir = os.path.join(helper.get_home_folder(), '.dolphin-emu', 'ScreenShots', self.game_name)
        self.key_map = key2pad.KeyPadMap()
        self.history_length = history_length
        self.previous_tensors = collections.deque([], history_length)

    def process_frame(self):
        """ Process a single frame of the current Dolphin game.
        Note:
            Process means read the state of the game and decide what action to take in this context.
            Dolphin will not take screenshots if the game is paused!
        """
        # Advance the Dolphin frame
        # dp_frames.advance('P')

        # Take screenshot of current Dolphin frame

# Path: src/dp_screenshot.py
# def take_screenshot():
# 
# Path: src/helper.py
# def validate_function_key(slot_key):
# def get_output_folder():
# def get_models_folder():
# def get_dataset_folder():
# def get_home_folder():
# def pickle_object(data, name, directory=get_output_folder()):
# def generate_img_key(image):
# def get_tensor(image):
# def get_output_vector(presses):
# def get_key_state_from_vector(vector):
# 
# Path: src/mk_downsampler.py
# class Downsampler:
#     def __init__(self, game_name, blur_size=25, intermediate_dim=300, final_dim=10):
#     def downsample_dir(self, save_imgs=False, clean_data=False):
#     def downsample(self, file_path, output_name=None, save_img=False, clean_data=False):
#     def save_image(self, img, output_name):
# 
# Path: src/key2pad.py
# class KeyPadMap:
#     def __init__(self):
#     def update(self, keys):
#     def convert_key(self, key, is_press):


# Path: src/agents/mk_nn.py
import collections
import logging
import os
import time
import torch
from src import dp_screenshot, helper, mk_downsampler, key2pad

logger = logging.getLogger(__name__)


class MarioKartNN:
    """ Class implementing a neural network Mario Kart AI agent """
    game_name = "NABE01"

    def __init__(self, pickled_model_path, history_length=1, delay=0.2):
        """ Create a MarioKart Agent instance.
        Args:
            pickled_model_path: Path to the neural network model file.
        """
        self.model = torch.load(pickled_model_path)

        self.frame_delay = delay
        self.screenshot_dir = os.path.join(helper.get_home_folder(), '.dolphin-emu', 'ScreenShots', self.game_name)
        self.key_map = key2pad.KeyPadMap()
        self.history_length = history_length
        self.previous_tensors = collections.deque([], history_length)

    def process_frame(self):
        """ Process a single frame of the current Dolphin game.
        Note:
            Process means read the state of the game and decide what action to take in this context.
            Dolphin will not take screenshots if the game is paused!
        """
        # Advance the Dolphin frame
        # dp_frames.advance('P')

        # Take screenshot of current Dolphin frame

        dp_screenshot.take_screenshot()