Ejemplo n.º 1
0
    public void functionality()
    {
        AI_Action action = myAgent.currentActions.Peek();

        if (action.requiresInRange() && action.target == null)
        {
            Debug.Log("toPlan");

            toPlan();
        }
        else
        {
            //Debug.Log("Moving State");
            //myAgent.transform.position = action.target.transform.position - myAgent.transform.position * Time.deltaTime;
            Debug.Log("IN MOVE STATE");
            myAgent.transform.position = Vector3.Lerp(myAgent.transform.position, action.target.transform.position, .01f);
            distance = Vector3.Distance(myAgent.transform.position, action.target.transform.position);
            //Debug.Log(distance);
            //Debug.Log(distance);
            if (distance < 10)
            {
                //Debug.Log("Distance < 10");
                action.setInRange(true);
            }
            if (action.isInRange())
            {
                Debug.Log("MoveTo STATE:: -> PerformActionState");
                toDoAction();
            }
        }
    }
Ejemplo n.º 2
0
        void ChangeActionToPatrol()
        {
            if (path2.Count < 1)
            {
                return;
            }

            int endPosX = graphTools.RoundToTileCoord(player.transform.position.x, 0).x;
            int endPosY = graphTools.RoundToTileCoord(0, player.transform.position.y).y;
            int tx      = graphTools.RoundToTileCoord(transform.position.x, 0).x;
            int ty      = graphTools.RoundToTileCoord(0, transform.position.y).y;

            // Debug.Log(1);
            if (tileClass.myTile[endPosX, endPosY] == null)
            {
                return;
            }

            // Debug.Log(2);
            if (tileClass.myTile[tx, ty] == null)
            {
                return;
            }

            // Debug.Log(3);
            if (Vector2.Distance(tileClass.myTile[endPosX, endPosY].tileCoord, tileClass.myTile[tx, ty].tileCoord) > 10)
            {
                // Debug.Log("Change2");
                ai_Action    = AI_Action.Patrol;
                endTileCoord = patrolPoint[patrolPointNumber];
                UpdatePath();
            }
        }
Ejemplo n.º 3
0
 public Node(Node parent, float costSoFar, HashSet <KeyValuePair <string, object> > state, AI_Action action)
 {
     this.parent    = parent;
     this.costSoFar = costSoFar;
     this.state     = state;
     this.action    = action;
 }
Ejemplo n.º 4
0
    /// <summary>
    /// Called when a character finishes its current action.
    /// </summary>
    /// <param name="caster">Caster</param>
    public void OnCharacterActionFinished(AI_Character caster)
    {
        Debug.Log("[AI] Action finished (Caster ID: " + caster.CharacterID + ").");
        AI_Action action = caster.OnActionFinished(this.LastUpdateTime);

        this.TrainAction(action);
    }
Ejemplo n.º 5
0
    /// <summary>
    /// Trains the action/reaction network.
    /// </summary>
    /// <param name="action">Action performed</param>
    public void TrainAction(AI_Action action)
    {
        AI_DeepLearningNetwork network;

        // Training network - action
        network = this.Networks_Action[action.ActionCode];
        network.Learn(new float[] {
            action.CastDistance,
            action.CastAngleForCaster,
            action.CastAngleForTarget
        }, new float[] {
            action.Success ? 1.0f : 0.0f
        });

        // Training network - reaction
        network = this.Networks_Reaction[action.ActionCode][action.TargetActionCode];
        network.Learn(new float[] {
            action.CastDistance,
            action.CastAngleForCaster,
            action.CastAngleForTarget,
            action.TargetActionAdvantage
        }, new float[] {
            action.DamageDealt,
            action.DamageTaken
        });
    }
Ejemplo n.º 6
0
        void ChangeActionToChase()
        {
            if (path2.Count < 1)
            {
                return;
            }

            int endPosX = graphTools.RoundToTileCoord(player.transform.position.x, 0).x;
            int endPosY = graphTools.RoundToTileCoord(0, player.transform.position.y).y;
            int tx      = graphTools.RoundToTileCoord(transform.position.x, 0).x;
            int ty      = graphTools.RoundToTileCoord(0, transform.position.y).y;

            if (tileClass.myTile[endPosX, endPosY] == null)
            {
                return;
            }

            if (tileClass.myTile[tx, ty] == null)
            {
                return;
            }

            if (Vector2.Distance(tileClass.myTile[endPosX, endPosY].tileCoord, tileClass.myTile[tx, ty].tileCoord) < 10)
            {
                //Debug.Log("Change");
                ai_Action = AI_Action.Chase;
                UpdatePath();
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 获取Action的信息
        /// </summary>
        /// <param name="data">Action的数据</param>
        /// <returns>Action的信息</returns>
        public static string[] GetActionInformation(object data)
        {
            if (data == null || !(data is AI_SingleAction))
            {
                return(null);
            }

            AI_SingleAction saction = data as AI_SingleAction;
            AI_Action       action  = saction.Action;

            //获取参数
            string strRet = "";

            foreach (AI_Parm parm in action.Args)
            {
                strRet += parm.Value.GetCode() + ", ";
            }
            strRet = strRet.TrimEnd((new char[] { ',', ' ' }));

            // 返回值包含3个字符串:
            // 0: Action名
            // 1: 参数字符串,已经用,分隔开了
            // 2: ActionID
            // 3: ActionInfo
            return(new string[] { action.Ename.Trim(), strRet, action.ActionID, action.Info });
        }
Ejemplo n.º 8
0
    //RTA = RemoveThisAction
    //creates a subset of actions that excludes the RTA from the set
    private HashSet <AI_Action> actionSubset(HashSet <AI_Action> actions, AI_Action removeMe)
    {
        HashSet <AI_Action> subset = new HashSet <AI_Action>();

        foreach (AI_Action a in actions)
        {
            if (!a.Equals(removeMe))
            {
                subset.Add(a);
            }
        }
        return(subset);
    }
Ejemplo n.º 9
0
    //RTA = RemoveThisAction
    //creates a subset of actions that excludes the RTA from the set
    public HashSet <AI_Action> actionSubset(HashSet <AI_Action> actions, AI_Action RTA)
    {
        HashSet <AI_Action> subset = new HashSet <AI_Action>();

        foreach (AI_Action a in actions)
        {
            if (a.Equals(RTA))
            {
                subset.Add(a);
            }
        }
        return(subset);
    }
Ejemplo n.º 10
0
    public void Think(Board board)
    {
        state = StateEnum.Thinking;

        costTime = Time.realtimeSinceStartup;

        descriptor = new GameDescriptor(board, myTurn);
        action     = new AI_Action();
        nodeCount  = 0;

        aiTask = new Thread(DoCalculate);
        aiTask.Start();
        //DoCalculate();
    }
Ejemplo n.º 11
0
 /// <summary>
 /// 支援カードの破棄条件を満たしたら破棄する
 /// </summary>
 /// <param name="state"></param>
 /// <param name="action"></param>
 void SupportDestTrigger(PlayerState state, AI_Action action)
 {
     if (action.card != null && action.card.State.Cost >= 4)
     {
         foreach (Card c in new List <Card>(state.support))
         {
             if (c.State.cardType == ObjectType.Support && c.State.trigger == TriggerType.PlayCard_4CostOrMore)
             {
                 state.RemoveSupport(c);//.support.Remove(c);
                 state.Dest.Add(c);
             }
         }
     }
 }
Ejemplo n.º 12
0
    public void functionality()
    {
        if (!myAgent.hasActionQueue())
        {
            Debug.Log("ACTION STATE:: No actions to Perform!! -> PlanState");

            myAgent.dataProvider.actionsFinished();
            toPlan();
        }

        AI_Action action = myAgent.currentActions.Peek();

        if (action.isDone())
        {
            myAgent.currentActions.Dequeue();
        }

        if (myAgent.hasActionQueue())
        {
            //Debug.Log("Still have Actions to DO!");
            action = myAgent.currentActions.Peek();
            bool inRange = action.requiresInRange() ? action.isInRange() : true;

            if (inRange)
            {
                bool success = action.performAction(myAgent.gameObject);

                if (!success)
                {
                    myAgent.dataProvider.planAborted(action);
                    Debug.Log("ACTION STATE:: Plan Failed!! -> PlanState");

                    toPlan();
                }
            }
            else
            {
                Debug.Log("ACTION STATE:: Received moveTo!! -> MoveToState");

                toMoveTo();
            }
        }
        else
        {
            Debug.Log("ACTION STATE:: Action Queue Finished!! -> PlanState");
            myAgent.dataProvider.actionsFinished();
            toPlan();
        }
    }
    public void OnTargetActionStarted(AI_Action action)
    {
        if (this.Target != null && this.Target.CharacterID == action.Caster.CharacterID && (this.TargetActionCode == EActionCode.ActionCodeNoAction))
        {
            this.TargetActionCode      = action.ActionCode;
            this.TargetActionAdvantage = this.CastTime - action.CastTime;

            switch (action.ActionCode)
            {
            case EActionCode.ActionCodeGuard:
            case EActionCode.ActionCodeRoll:
                this.Success = true;
                break;
            }
        }
    }
Ejemplo n.º 14
0
    public AI_Action GetAcition()
    {
        if (actions.Count == 0)
        {
            return(new AI_Action());
        }
        AI_Action action = actions[0];

        actions.RemoveAt(0);
        if (actions.Count == 0)
        {
            state = StateEnum.Idle;
        }

        return(action);
    }
Ejemplo n.º 15
0
    private void Disturb(List <AI_Action> actions)
    {
        long tick = DateTime.Now.Ticks;

        System.Random random = new System.Random((int)(tick & 0xffffffffL) | (int)(tick >> 32));

        for (int i = 0; i < Disturb_Num; i++)
        {
            int indexA = random.Next(0, actions.Count),
                indexB = random.Next(0, actions.Count);

            AI_Action tmp = actions[indexA];
            actions[indexA] = actions[indexB];
            actions[indexB] = tmp;
        }
    }
Ejemplo n.º 16
0
    public bool moveAgent(AI_Action nextAction)
    {
        float walk = moveSpeed * Time.deltaTime;

        gameObject.transform.position = Vector3.MoveTowards(gameObject.transform.position, nextAction.target.transform.position, walk);

        if (gameObject.transform.position.Equals(nextAction.target.transform.position))
        {
            nextAction.setInRange(true);
            return(true);
        }
        else
        {
            return(false);
        }
    }
Ejemplo n.º 17
0
        /// <summary>
        /// 获取动作结点返回值个数
        /// </summary>
        /// <param name="data">动作结点数据</param>
        /// <returns>返回值个数</returns>
        public static int GetActionRetCount(object data)
        {
            int count = 0;

            if (data != null)
            {
                AI_SingleAction saction = data as AI_SingleAction;

                if (saction != null)
                {
                    AI_Action action = saction.Action;
                    count = action.RetList.Count;
                }
            }

            return(count);
        }
Ejemplo n.º 18
0
    private bool DoAIAction()
    {
        AI_Action action = ai.GetAcition();

        if (action.type == AI_Action.Type.Complete)
        {
            return(true);
        }
        else if (action.type == AI_Action.Type.Move)
        {
            Move(board.GetUnit(action.move.src), board.GetUnit(action.move.tar), action.move.tar);
        }
        else
        {
            Buy(action.buy.type);
        }
        return(false);
    }
Ejemplo n.º 19
0
    /// <summary>
    /// Called when a character starts a new action.
    /// </summary>
    /// <param name="caster">Caster</param>
    /// <param name="action_code">Code of the action (see EActionCode)</param>
    public void OnCharacterActionStarted(AI_Character caster, EActionCode action_code)
    {
        Debug.Log("[AI] Action started (Caster ID: " + caster.CharacterID + ", Action Code: " + action_code + ").");
        AI_Character target = null;

        // Determining the target
        switch (caster.CharacterType)
        {
        case ECharacterType.CharacterTypeEnemy:
            Debug.Assert(this.Characters.ContainsKey(AI_Params.PlayerID), "[AI] Invalid player ID (" + AI_Params.PlayerID + ").");
            target = this.Characters[AI_Params.PlayerID];
            break;

        case ECharacterType.CharacterTypePlayer:
            float distance = 10000.0f;
            foreach (AI_Character c in this.Characters.Values)
            {
                if (distance > Vector3.Distance(c.Position, caster.Position) + Mathf.Abs(Vector3.Angle(caster.Direction, c.Position - caster.Position)))
                {
                    distance = Vector3.Distance(c.Position, caster.Position) + Mathf.Abs(Vector3.Angle(caster.Direction, c.Position - caster.Position));
                    target   = c;
                }
            }
            break;
        }

        // Registering the action
        AI_Action action = caster.OnActionStarted(this.LastUpdateTime, action_code, target);

        foreach (AI_Character c in this.Characters.Values)
        {
            if ((c.CurrentAction != null) && (c.CurrentAction.Target.CharacterID == caster.CharacterID))
            {
                c.CurrentAction.OnTargetActionStarted(action);
            }
        }

        // Training anticipation network
        if (caster.CharacterType == ECharacterType.CharacterTypePlayer)
        {
            this.TrainAnticipation(caster, action_code);
        }
    }
Ejemplo n.º 20
0
 protected void Add(AI_Action action)
 {
     actions.Add(action);
 }
Ejemplo n.º 21
0
 public void planAborted(AI_Action aborted)
 {
     Debug.Log("AI AGENT ABORTED PLAN ON :::" + aborted);
 }
Ejemplo n.º 22
0
 public void DoAction(AI_Action action)
 {
     action.Do(this);
     NewTurn();
 }
Ejemplo n.º 23
0
    // Use this for initialization
    void Start()
    {
        //Check for players position and action
        //Read in SaveGame.xml
        XmlDocument SaveGameDoc = new XmlDocument();
        SaveGameDoc.LoadXml(DoSaveGame.FetchSaveData());

        foreach (XmlNode node in SaveGameDoc.SelectNodes("SaveData/SaveState/Scenes/Scene"))
        {
            if (Application.loadedLevelName == node.SelectSingleNode("SceneName").InnerText)
            {

                if (this.gameObject.name == "AI Josh" & node.SelectSingleNode("AI/JoshAI/X").InnerText != "" && node.SelectSingleNode("AI/JoshAI/Y").InnerText != "")
                {
                    //Set players x and y to what its saved in the save data
                    this.GetComponent<Transform>().position = new Vector3(float.Parse(node.SelectSingleNode("AI/JoshAI/X").InnerText), float.Parse(node.SelectSingleNode("AI/JoshAI/Y").InnerText));
                    if (node.SelectSingleNode("AI/JoshAI/Action").InnerText == "FollowPlayer") Action = AI_Action.FollowPlayer;
                    else if (node.SelectSingleNode("AI/JoshAI/Action").InnerText == "Event")
                    {
                        Action = AI_Action.Event;
                        EventType = int.Parse(node.SelectSingleNode("AI/JoshAI/EventType").InnerText);
                    }
                }
                else if (this.gameObject.name == "AI Matt" & node.SelectSingleNode("AI/MattAI/X").InnerText != "" && node.SelectSingleNode("AI/MattAI/Y").InnerText != "")
                {
                    //Set players x and y to what its saved in the save data
                    this.GetComponent<Transform>().position = new Vector3(float.Parse(node.SelectSingleNode("AI/MattAI/X").InnerText), float.Parse(node.SelectSingleNode("AI/MattAI/Y").InnerText));
                    if (node.SelectSingleNode("AI/MattAI/Action").InnerText == "FollowPlayer") Action = AI_Action.FollowPlayer;
                    else if (node.SelectSingleNode("AI/MattAI/Action").InnerText == "Event")
                    {
                        Action = AI_Action.Event;
                        EventType = int.Parse(node.SelectSingleNode("AI/MattAI/EventType").InnerText);
                    }
                }
                else if (this.gameObject.name == "AI Kate" & node.SelectSingleNode("AI/KateAI/X").InnerText != "" && node.SelectSingleNode("AI/KateAI/Y").InnerText != "")
                {
                    //Set players x and y to what its saved in the save data
                    this.GetComponent<Transform>().position = new Vector3(float.Parse(node.SelectSingleNode("AI/KateAI/X").InnerText), float.Parse(node.SelectSingleNode("AI/KateAI/Y").InnerText));
                    if (node.SelectSingleNode("AI/KateAI/Action").InnerText == "FollowPlayer") Action = AI_Action.FollowPlayer;
                    else if (node.SelectSingleNode("AI/KateAI/Action").InnerText == "Event")
                    {
                        Action = AI_Action.Event;
                        EventType = int.Parse(node.SelectSingleNode("AI/KateAI/EventType").InnerText);
                    }
                    //else if (node.SelectSingleNode("AI/KateAI/Action").InnerText == "Stationary") Action = AI_Action.Stationary;
                    //else if (node.SelectSingleNode("AI/KateAI/Action").InnerText == "StationaryWithDir") Action = AI_Action.StationaryWithDir;
                }
                else if (this.gameObject.name == "AI April" & node.SelectSingleNode("AI/AprilAI/X").InnerText != "" && node.SelectSingleNode("AI/AprilAI/Y").InnerText != "")
                {
                    //Set players x and y to what its saved in the save data
                    this.GetComponent<Transform>().position = new Vector3(float.Parse(node.SelectSingleNode("AI/AprilAI/X").InnerText), float.Parse(node.SelectSingleNode("AI/AprilAI/Y").InnerText));
                    if (node.SelectSingleNode("AI/AprilAI/Action").InnerText == "FollowPlayer") Action = AI_Action.FollowPlayer;
                    else if (node.SelectSingleNode("AI/AprilAI/Action").InnerText == "Event")
                    {
                        Action = AI_Action.Event;
                        EventType = int.Parse(node.SelectSingleNode("AI/AprilAI/EventType").InnerText);
                    }
                }
                else if (this.gameObject.name == "AI Ethan" & node.SelectSingleNode("AI/EthanAI/X").InnerText != "" && node.SelectSingleNode("AI/EthanAI/Y").InnerText != "")
                {
                    //Set players x and y to what its saved in the save data
                    this.GetComponent<Transform>().position = new Vector3(float.Parse(node.SelectSingleNode("AI/EthanAI/X").InnerText), float.Parse(node.SelectSingleNode("AI/EthanAI/Y").InnerText));
                    if (node.SelectSingleNode("AI/EthanAI/Action").InnerText == "FollowPlayer") Action = AI_Action.FollowPlayer;
                    else if (node.SelectSingleNode("AI/EthanAI/Action").InnerText == "Event")
                    {
                        Action = AI_Action.Event;
                        EventType = int.Parse(node.SelectSingleNode("AI/EthanAI/EventType").InnerText);
                    }
                }

                break;
            }
        }

        Body = GetComponent<Rigidbody2D>();
        Anim = GetComponent<Animator>();
        CircleCollision = GetComponent<CircleCollider2D>();
    }
Ejemplo n.º 24
0
 public void DoAction(AI_Action action)
 {
     action.Do(this);
     NewTurn();
 }
Ejemplo n.º 25
0
    /// <summary>
    /// 行動結果を予測する
    /// </summary>
    /// <param name="state">実行前の状況</param>
    /// <param name="action">実行する行動</param>
    /// <returns>実行後の状況</returns>
    PlayerState ActionEnter(PlayerState state, AI_Action action)
    {
        state = new PlayerState(state);
        state.enterdAction = action;
        state.actionCount++;

        //なんか色々
        switch (action.actType)
        {
        case ActionType.Attack:
            if (action.target)
            {
                state.atkedCount++;
                Damage(state, action.target, state.atk);
            }
            break;

        case ActionType.cardPlay:
            state.hand.Remove(action.card);
            SupportDestTrigger(state, action);
            state.cost -= action.card.State.Cost;
            switch (action.card.State.cardType)
            {
            case ObjectType.Unit:
                state.AddUnit(action.card);        // unit.Add(action.card);
                state.atk   += action.card.State.atk;
                state.skill += action.card.State.skill;
                break;

            case ObjectType.Support:
                state.AddSupport(action.card);        //support.Add(action.card);
                state.atk   += action.card.State.atk;
                state.skill += action.card.State.skill;
                break;

            case ObjectType.Trap:
                state.AddSupport(action.card);        //support.Add(action.card);
                state.cost += action.card.State.Cost;
                break;

            case ObjectType.Skill:
                state.Dest.Add(action.card);
                break;

            default: break;
            }
            foreach (CardEffect ce in action.card.State.Effect)
            {
                if (ce.GetEffectPlayType() == EffectPlayType.triggerEffect)
                {
                    state.score_mod += GetTriggerEffectPoint(state, ce as TriggerEffect);
                    state.score_mod -= action.card.State.atk * ai.atk;
                    continue;
                }
                else if (ce.GetEffectPlayType() == EffectPlayType.activeEffect && action.card.State.cardType == ObjectType.Support)
                {
                    state.score_mod += 3;
                }
                if (ce.GetEffectPlayType() != EffectPlayType.playEffect)
                {
                    continue;
                }
                foreach (EffectState es in ce.effectState)
                {
                    switch (es.effectType)
                    {
                    case EffectType.AttackAdd:
                        if (es.Target.targetType == TargetType.friend)
                        {
                            state.atk += es.value;
                            //ターン終了で攻撃力が戻るので、継続的なスコアには加算しない
                            state.score_mod -= es.value * ai.atk;
                        }
                        else
                        {
                            state.enemy.atk += es.value;
                        }
                        break;

                    case EffectType.AttackTime:
                        state.atkCount = es.value;
                        break;

                    case EffectType.CardDest:
                        if (action.target)
                        {
                            Dest(state, action.target);
                        }
                        else if (es.Target.isAll)
                        {
                            Dest(state, es.GetTargets(state.p));
                        }
                        break;

                    case EffectType.CardDraft:
                        state.hand.Add(null);
                        break;

                    case EffectType.CardDraw:
                        for (int i = 0; i < es.value; i++)
                        {
                            state.hand.Add(null);
                        }
                        break;

                    case EffectType.CardUnDraft:
                        for (int i = 0; i < es.value - 1; i++)
                        {
                            state.hand.Add(null);
                        }
                        break;

                    case EffectType.CostAdd:
                        state.cost += es.value;
                        break;

                    case EffectType.Damage:
                        int damage = es.value + (action.card.State.cardType == ObjectType.Skill ? state.skill : 0);
                        //Debug.Log(action.card.State.cardName + ":" + damage);
                        if (action.target)
                        {
                            Damage(state, action.target, damage);
                        }
                        else if (es.Target.isAll)
                        {
                            Damage(state, es.Target.GetTargets(state.p), damage);
                        }
                        else
                        {
                            Debug.Log("対象が不明です");
                        }
                        break;

                    case EffectType.Counter:
                        state.score_mod += 2;
                        break;
                    }
                }
            }
            break;

        case ActionType.cardDisp:
            switch (action.card.State.cardType)
            {
            case ObjectType.Unit:
                state.RemoveUnit(action.card);        //.unit.Remove(action.card);
                state.atk   -= action.card.State.atk;
                state.skill -= action.card.State.skill;
                break;

            case ObjectType.Support:
                state.RemoveSupport(action.card);        //support.Remove(action.card);
                state.atk   -= action.card.State.atk;
                state.skill -= action.card.State.skill;
                break;

            case ObjectType.Trap:
                state.RemoveSupport(action.card);        //support.Remove(action.card);
                break;
            }
            state.score_mod -= 2;
            foreach (CardEffect ce in action.card.State.Effect)
            {
                if (ce.GetEffectPlayType() == EffectPlayType.triggerEffect)
                {
                    state.score_mod -= GetTriggerEffectPoint(state, ce as TriggerEffect);
                }
            }
            break;

        case ActionType.activeEffect:
            foreach (CardEffect ce in action.card.State.Effect)
            {
                ActiveEffect ae = ce as ActiveEffect;
                if (ae != null)
                {
                    state.cost -= ae.cost;
                    state.PlayActiveEffect(action.card);
                    foreach (EffectState es in ce.effectState)
                    {
                        switch (es.effectType)
                        {
                        case EffectType.AttackAdd:
                            state.atk += es.value;
                            break;

                        case EffectType.GetDisZoneCard:
                            if (action.target)
                            {
                                Card c = action.target.GetComponent <Card>();
                                state.hand.Add(c);
                                state.Dest.Remove(c);
                            }
                            break;
                        }
                    }
                }
            }
            break;
        }
        GetAllAction(state);
        return(state);
    }
Ejemplo n.º 26
0
 protected void Add(AI_Action action)
 {
     actions.Add(action);
 }
Ejemplo n.º 27
0
    public void Think(Board board)
    {
        state = StateEnum.Thinking;

        costTime = Time.realtimeSinceStartup;

        descriptor = new GameDescriptor(board, myTurn);
        action = new AI_Action();
        nodeCount = 0;

        aiTask = new Thread(DoCalculate);
        aiTask.Start();
        //DoCalculate();
    }
Ejemplo n.º 28
0
 public bool moveAgent(AI_Action nextAction)
 {
     return(false);
 }
Ejemplo n.º 29
0
 public void planAborted(AI_Action aborter)
 {
     Debug.Log("PLAN ABORTED PLAN ABORTED PLAN ABORTED");
 }
Ejemplo n.º 30
0
        void MakeMove()
        {
            // Debug.Log(n);
            if (path2.Count < 1)
            {
                i = 0;
                //Debug.Log("asdasdsa");
                return;
            }

            if (i > path2.Count - 1)
            {
                i = 0;
                // Debug.Log("00");
                return;
            }

            if (tileClass.myTile[startTileCoord.x, startTileCoord.y] == null)
            {
                // Debug.Log("StartNull");
                return;
            }

            if (tileClass.myTile[endTileCoord.x, endTileCoord.y] == null)
            {
                // Debug.Log("endNull");
                endTileCoord = path2[path2.Count - 1].tilePos;
                //return;
            }

            if (path2[i].tilePos == endTileCoord)
            {
                // Debug.Log("End");
                n         = Vector2Int.zero;
                ai_Action = AI_Action.Attack;
                // i = 0;
                // return;
            }

            if (i < path2.Count - 1 && startTileCoord == path2[i].tilePos)
            {
                i++;
                n = path2[i].tilePos - tileClass.myTile[startTileCoord.x, startTileCoord.y].tileCoord;
                // Debug.Log("n = " + n);
            }

            if (n.y == 0 && Mathf.Abs(n.x) == 1)
            {
                // Debug.Log("NNNNN");
                Move(path2[i].tilePos);
            }

            if (n.y < 0 && n.x == 0)
            {
                MoveDown(path2[i].tilePos);
            }

            if (n.y < 0 && Mathf.Abs(n.x) > 0)
            {
                Jump(path2[i], n);
            }

            if (n.y == 0 && Mathf.Abs(n.x) > 1)
            {
                JumpBridge(path2[i], n);
            }

            if (n.y > 0)
            {
                Jump(path2[i], n);
            }
        }
Ejemplo n.º 31
0
 public void addAction(AI_Action action)
 {
     availableActions.Add(action);
 }
Ejemplo n.º 32
0
    protected virtual IEnumerator DoTurn(GridManager a_grid)
    {
        AI_Action  bestAction     = null;
        int        playerToAttack = 0;
        float      bestScore      = int.MinValue;
        List <Hex> path           = null;

        players[0] = Manager.instance.PlayerController.EarthUnit;
        players[1] = Manager.instance.PlayerController.LightningUnit;

        ScoringInfo[] scoringInfo = new ScoringInfo[2];
        scoringInfo[0] = (players[0] == null || players[0].IsDead) ? null : new ScoringInfo(a_grid, this, players[0]);
        scoringInfo[1] = (players[1] == null || players[1].IsDead) ? null : new ScoringInfo(a_grid, this, players[1]);

        foreach (AI_Action action in actions)
        {
            for (int i = 0; i < 2; i++)
            {
                if (scoringInfo[i] == null)
                {
                    continue;
                }

                float score = action.GetScore(scoringInfo[i]);
                if (scoringInfo[i].Path != null)
                {
                    if (score > bestScore)
                    {
                        bestAction     = action;
                        playerToAttack = i;
                        bestScore      = score;
                        path           = scoringInfo[i].Path;
                    }
                }
            }
        }

        if (bestAction == null)
        {
            Debug.Log("No valid actions found", gameObject);
            turnComplete = true;
            yield break;
        }

        // Remove the path that is out of the movement range
        if (path.Count > MoveRange)
        {
            path.RemoveRange(MoveRange, path.Count - MoveRange);
        }

        // Path find and wait for it to finish
        isPerformingAction = true;
        finishedWalking    = FinishedAction;
        StartCoroutine(Walk(path));
        yield return(new WaitUntil(() => isPerformingAction == false));

        // Attack the player, checking if it is in range && if we have a clear shot
        if (HexUtility.Distance(currentTile, players[playerToAttack].CurrentTile) <= attackRange && HasClearShot(players[playerToAttack]))
        {
            isPerformingAction = true;
            BasicAttack(new Hex[] { players[playerToAttack].CurrentTile }, null, FinishedAction);
            yield return(new WaitUntil(() => isPerformingAction == false));
        }

        turnComplete = true;
        yield break;
    }