예제 #1
0
        // this is an AI which chooses a random unit and returns a random answer
        public override void YourTurn(TurnData turnData)
        {
            base.YourTurn(turnData);
            var turnObject = GameManager.Brain.MakeDecision(turnData, this);

            StartCoroutine(UIManager.ChoiceManager.HandleAiChoice(ValidateTurnObject(turnObject)));
        }
        public override TurnObject MakeDecision(TurnData turnData, Player player)
        {
            var myUnits       = player.MyUnits;
            var randomIndex   = Random.Range(0, myUnits.Count);
            var randomUnit    = myUnits[randomIndex];
            var unitOptions   = turnData._positionOptions[randomUnit];
            var positionIndex = Random.Range(0, unitOptions.Count);
            var position      = unitOptions[positionIndex];

            randomUnit.Position = position;
            var turnObject = new TurnObject();

            turnObject.ChosenUnit = randomUnit;

            randomIndex = Random.Range(0, 2);
            switch (randomIndex)
            {
            case 0:
                turnObject.AttackDirection = AttackDirection.row;
                break;

            case 1:
                turnObject.AttackDirection = AttackDirection.square;
                break;

            case 2:
                turnObject.AttackDirection = AttackDirection.colum;
                break;
            }

            return(turnObject);
        }
 public void StartTurn(Player player, TurnData turnData)
 {
     ClearData();
     _playerTurnData = turnData;
     _numberChoices  = new List <int>();
     foreach (var unit in _playerTurnData._positionOptions.Keys)
     {
         if (_playerTurnData._positionOptions[unit].Count > 0)
         {
             _numberChoices.Add(unit.Value);
         }
     }
     UIManager.SetPlayerAvailableNumbers(_numberChoices, player.playerSide, true);
 }
        // this is an AI which chooses a random unit and returns a random answer

        public override TurnObject MakeDecision(TurnData turnData, Player player)
        {
            var randomIndex = UnityEngine.Random.Range(0, player.MyUnits.Count);
            var randomUnit  = player.MyUnits[randomIndex];
            var unitOptions = turnData._positionOptions[randomUnit];

            while (unitOptions.Count == 0)
            {
                randomIndex = UnityEngine.Random.Range(0, player.MyUnits.Count);
                randomUnit  = player.MyUnits[randomIndex];
                unitOptions = turnData._positionOptions[randomUnit];
            }

            var turnObject = new TurnObject();

            turnObject.ChosenUnit = randomUnit;

            SetHighestPointAttack(turnObject, unitOptions, turnData);
            return(turnObject);
        }
 private bool IsGameOver(TurnData nextTurnData)
 {
     return(nextTurnData._positionOptions.Count == 0);
 }
        private void SetHighestPointAttack(TurnObject turnObject, List <Position> unitOptions, TurnData turnData)
        {
            var unit          = turnObject.ChosenUnit;
            var maxPoints     = 0;
            var index         = 0;
            var bestDirection = AttackDirection.colum;

            for (int i = 0; i < unitOptions.Count; i++)
            {
                var rowPoints    = GetRowPoints(unitOptions[i], unit, turnData.boardData);
                var columnPoints = GetColumnPoints(unitOptions[i], unit, turnData.boardData);
                var squarePoints = GetSquarePoints(unitOptions[i], unit, turnData.boardData);

                if (rowPoints > maxPoints)
                {
                    index         = i;
                    maxPoints     = rowPoints;
                    bestDirection = AttackDirection.row;
                }

                if (columnPoints > maxPoints)
                {
                    index         = i;
                    maxPoints     = columnPoints;
                    bestDirection = AttackDirection.colum;
                }

                if (columnPoints > maxPoints)
                {
                    index         = i;
                    maxPoints     = columnPoints;
                    bestDirection = AttackDirection.square;
                }
            }

            unit.Position = unitOptions[index];
            turnObject.AttackDirection = bestDirection;
        }
 public abstract TurnObject MakeDecision(TurnData turnData, Player player);