Beispiel #1
0
    public AICityManager(int pDifficulty = 50, int pAnimosity = 0)
    {
        _difficulty = pDifficulty;

        if (pAnimosity == 0)
        {
            pAnimosity = UnityEngine.Random.Range(43, 55);
        }
        _animosity = pAnimosity; //Starting animosity decides wether the AI will focus on digsites, a wonder, or missiles. Will only change to a bridge if affected by player. Chances for each option: 6, 6, 1 = ~(46.25%, 46.25%, 7.5%)
        //If animosity drops below missiles range, change focus to digsites or wonder (whichever is cheapest).
        if (_animosity < 49)
        {
            _initialFocus = AIFocus.Wonder;
            _myFocus      = AIFocus.Wonder;
        }
        else if (_animosity < 54)
        {
            _initialFocus = AIFocus.Digsites;
            _myFocus      = AIFocus.Digsites;
        }
        else if (_animosity < 55)
        {
            _initialFocus = AIFocus.Digsites;
            _myFocus      = AIFocus.Missiles;
            _animosity    = 99;
        }
        Debug.Log(_animosity);
    }
Beispiel #2
0
 public void ChangeAnimosity(int pAnimo, City pCity)
 {
     _animosity = Mathf.Clamp(_animosity + pAnimo, 0, 100);
     Debug.Log("New animosity: " + _animosity);
     if (_animosity <= 0 && pCity.GetBridgesBuilt() < Glob.AmountOfBridgesNeededToWin)
     {
         _myFocus = AIFocus.Bridge;
     }
     else if (_animosity < 56)
     {
         _myFocus = _initialFocus;
     }
     else if (_animosity < 100)
     {
         _myFocus = AIFocus.Missiles;
     }
 }
Beispiel #3
0
    private Move getMove(City pCity, int optimalChance = 65, int subOptimalDiff = 1)
    {
        CustomTile[,] grid = pCity.GetTileMap();
        Move optimalMove    = new Move(grid[0, 0], _buildings[0], -50);
        Move subOptimalMove = new Move(grid[0, 0], _buildings[0], -50);
        Move currentMove    = new Move(grid[0, 0], _buildings[0], 0);

        for (int i = 0; i < grid.GetLength(0); i++)
        {
            for (int j = 0; j < grid.GetLength(1); j++)
            {
                if (grid[i, j].GetBuildingOnTile() == null)
                {
                    currentMove._tile  = grid[i, j];             //For every tile on the grid
                    currentMove._value = 0;
                    for (int k = 0; k < Glob.buildingCount; k++) //Place every possible building
                    {
                        if (_buildings[k].GetCost() <= pCity.GetBudget())
                        {
                            currentMove._building = _buildings[k];
                            if (currentMove._building is Bridge && _myFocus == AIFocus.Bridge && pCity.GetBridgesBuilt() < Glob.AmountOfBridgesNeededToWin)
                            {
                                currentMove._value = 100000; //After building part of the bridge, switch focus to initial focus, just in case the player doesn't finish the bridge.
                                _myFocus           = _initialFocus;
                            }
                            else if (currentMove._building is MissileSilo && _myFocus == AIFocus.Missiles)
                            {
                                currentMove._value = 150; //TODO: Balance this value
                            }
                            else if (currentMove._building is Digsite && _myFocus == AIFocus.Digsites)
                            {
                                currentMove._value = -currentMove._building.GetCost() + pCity.GetBudget() / 5;
                                Building[] closeBuildings = pCity.GetBuildingsAroundTile(1, currentMove._tile);
                                for (int l = 0; l < closeBuildings.Length; l++)
                                {
                                    if (closeBuildings[l] is House)
                                    {
                                        currentMove._value += 0.01f;
                                    }
                                    else if (closeBuildings[l] is Digsite)
                                    {
                                        currentMove._value += 0.02f;
                                    }
                                }
                                currentMove._value += pCity.GetRelicAmount() * 5;
                            }
                            else if (_myFocus == AIFocus.Wonder && (currentMove._building is Park || currentMove._building is House || currentMove._building is Wonder))
                            {
                                Building[] closeBuildings = pCity.GetBuildingsAroundTile(1, currentMove._tile);
                                if (currentMove._building is Park)
                                {
                                    currentMove._value = -currentMove._building.GetCost() + pCity.GetBudget() / 10;
                                    foreach (Building building in closeBuildings)
                                    {
                                        if (building is House)
                                        {
                                            currentMove._value += 25;
                                            Building[] closeToHouse = pCity.GetBuildingsAroundTile(1, building.GetBuildingTile());
                                            for (int l = 0; l < closeToHouse.Length; l++)
                                            {
                                                if (closeToHouse[l] is Park)
                                                {
                                                    currentMove._value -= 25;
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                }
                                else if (currentMove._building is House)
                                {
                                    currentMove._value = getMoveValue(currentMove._tile, currentMove._building);
                                    foreach (Building building in closeBuildings)
                                    {
                                        if (building is Park)
                                        {
                                            currentMove._value += 5;
                                            break;
                                        }
                                    }
                                }
                                else if (currentMove._building is Wonder)
                                {
                                    if (pCity.GetHappyHouseAmount() >= Glob.WonderHappyHouseReq)
                                    {
                                        currentMove._value = 100000;
                                    }
                                    else
                                    {
                                        currentMove._value = -50;
                                    }
                                }
                            }
                            else
                            {
                                currentMove._value = getMoveValue(currentMove._tile, currentMove._building);
                            }

                            if (currentMove._value > subOptimalMove._value && currentMove._value < optimalMove._value - subOptimalDiff)
                            {
                                subOptimalMove._tile     = currentMove._tile; //Overwrite the sub-optimal move with the current one.
                                subOptimalMove._building = currentMove._building;
                                subOptimalMove._value    = currentMove._value;
                            }
                            else if (currentMove._value > optimalMove._value) //If the tile/building combination gives a higher value than the previous optimal move.
                            {
                                optimalMove._tile     = currentMove._tile;    //Overwrite the optimal move with the current one.
                                optimalMove._building = currentMove._building;
                                optimalMove._value    = currentMove._value;
                            }
                        }
                    }
                }
            }
        }

        int rnd = UnityEngine.Random.Range(0, 100);

        if (rnd < optimalChance || subOptimalMove._value < 0 || optimalMove._value >= 50000)
        {
            return(optimalMove);
        }
        else
        {
            Debug.Log("SUB-OPTIMAL!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
            return(subOptimalMove);
        }
    }