Пример #1
0
        private void ControllerThread_Work()
        {
            foreach (var team in m_teams)
            {
                team.AIPlugin.GameStarted();
            }
            drawMap();
            AIStep[] nextSteps = new AIStep[m_teams.Count];
            int      seed      = 0;

            while (!m_gameFinished)
            {
                Thread.Sleep(m_waitTimeBetweenStepsMs);
                m_controllerThreadEvent.WaitOne();

                for (int i = 0; i < nextSteps.Length; ++i)
                {
                    if (m_teams[i].IsAlive)
                    {
                        nextSteps[i] = m_teams[i].AIPlugin.RequireStep(seed);
                        ++seed;
                    }
                }
                ProcessSteps(nextSteps);
                drawMap();
                postProcessMap();   //remove explosion fires, etc...
            }
        }
Пример #2
0
        public AIStep RequireStep(int seed)
        {
            //How to get the place of your player
            //m_thisTeam.FieldI.X;
            //m_thisTeam.FieldI.Y;

            //m_thisTeam.getBombsI();   //get all of your bombs
            //m_gameController.isExplodable(m_gameBoard.getFieldI(5, 6));   //is (5, 6) field explodable (walls are not explodable)
            //m_gameController.isValidToBomb(m_gameBoard.getFieldI(2, 4), m_gameBoard, m_thisTeam);    //can you put bomb onto field (2, 4) or not

            //How to get all of the players of the game (including your team)
            //m_gameController.getTeamsI();
            //m_gameController.getTeamsI().Length;  //count of the teams in the game
            //m_gameController.getTeamsI()[2].IsAlive;    //is the given team still alive or not

            //m_gameController.getTeamsI()[2].getBombsI();  //returns all of the bombs of team 2

            //How to get the sizes of gameboard
            //m_gameBoard.Size;   //== MaxX - MinX + 1
            //m_gameBoard.MinX;   //the smallest valid x coordinate on the board
            //m_gameBoard.MaxX;   //the largest valid x coordinate on the board
            //m_gameBoard.MinY;
            //m_gameBoard.MaxY;
            //How to get a given field by coordinates, returns null if the coordinates are not valid
            //m_gameBoard.getFieldI(X, Y);

            //field examples
            //m_gameBoard.getFieldI(5, 8).getBombsI();  //return all of the bombs of field (5, 8)

            //bomb examples
            //List<IBomb> allBombs = m_gameController.getBombsI();    //get all of the bombs on the board
            //IBomb bomb = m_gameBoard.getFieldI(5, 8).getBombsI().ToArray[1];  //range check required before ToArray()
            //bomb.getOwnerI();   //get the owner team of a given bomb
            //bomb.FieldI.X;        //the place of the bomb
            //bomb.FieldI.Y;
            //bomb.getExplosiveRadius();    //the explosive radius of the given bomb

            Random random = new Random(seed);

            AIStep response  = new AIStep();
            int    nextStepi = random.Next(typeof(AIStep.StepEnum).GetEnumValues().Length);
            int    nextMovei = random.Next(typeof(AIStep.MoveEnum).GetEnumValues().Length);

            response.nextStep = (AIStep.StepEnum)nextStepi;
            //response.nextStep = AIStep.StepEnum.MOVE;
            response.nextMove = (AIStep.MoveEnum)nextMovei;

            return(response);
        }
Пример #3
0
 void Restart()
 {
     //Debug.Log("*AI* Restarting Steps");
     currentStep = AIStep.SelectUnit;
     selectedUnit = null;
     target = null;
     path = null;
 }
Пример #4
0
        public void Control()
        {
            if (!stopped && stepTime > stepDelay)
            {
                stepTime -= stepDelay;
                //Debug.Log("*AI* Loop");
                switch (currentStep)
                {
                    case AIStep.SelectUnit:
                        //Debug.Log("*AI* Selection");
                        if (!SelectUnit())
                        {
                            stopped = true;
                            //Debug.Log("*AI* Stopped!");
                        }
                        else if (selectedUnit != null)
                        {
                            currentStep = AIStep.FindPath;
                            unitController.SelectedInstance = selectedUnit;
                            //Debug.Log("*AI* Unit Selected");
                        }
                        break;

                    case AIStep.FindPath:
                        //Debug.Log("*AI* Pathing");

                        //path = GGAStar.GetPath(selectedUnit.Head.Cell, target, true, false);
                        path = RegenPath();

                        // GOTO Move
                        currentStep = AIStep.Move;
                        unitController.CurrentAction = UnitController.SelectedAction.Move;
                        pathIndexer = 1;
                        break;

                    case AIStep.Move:
                        //Debug.Log("*AI* Moving");
                        int pathMinus = 0;
                        if (path.LastOrDefault() != null)
                        {
                            UnitBody body = path.LastOrDefault().Objects.Select(ggo => ggo.GetComponent<UnitBody>()).FirstOrDefault(b => b != null);
                            if (path.LastOrDefault().IsOccupied && body != null && body.UnitInstance != selectedUnit)
                            {
                                pathMinus = 1;
                            }
                        }

                        if (unitController.RemainingMoves > 0 && pathIndexer < path.Count - pathMinus)
                        {
                            //Debug.Log("*AI* Move");
                            unitController.MoveSelectedUnit(path[pathIndexer]);
                            pathIndexer++;
                        }
                        else
                        {
                            //Debug.Log("*AI* Destination");
                            //unitController.CompleteTurnActions();
                            //Restart();
                            currentStep = AIStep.SelectTarget;
                        }
                        break;

                    case AIStep.SelectTarget:
                        //Debug.Log("*AI* Targeting");
                        target = GetNearestOfEnemy();

                        if (target != null && target.GetTypesInCell<UnitBody>().FirstOrDefault())
                        {
                            currentStep = AIStep.Attack;
                            unitController.CurrentAction = UnitController.SelectedAction.Action_1;
                        }
                        break;

                    case AIStep.Attack:
                        //Debug.Log("*AI* Attack");
                        //target

                        if (UnitInstance.GetDistanceBetweenCells(selectedUnit.Head.Cell, target) <= selectedUnit.Definition.GetActionModuleInclusive((int)unitController.CurrentAction).RangeValue)
                        {
                            unitController.CommitSelectedActionTo(target);
                            //unitController.CompleteTurnActions();
                        }
                        else
                        {
                            unitController.CompleteTurnActions();
                        }
                        Restart();
                        //stopped = true;
                        break;
                }
                /*if (selectedUnit.IsExausted)
                {
                    Restart();
                }*/
            }
            stepTime += Time.deltaTime;
        }