コード例 #1
0
    public override void OnTick(IBoardState[] data)
    {
        //Spend all tokens
        //Spawn in each lane otherwise attack or move
        int maxCycles = 99;

        while (AIResponse.Tokens > 0 && maxCycles > 0)   //Spend all tokens
        {
            maxCycles--;
            if (Random.Range(0, 2) == 0 || _Creatures.Count == 0)
            {
                int randomLane = Random.Range(1, TournamentManager._instance.lanes.Count + 1);
                // LogStack.Log ("Random Spawn Lane " + randomLane, LogLevel.System);
                if (!AIResponse.Spawn(Random.Range(0, 2) == 0 ? Spawnable.Bunny : Spawnable.Unicorn, randomLane))
                {
                    if (_Creatures.Count > 0)
                    {
                        CreatureBase randomCreature = _Creatures[Random.Range(0, _Creatures.Count)];
                        AttemptMoveAttack(randomCreature);
                    }
                }
            }
            else if (_Creatures.Count > 0)
            {
                CreatureBase randomCreature = _Creatures[Random.Range(0, _Creatures.Count)];
                AttemptMoveAttack(randomCreature);
            }
        }

        AIResponse.FinalizeResponse();
    }
コード例 #2
0
 public override void OnTick(IBoardState[] data)
 {
     if (!AIResponse.Spawn(Spawnable.Unicorn, 1))
     {
     }
     //IResponse[] responses = AIResponse.QueryResponse();
     AIResponse.FinalizeResponse();
 }
コード例 #3
0
 private bool TokenCheck()
 {
     if (AIResponse.Tokens <= 0)
     {
         AIResponse.FinalizeResponse();
         return(false);
     }
     return(true);
 }
コード例 #4
0
 public override void OnTick(IBoardState[] data)
 {
     if (!AIResponse.Spawn(Random.Range(0, 2) == 0 ? Spawnable.Bunny : Spawnable.Unicorn, Random.Range(1, 4)))
     {
         if (_Creatures.Count > 0)
         {
             AIResponse.Attack(_Creatures[0]);
         }
     }
     //IResponse[] responses = AIResponse.QueryResponse();
     AIResponse.FinalizeResponse();
 }
コード例 #5
0
    public override void OnTick(IBoardState[] data)
    {
        boardState = (LaneManager[])data;

        for (int i = 1; i < (TournamentManager._instance.tokensPerRound == 1?3:6); i++)
        {
            FormPattern(LanePattern, i, boardState);
        }
        //for (int i = 0; i < 3; i++)
        //{
        //    AIResponse.Attack(boardState[i].GetFriendliesInLane(this).Count>0? boardState[i].GetFriendliesInLane(this)[0]:null);
        //}

        Auto_Nearest(boardState);

        CreatureBase nearest = null;

        for (int i = 0; i < 2; i++)
        {
            if (boardState[i].GetFriendliesInLane(this).Count != 0)
            {
                if (nearest != null)
                {
                    if (boardState[i].GetFriendliesInLane(this) [0].LaneProgress > nearest.LaneProgress)
                    {
                        nearest = boardState[i].GetFriendliesInLane(this) [0];
                    }
                }
                else
                {
                    nearest = boardState[i].GetFriendliesInLane(this) [0];
                }
            }
        }

        if (AIResponse.Tokens > Threshhold)
        {
            AIResponse.Move(nearest, AIResponse.Tokens - Threshhold);
        }
        else
        {
            AIResponse.Move(nearest, 1);
        }

        for (int i = 0; i < AIResponse.Tokens; i++)
        {
            Auto_Nearest(boardState);
        }

        AIResponse.FinalizeResponse();
    }
コード例 #6
0
    public override void OnTick(IBoardState[] data)
    {
        boardState = (LaneManager[])data;

        for (int i = 1; i < 3; i++)
        {
            FormPattern(LanePattern, i, boardState);
        }

        //Auto_Nearest(boardState);

        //if (AIResponse.Tokens > 1)
        //    AIResponse.Move(MostProgressed(boardState), 1);

        AIResponse.FinalizeResponse();
    }
コード例 #7
0
    public override void OnTick(IBoardState[] board)
    {
        boardState = (LaneManager[])board;

        Debug.Log(boardState.Length);
        LogStack.Log("Run Auto Response Nearest for:" + AIResponse.Tokens, Logging.LogLevel.Color);
        //for (int i = 0; i < AIResponse.Tokens; i++)
        //{
        //    Auto_Nearest(boardState);
        //}
        Auto_Nearest(boardState);
        Auto_Nearest(boardState);
        Auto_Nearest(boardState);

        //}
        ////IResponse[] responses = AIResponse.QueryResponse();
        AIResponse.FinalizeResponse();
    }
コード例 #8
0
    public override void OnTick(IBoardState[] data)
    {
        int  maxCycles = 99;
        int  tokens    = AIResponse.Tokens;
        bool saving    = true;
        bool fresh     = true;

        int cnt = 0;

        if (saving)
        {
            if (tokens > 30)
            {
                saving = false;
                fresh  = false;
            }
        }

        foreach (LaneManager lane in TournamentManager._instance.lanes)
        {
            if (lane.GetEnemiesInLane(this).Count > 0)
            {
                saving = false;
            }
        }

        if (!saving)
        {
            while (AIResponse.Tokens > 0 && maxCycles > 0)
            {
                DoSpawn();

                maxCycles--;
            }
        }
        //IResponse[] responses = AIResponse.QueryResponse();


        AIResponse.FinalizeResponse();
    }
コード例 #9
0
            public override void OnTick(IBoardState[] data)
            {
                AIResponse.onTick(null);

                var maxCycles = 99;

                Initialize();

                while (AIResponse.Tokens > 0 && maxCycles > 0)
                {
                    if (CheckIfAlliesAreInAttackingDistance())
                    {
                        continue;
                    }



                    SpawnEnemy();


                    CreatureBase FarthestLane1Ally = null;
                    CreatureBase FarthestLane2Ally = null;
                    CreatureBase FarthestLane3Ally = null;

                    if (TournamentManager._instance.lanes[0].GetFriendliesInLane(this).Count > 0)
                    {
                        FarthestLane1Ally = TournamentManager._instance.lanes[0].GetFriendliesInLane(this)[0];
                        if (FarthestLane1Ally != null && !friendlyBases.Contains(FarthestLane1Ally))
                        {
                            friendlyBases.Add(FarthestLane1Ally);
                        }
                    }

                    if (TournamentManager._instance.lanes[1].GetFriendliesInLane(this).Count > 0)
                    {
                        FarthestLane2Ally = TournamentManager._instance.lanes[1].GetFriendliesInLane(this)[0];
                        if (FarthestLane2Ally != null && !friendlyBases.Contains(FarthestLane2Ally))
                        {
                            friendlyBases.Add(FarthestLane2Ally);
                        }
                    }

                    if (TournamentManager._instance.lanes[2].GetFriendliesInLane(this).Count > 0)
                    {
                        FarthestLane3Ally = TournamentManager._instance.lanes[2].GetFriendliesInLane(this)[0];
                        if (FarthestLane3Ally != null && !friendlyBases.Contains(FarthestLane3Ally))
                        {
                            friendlyBases.Add(FarthestLane3Ally);
                        }
                    }


                    var          farthsetAlong    = 0;
                    CreatureBase withMostProgress = null;


                    foreach (var creatureBase in friendlyBases)
                    {
                        if (creatureBase != null && creatureBase.LaneProgress > farthsetAlong ||
                            withMostProgress.isDead)
                        {
                            farthsetAlong = creatureBase.LaneProgress;

                            withMostProgress = creatureBase;
                        }
                    }

                    Debug.Log("Further: " +
                              (withMostProgress != null ? withMostProgress.GetInstanceID().ToString() : " NULL"));


                    CreatureBase canFinish = null;

                    foreach (var creature in _Creatures)
                    {
                        int remaining = creature.LaneProgress - 10;

                        if (remaining <= 10)
                        {
                            canFinish = creature;
                        }
                    }


                    if (CheckIfCreatureCanFinish(canFinish))
                    {
                        Debug.Log("Finish");
                    }
                    else
                    {
                        CheckIfClosestenemyIsInAttackingrange(withMostProgress);
                    }



                    maxCycles--;
                }


                AIResponse.FinalizeResponse();
            }
コード例 #10
0
 void Finalise()
 {
     IResponse[] responses = AIResponse.QueryResponse();
     AIResponse.FinalizeResponse();
     Debug.Log(this.name + " cost: " + AIResponse.Tokens);
 }
コード例 #11
0
    public override void OnTick(IBoardState[] data)
    {
        if (!B_Init)
        {
            Init();
        }
        I_Round++;

        // ####### --- Performance Tracking (Learning) System --- #######
        PrintPerformance();
        UpdatePerformanceData();
        CalculatePerformance();
        if (I_Round % I_TurnsBetweenChecks == 0)
        {
            EvaluatePerformance();
        }
        if (I_Round % I_TurnsBetweenChanges == 0)
        {
            Adapt();
        }

        AttackedThisTurn.Clear();
        UpdateLaneAdvantage();
        iUnicornAttacks = 0;

        // ####### --- Advanced Response System --- #######
        responseState = EResponseState.Basic;
        EmergencyCheck();
        if (responseState == EResponseState.Emergency)
        {
            SpawnTroop(iResponseLane);
            responseState = EResponseState.Basic;
        }
        else // Ensures emergencies are priorities over point pushing and bunny rushing.
        {
            PointPushCheck();
            if (responseState == EResponseState.PointPush)
            {
                LogStack.Log("%%%%%%%%%%%%%%%%%%%%%% Point Push Triggered - iSavingTokens =" + iSavingTokens, LogLevel.Debug);
                if (AIResponse.Tokens >= iSavingTokens)
                {
                    AdvancedResponse();
                }
            }
            else // Ensures point pushes are priorities over bunny rushing.
            {
                BunnyThreatCheck();
                if (responseState == EResponseState.BunnyRush && AIResponse.Tokens > iSavingTokens)
                {
                    iSavingTokens--;
                    AdvancedResponse();
                }
            }
        }
        LogStack.Log("%%%%%%%%%%%%%%%%%%%%%% Advanced Responses Complete - iSavingTokens =" + iSavingTokens, LogLevel.Debug);

        // ####### --- Basic Response System --- #######
        // ####### --- Defense --- #######
        int iCount            = 0;
        int iCurrentThreshold = iDefTokenThreshold + iSavingTokens;

        while ((AIResponse.Tokens > iCurrentThreshold) && iCount < 5)
        {
            iCount++;
            if (TokenCheck() == false)
            {
                return;
            }
            int iWeakLane = GetDefendingLane();
            LogStack.Log("Weak Lane = " + iWeakLane.ToString(), LogLevel.Debug);
            SpawnTroop(iWeakLane);
        }
        //if (TokenCheck() == false) return;

        // ####### --- Offense (A) --- #######
        // ------- Stage One - Bunnies -------
        List <CreatureBase> StageTroops = GetTroops(Spawnable.Bunny, true); // Front Bunnies.

        LogStack.Log("%%%%%%%%%%%%%%%%%%%%%% Front Bunnies Count =" + StageTroops.Count, LogLevel.Debug);
        AttackWithTroops(StageTroops);
        StageTroops.Clear(); // Reset for Second Stage

        // ------- Stage Two - Unicorns -------
        StageTroops = GetTroops(Spawnable.Unicorn); // All Unicorns.
        AttackWithTroops(StageTroops);
        StageTroops.Clear();

        // ####### --- Offense (M) --- ####### ------------------------------------------------------------------------ TODO - Change to use all available extra tokens? Use dedicated "Push" and "Push Support" lanes.
        if (TokenCheck() == false)
        {
            return;
        }
        iCurrentThreshold = iAttackTokenThreshold + iSavingTokens;
        int iAvalableTokens = AIResponse.Tokens - iCurrentThreshold;

        if (iAvalableTokens > 0)
        {
            int iLane = UnityEngine.Random.Range(1, 3);
            List <CreatureBase> AvailableLaneTroops = TournamentManager._instance.lanes[iLane].GetFriendliesInLane(this);
            if (AvailableLaneTroops.Count > 0)
            {
                AIResponse.Move(AvailableLaneTroops[0], iAvalableTokens);
            }
        }

        AIResponse.FinalizeResponse();
    }
コード例 #12
0
    public override void OnTick(IBoardState[] data)
    {
        if (_Start)
        {
            _Start         = false;
            attackingPairs = new List <AttackingPair> ();
            //---Add empty pairs at start---
            for (int i = 1; i < 4; i++)
            {
                attackingPairs.Add(new AttackingPair(i, this));
            }
        }

        boardState = (LaneManager[])data;

        //---spawn for each pair---
        foreach (var pair in attackingPairs)
        {
            pair.SpawnPair(AIResponse);
        }

        foreach (LaneManager lane in TournamentManager._instance.lanes)
        {
            int playerInLane = lane.GetFriendliesInLane(this).Count;
            if (playerInLane <= 0)
            {
                foreach (var pair in attackingPairs)
                {
                    if (pair.spawnProg == 0)
                    {
                        pair.SpawnPair(AIResponse);
                    }
                }
            }
        }


        #region More than 20
        if (AIResponse.Tokens >= 20)
        {
            LaneManager  _lane           = null;
            CreatureBase _friendlyToMove = null;
            int          previousEnemies = 0;
            bool         _moveAttack     = true;

            //---check each lane---
            foreach (LaneManager lane in TournamentManager._instance.lanes)
            {
                int playerInLane = lane.GetFriendliesInLane(this).Count;
                int enemyInLane  = lane.GetEnemiesInLane(this).Count;
                //---Find Open lane---
                if (enemyInLane == 0 && playerInLane > 0)
                {
                    _lane           = lane;
                    _friendlyToMove = _lane.GetFriendliesInLane(this) [0];
                    //---move the creature to end of lane---
                    int _openNodes = _friendlyToMove.ActiveLaneNode.laneManager.GetOpenNodes(_friendlyToMove.ActiveLaneNode, _RightFacing);
                    //---find pair that contains friendlyToMove---
                    foreach (var pair in attackingPairs)
                    {
                        if (pair.ContainsCreature(_friendlyToMove))
                        {
                            pair.MovePair(AIResponse);
                            break;
                        }
                    }
                    _moveAttack = false;
                    break;
                }
                //---ELSE Find lane with least amount of enemies---
                else if (enemyInLane > 0 && playerInLane > 0)
                {
                    if (enemyInLane > previousEnemies)
                    {
                        previousEnemies = enemyInLane;
                        _lane           = lane;
                        _friendlyToMove = _lane.GetFriendliesInLane(this) [0];
                    }
                }
            }

            Debug.Log("Friendly to move: " + _friendlyToMove);
            Debug.Log("MoveAttack :" + _moveAttack);
            if (_moveAttack && _friendlyToMove != null)
            {
                //---attemp movetowards and attack each enemy in lane, then move to end of lane---
                foreach (CreatureBase _enemy in _lane.GetEnemiesInLane(this))
                {
                    //---Move to enemy, attack, then move to end of Lane---
                    int _openNodes = _friendlyToMove.ActiveLaneNode.laneManager.GetOpenNodes(_friendlyToMove.ActiveLaneNode, _RightFacing);
                    //---find pair that contains friendlyToMove---
                    foreach (var pair in attackingPairs)
                    {
                        if (pair.ContainsCreature(_friendlyToMove))
                        {
                            if (!pair.MovePair(AIResponse))
                            {
                                AttemptMoveAttack();
                            }
                            break;
                        }
                    }
                }
            }
        }
        #endregion
        else
        {
            //---Get Enemy Count---
            GetCount();

            //---If there are Enemies, find the closest---
            if (enemyCount > 0)
            {
                FindNearest();
                //---if neareast found, move towards and attack---
                if (targetCreature != null)
                {
                    AttemptAttackMoveTarget(targetCreature);
                }
            }
            //--else random move or attack--
            else
            {
                AttemptMoveAttack();
            }
        }
        AIResponse.FinalizeResponse();
    }