#!/usr/bin/env python
# coding: utf-8

import time
import random


from aimodel.AIModel import AIModel

# 一局内最大运行时间
MAX_PLAYING_TIME = 60


class XXXAI(AIModel):
    # 构造函数
    def __init__(self):
        AIModel.__init__(self)
        self.__state = None
        self.__agentEnv = None
        self.__time = -1

    # 初始化函数，参数agentEnv为 Env插件类实例对象
    def Init(self, agentEnv):
        self.__agentEnv = agentEnv
        return True

    # 退出函数
    def Finish(self):
        pass

    # 检测到每一局游戏开始后，AI算法进行的操作可以在此处实现，如一些变量的重置等
    def OnEpisodeStart(self):
        self.__time = time.time()
        self.logger.debug("EpisodeStart time {}".format(self.__time))

    # 检测到每一局游戏结束后，AI算法进行的操作可以在此处实现
    def OnEpisodeOver(self):
        pass

    # 当加载进入游戏场景时，需要进行的操作可以在此处实现
    def OnEnterEpisode(self):
        pass

    # 当离开退出游戏场景时，需要进行的操作可以在此处实现
    def OnLeaveEpisode(self):
        pass

    # 训练AI操作的每一个step实现,通常强化学习算法需要实现此接口,基于规则的AI无需训练,不需要实现此接口
    def TrainOneStep(self):
        pass

    # AI测试的每一个step实现，通常实现为agentEnv获取游戏状态数据，然后根据AI算法输出对应的游戏操作
    def TestOneStep(self):
        self.__state = self.__agentEnv.GetState()
        image = self.__state['image']

        self.logger.debug('scene is {}'.format(self.__state['scene']))
        curTime = time.time()
        if curTime - self.__time > MAX_PLAYING_TIME:
            action = dict()
            action['type'] = 'exit'
            self.__agentEnv.DoAction(action)
            self.logger.info("do exit")
            self.__time = curTime
        else:
            action = dict()
            action['type'] = 'run'
            self.__agentEnv.DoAction(action)
            self.logger.info("do run")
        return True

ab890cbeb844f43794b5b5c8e1d5088cb9d30ce7
<mask token>


class XXXAI(AIModel):

    def __init__(self):
        AIModel.__init__(self)
        self.__state = None
        self.__agentEnv = None
        self.__time = -1

    def Init(self, agentEnv):
        self.__agentEnv = agentEnv
        return True

    def Finish(self):
        pass
    <mask token>
    <mask token>

    def OnEnterEpisode(self):
        pass

    def OnLeaveEpisode(self):
        pass

    def TrainOneStep(self):
        pass
    <mask token>

<mask token>


class XXXAI(AIModel):

    def __init__(self):
        AIModel.__init__(self)
        self.__state = None
        self.__agentEnv = None
        self.__time = -1

    def Init(self, agentEnv):
        self.__agentEnv = agentEnv
        return True

    def Finish(self):
        pass
    <mask token>

    def OnEpisodeOver(self):
        pass

    def OnEnterEpisode(self):
        pass

    def OnLeaveEpisode(self):
        pass

    def TrainOneStep(self):
        pass
    <mask token>

<mask token>


class XXXAI(AIModel):

    def __init__(self):
        AIModel.__init__(self)
        self.__state = None
        self.__agentEnv = None
        self.__time = -1

    def Init(self, agentEnv):
        self.__agentEnv = agentEnv
        return True

    def Finish(self):
        pass

    def OnEpisodeStart(self):
        self.__time = time.time()
        self.logger.debug('EpisodeStart time {}'.format(self.__time))

    def OnEpisodeOver(self):
        pass

    def OnEnterEpisode(self):
        pass

    def OnLeaveEpisode(self):
        pass

    def TrainOneStep(self):
        pass
    <mask token>

import time
import random
from aimodel.AIModel import AIModel
MAX_PLAYING_TIME = 60


class XXXAI(AIModel):

    def __init__(self):
        AIModel.__init__(self)
        self.__state = None
        self.__agentEnv = None
        self.__time = -1

    def Init(self, agentEnv):
        self.__agentEnv = agentEnv
        return True

    def Finish(self):
        pass

    def OnEpisodeStart(self):
        self.__time = time.time()
        self.logger.debug('EpisodeStart time {}'.format(self.__time))

    def OnEpisodeOver(self):
        pass

    def OnEnterEpisode(self):
        pass

    def OnLeaveEpisode(self):
        pass

    def TrainOneStep(self):
        pass

    def TestOneStep(self):
        self.__state = self.__agentEnv.GetState()
        image = self.__state['image']
        self.logger.debug('scene is {}'.format(self.__state['scene']))
        curTime = time.time()
        if curTime - self.__time > MAX_PLAYING_TIME:
            action = dict()
            action['type'] = 'exit'
            self.__agentEnv.DoAction(action)
            self.logger.info('do exit')
            self.__time = curTime
        else:
            action = dict()
            action['type'] = 'run'
            self.__agentEnv.DoAction(action)
            self.logger.info('do run')
        return True

#!/usr/bin/env python
# coding: utf-8

import time
import random


from aimodel.AIModel import AIModel

# 一局内最大运行时间
MAX_PLAYING_TIME = 60


class XXXAI(AIModel):
    # 构造函数
    def __init__(self):
        AIModel.__init__(self)
        self.__state = None
        self.__agentEnv = None
        self.__time = -1

    # 初始化函数，参数agentEnv为 Env插件类实例对象
    def Init(self, agentEnv):
        self.__agentEnv = agentEnv
        return True

    # 退出函数
    def Finish(self):
        pass

    # 检测到每一局游戏开始后，AI算法进行的操作可以在此处实现，如一些变量的重置等
    def OnEpisodeStart(self):
        self.__time = time.time()
        self.logger.debug("EpisodeStart time {}".format(self.__time))

    # 检测到每一局游戏结束后，AI算法进行的操作可以在此处实现
    def OnEpisodeOver(self):
        pass

    # 当加载进入游戏场景时，需要进行的操作可以在此处实现
    def OnEnterEpisode(self):
        pass

    # 当离开退出游戏场景时，需要进行的操作可以在此处实现
    def OnLeaveEpisode(self):
        pass

    # 训练AI操作的每一个step实现,通常强化学习算法需要实现此接口,基于规则的AI无需训练,不需要实现此接口
    def TrainOneStep(self):
        pass

    # AI测试的每一个step实现，通常实现为agentEnv获取游戏状态数据，然后根据AI算法输出对应的游戏操作
    def TestOneStep(self):
        self.__state = self.__agentEnv.GetState()
        image = self.__state['image']

        self.logger.debug('scene is {}'.format(self.__state['scene']))
        curTime = time.time()
        if curTime - self.__time > MAX_PLAYING_TIME:
            action = dict()
            action['type'] = 'exit'
            self.__agentEnv.DoAction(action)
            self.logger.info("do exit")
            self.__time = curTime
        else:
            action = dict()
            action['type'] = 'run'
            self.__agentEnv.DoAction(action)
            self.logger.info("do run")
        return True
