# -*- coding:utf-8 -*-
# Author: Liaojiang

"""
海洋空战.scen
6v6+打船
红方bot
"""

import logging

from engine.LingYi.entitys.global_util import *
from engine.LingYi.entitys.agent_base import RuleAgentBase


class Agent(RuleAgentBase):
    def __init__(self, side_name, params):
        RuleAgentBase.__init__(self, side_name)
        logging.info('%s:%s play game' % (side_name, self.__class__.__name__))

    def initial(self, situation):
        """
        初始化函数，每局推演开始前被调用. 可用于任务创建、设置，条令设置，变量初始化等
        :param situation: tuple: units, contacts
        :return:
        """
        # 创建空战巡逻任务
        self.north_patrol = self.create_patrol_mission("北巡逻", MissionPatrolType.AIR,
                                                       [(52.2833, 135), (52.2833, 136.2042), (51.1444, 136.2042),(51.1444, 135)])
        self.south_patrol = self.create_patrol_mission("南巡逻", MissionPatrolType.AIR,
                                                  [(49.6247, 135), (50.6247, 136.2042), (50.4242, 136.2042),(49.4242, 135)])
        # 设置巡逻任务不执行三分之一规则
        self.north_patrol.set_one_third_rule(False)
        self.south_patrol.set_one_third_rule(False)

    def step(self, time_elapse, situation):
        """
        # 每步决策函数
        :param time_elapse:  int, time elapse
        :param situation: tuple: units-list, contacts-list
        :return:
        """
        """
        如果打掉对方船:
            闪电没有远程空空弹，返航, 否则加入空战巡逻任务
        如果大黄蜂没有远程空空弹后，不再巡逻，返航
        """
        pass

    def deduction_end(self):
        # agent结束后自动被调用函数， 可保存模型，比如记录本局策略后的得分等
        logging.info('%s:%s play game result:%d' % (self.Name, self.__class__.__name__, self.TotalScore))

    def is_done(self):
        # agent主动结束本局推演，比如一定胜利或失败后
        # 只能训练时调用此函数，比赛对战时此函数不可用
        if self.TotalScore >= 1500 or self.TotalScore <= -1500:
            return True
        return False

