Esempio n. 1
0
    public static InfluenceMap getInstance()
    {
        if (instance == null)
            instance = new InfluenceMap ();

        return instance;
    }
Esempio n. 2
0
    void Update()
    {
        //InfluenceMap.getInstance ().Show (0);
        if (!isStart)
        {
            return;
        }
        if (path.Count == 0 && Vector3.Distance(this.transform.position, target.transform.position) > 1.0f && tempTarget == Vector3.zero)
        {
            path = InfluenceMap.getInstance().AStarFindPath(this.gameObject.transform.position, target.transform.position, pAStarComputerformula);
            //Debug.Log (path.Count);
        }
        if (InfluenceMap.getInstance().isWall(InfluenceMap.getInstance().getTilefromPosition(new Vector2(tempTarget.x, tempTarget.z))))
        {
            path = InfluenceMap.getInstance().AStarFindPath(this.gameObject.transform.position, target.transform.position, pAStarComputerformula);
        }
        if (tempTarget == Vector3.zero && path != null)
        {
            if (path.Count != 0)
            {
                tempTarget = path.Pop();
            }
        }
        Vector3 v = new Vector3(tempTarget.x - this.transform.position.x, 0, tempTarget.z - this.transform.position.z);

        v.Normalize();
        if (Vector3.Distance(this.transform.position, tempTarget) > 1.0f)
        {
            this.transform.position += (v) * Time.deltaTime * Velocity;
        }
        else
        {
            tempTarget = Vector3.zero;
        }
    }
Esempio n. 3
0
    void CreateMap()
    {
        int width  = (int)(Mathf.Abs(_upperRight.position.x - _bottomLeft.position.x) / _gridSize);
        int height = (int)(Mathf.Abs(_upperRight.position.z - _bottomLeft.position.z) / _gridSize);

        _influenceMap = new InfluenceMap(width, height, _decay, _momentum);
    }
Esempio n. 4
0
    public void Init(InfluenceMapper im)
    {
        IM = im;

        InfluenceMap npcMap = new InfluenceMap(MapType.Npc, IM.Box,
                                               0f, 1f, 1);

        IM.Maps.Add(MapType.Npc, npcMap);
    }
    public void Init(InfluenceMapper im)
    {
        IM = im;

        InfluenceMap navigationMap = new InfluenceMap(MapType.Navigation, IM.Box,
                                                      0f, 1f, 0, LayerMask.GetMask("Default"));

        IM.Maps.Add(MapType.Navigation, navigationMap);
    }
Esempio n. 6
0
    public void Init(InfluenceMapper mp)
    {
        IM = mp;

        InfluenceMap hazardMap = new InfluenceMap(MapType.Hazard, IM.Box,
                                                  0f, 1f, 1);

        mp.Maps.Add(MapType.Hazard, hazardMap);
    }
Esempio n. 7
0
    public void Init(InfluenceMapper im)
    {
        IM = im;

        InfluenceMap roadMap = new InfluenceMap(MapType.Road, IM.Box,
                                                0f, 1f, 0.5f);

        IM.Maps.Add(MapType.Road, roadMap);
    }
Esempio n. 8
0
 /// <summary>
 /// Clears The entire influence map and game objects
 /// </summary>
 private void ClearMap()
 {
     negativeObjects.Clear();
     positiveObjects.Clear();
     gameObjects.Clear();
     blockedMap           = new BlockedInfluenceMap(CreatePixel(), Color.Black);
     positiveInfluenceMap = new InfluenceMap(CreatePixel(), Color.SkyBlue);
     negativeInfluenceMap = new InfluenceMap(CreatePixel(), Color.MonoGameOrange);
     influenceMap         = new FinalInfluenceMap(CreatePixel(), Color.Black);
 }
Esempio n. 9
0
 void Start()
 {
     m_meshPivot     = this.gameObject.transform.GetChild(1);
     m_influenceMap  = GetComponent <InfluenceMap>();
     m_movement      = GetComponent <SeekerMovement>();
     m_fieldOfView   = GetComponent <FieldOfView>();
     m_viewAngle     = m_fieldOfView.m_viewAngle;
     m_lookAround    = 0;
     m_lookRightLeft = 0;
 }
Esempio n. 10
0
 // Correctly handles singleton behavior
 private void Awake()
 {
     if (Instance == null)
     {
         Instance = this;
     }
     else if (Instance != this)
     {
         Destroy(gameObject);
     }
 }
Esempio n. 11
0
    // Start is called before the first frame update
    public void Start()
    {
        tileMap = GameObject.Find("Tilemap").GetComponent <Tilemap>();

        gridCells = new GridCell[size.x, size.y];
        prev      = new Vector2Int[size.x, size.y];

        InitGround();

        influenceMap = new InfluenceMap(size.x, size.y);
    }
Esempio n. 12
0
 private void Awake()
 {
     //Prevents more than one instance existing in the scene
     if (_instance != null && _instance != this)
     {
         Destroy(this.gameObject);
     }
     else
     {
         _instance = this;
     }
 }
Esempio n. 13
0
    public void Initialize(Pathfinder pathfinder, List <Region> regions)
    {
        this.pathfinder = pathfinder;
        this.regions    = regions;
        PopulationMap   = new InfluenceMap(InfluenceType.Population, regions, this, 0.5f, 0.5f);

        CalculateRegionDistances();

        propagationTimer = secondsTillPropagation;

        AddListeners();
    }
    void CreateMap()
    {
        // how many of gridsize is in Mathf.Abs(_upperRight.positon.x - _bottomLeft.position.x)
        int width = (int)(Mathf.Abs(_upperRight.position.x - _bottomLeft.position.x) / _gridSize);
        int height = (int)(Mathf.Abs(_upperRight.position.z - _bottomLeft.position.z) / _gridSize);

        Debug.Log(width + " x " + height);

        _influenceMap = new InfluenceMap(width, height, _decay, _momentum);

        _display.SetGridData(_influenceMap);
        _display.CreateMesh(_bottomLeft.position, _gridSize);
    }
Esempio n. 15
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            positiveInfluenceMap = new InfluenceMap(CreatePixel(), Color.SkyBlue);
            negativeInfluenceMap = new InfluenceMap(CreatePixel(), Color.MonoGameOrange);
            blockedMap           = new BlockedInfluenceMap(CreatePixel(), Color.Violet);
            influenceMap         = new FinalInfluenceMap(CreatePixel(), Color.Black);

            positiveObjects = new List <GameObject>();
            negativeObjects = new List <GameObject>();
            gameObjects     = new List <GameObject>();

            IsMouseVisible = true;
            base.Initialize();
        }
Esempio n. 16
0
    // Start is called before the first frame update
    void Start()
    {
        Debug.Log("argrg");
        _influenceMap = new InfluenceMap(mapRange.x, mapRange.y);
        CSVReader csvreader = GameObject.FindWithTag("MainCamera").GetComponent <CSVReader>();

        animator        = GetComponent <Animator>();
        moveSceneScript = GameObject.FindWithTag("MainCamera").GetComponent <MoveSceneScript>();
        warning         = GameObject.FindWithTag("MainCamera").GetComponent <Warning>();
        playerTransform = GameObject.FindWithTag("Player").GetComponent <Transform>();

        _passableMap     = csvreader.LoadMap(mapRange);
        _initialPosition = EnemyPosition;
        StartCoroutine(StateManage());
    }
Esempio n. 17
0
    void Awake()
    {
        InfluenceMap.getInstance().center     = new Vector2(center.x, center.z);
        InfluenceMap.getInstance().DefaultY   = center.y;
        InfluenceMap.getInstance().height     = height;
        InfluenceMap.getInstance().width      = width;
        InfluenceMap.getInstance().htileCount = h_Tile;
        InfluenceMap.getInstance().wtileCount = w_Tile;
        InfluenceMap.getInstance().mPlane     = mPlane;
        InfluenceMap.getInstance().Init();
        GAPopulation.GlobalInit();
        GAPopulationManager.getInstance().Init();
        Type type = Type.GetType(DemoWorldName);

        aiWorld = (AIWorld)type.Assembly.CreateInstance(DemoWorldName);
        aiWorld.Init();
    }
Esempio n. 18
0
    public static void RunTurn(string gameState_Enc, string gameInfo_Enc)
    {
        LaPulzellaD_Orleans giovannaD_Arco = new LaPulzellaD_Orleans();

        giovannaD_Arco.currGameState = new GameState();
        giovannaD_Arco.currGameState.Decode(gameState_Enc);
        giovannaD_Arco.game = new GameInfo();
        giovannaD_Arco.game.Decode(gameInfo_Enc);

        foreach (var site in giovannaD_Arco.currGameState.sites)
        {
            site.pos = giovannaD_Arco.game.sites[site.siteId].pos;
        }

        InfluenceMap map = new InfluenceMap();

        giovannaD_Arco.think(out map);
    }
Esempio n. 19
0
    private AITurn ComputeTurn()
    {
        float[,] influenceMap = InfluenceMap.GetInfluenceMap(MapInfos, Team.Player);

        InfluenceMapDrawer drawer = GameObject.Find("InfluenceMapDrawer").GetComponent <InfluenceMapDrawer>();

        drawer.influenceMap = influenceMap;

        AITurn turn = new AITurn();

        turn.Actions = new List <AIAction>();

        AIActionMovement movement = new AIActionMovement();

        movement.GetHighestScore(influenceMap, CurrentCell.X, CurrentCell.Z, (int)MapInfos.Size.x, (int)MapInfos.Size.y, AttributesSheet.GetAttribute(AttributeType.MovementPoint));
        turn.Actions.Add(movement);

        /* while (enough AP to use a skill || enough MP to move) {
         *
         *  // if (enough AP to use a skill) {
         *
         *      - Get Available Skills
         *
         *      if (health == low && has a healing skill)
         *          Use healing skill
         *      else {
         *          - Get potential targets in Range
         *          - Get skill cellTarget
         *          - Add potential kills to turn
         *          - Add potential damage to turn
         *      }
         *
         *  } else (Move) {
         *      GetInfluenceMap(Team.Player);
         *      AIActionMovement movement = new AIActionMovement();
         *      if (CurrentHealth > 50%) {
         *          GetHighestScore();
         *      } else
         *          GetLowestScore();
         *      turns.Action.Add(movement);
         *  }
         */
        return(turn);
    }
Esempio n. 20
0
    // Use this for initialization
    void Start()
    {
        //オブジェクトのInstantiate
        enemy = Instantiate(enemy, new Vector3(enemyPos.x, 0, enemyPos.y), Quaternion.identity);
        item  = Instantiate(item, new Vector3(itemPos.x, 0, itemPos.y), Quaternion.identity);

        //mapGeneratorのインスタンス格納、変数、配列の読み込み
        MapooGenerator mapooGenerator = gameObject.GetComponent <MapooGenerator>();

        _passableMap = new GenericMap <bool>(mapooGenerator.passableMap);
        terrains     = mapooGenerator.terrains;
        mapRange     = mapooGenerator.mapRange;

        //結果を格納する行列を初期化
        map = new float[mapRange.x, mapRange.y];

        //影響マップスクリプトのインスタンス生成
        influenceMap = new InfluenceMap(mapRange.x, mapRange.y);
    }
Esempio n. 21
0
//#if RUNLOCAL
    public static InfluenceMap RunTurn()
    {
        LaPulzellaD_Orleans giovannaD_Arco = new LaPulzellaD_Orleans();

        giovannaD_Arco.currGameState = new GameState();
        giovannaD_Arco.currGameState.Decode(GAMESTATE_ENC);
        giovannaD_Arco.game = new GameInfo();
        giovannaD_Arco.game.Decode(GAMEINFO_ENC);

        foreach (var site in giovannaD_Arco.currGameState.sites)
        {
            site.pos = giovannaD_Arco.game.sites[site.siteId].pos;
        }

        InfluenceMap map = new InfluenceMap();

        giovannaD_Arco.think(out map);
        return(map);
    }
Esempio n. 22
0
    public void DrawCircleOnMap(string mapName, int x, int z, int radius, float value)
    {
        InfluenceMap map = GetMapByName(mapName);

        for (int i = radius; i >= 0; i--)
        {
            float angle = 0;
            while (angle < 360)
            {
                float newX = x + i * Mathf.Cos(angle);
                float newZ = z + i * Mathf.Sin(angle);

                if (newX > 0 && newX < _box.ScaleX - 1 && newZ > 0 && newZ < _box.ScaleZ - 1)
                {
                    map.Grid[Mathf.RoundToInt(newX)][Mathf.RoundToInt(newZ)] = value * i;
                }
                angle += 10f;
            }
        }
    }
Esempio n. 23
0
 // Setup
 ///////////////////
 private void RunSetup()
 {
     // Verify the setup
     if (this.player == null)
     {
         player = GameObject.FindWithTag("Player");
     }
     if (this.gameMaster == null)
     {
         gameMaster = GameObject.FindWithTag("GameMaster");
     }
     if (this.threatMap == null)
     {
         threatMap = gameMaster.GetComponent <InfluenceMap>();
     }
     this.playerLocation = player.transform.position;
     openList            = new List <Path>();
     closedList          = new List <Path>();
     return;
 }
Esempio n. 24
0
//#else
    static void Main(string[] args)
    {
        LaPulzellaD_Orleans giovannaD_Arco = new LaPulzellaD_Orleans();

        giovannaD_Arco.ParseInputs_Begin();

        int turn = 0;

        while (true)
        {
            turn++;
            giovannaD_Arco.ParseInputs_Turn();
            if (turn == 1)
            {
                Console.Error.WriteLine("Game Info");
                Console.Error.WriteLine(giovannaD_Arco.game.Encode() + "\n");
            }
            Console.Error.WriteLine(giovannaD_Arco.currGameState.Encode());
            InfluenceMap map  = new InfluenceMap();
            TurnAction   move = giovannaD_Arco.think(out map);
            move.PrintMove();
        }
    }
Esempio n. 25
0
    private void CreateMap()
    {
        _box = new BoundingBox(Vector3.zero, 25, 10, 25);

        InfluenceMap Map = new InfluenceMap("NavMap", _box,
                                            0f, 1f, 0, 0, true);

        _maps.Add(Map);

        InfluenceMap HazardMap = new InfluenceMap("HazardMap", _box,
                                                  0f, 1f, 1, 0, false);

        _maps.Add(HazardMap);


        Vector3    temp  = new Vector3(5.5f, 0, 5.3f);
        Vector2Int temp2 = WorldToGrid(temp);

        //GetMapByName("HazardMap").Grid[temp2.x][temp2.y] = 0.7f;
        //DrawCircleOnMap("HazardMap", 10,10,5f,1f);


        //InfluenceMap finalMap = GetMapByName("NavMap");
        //finalMap.Grid = finalMap.Multiply(GetMapByName("HazardMap").Grid);
        //_drawMaps.Add(finalMap);
        float[][] finalGrid = new float[_box.ScaleX][];

        for (int i = 0; i < _box.ScaleX; i++)
        {
            finalGrid[i] = new float[_box.ScaleZ];
        }

        finalGrid = GetMapByName("NavMap").Multiply(GetMapByName("HazardMap").Grid);
        _drawMaps.Add(finalGrid);
        DrawPos.Add(GetMapByName("NavMap").GridPosition);
    }
Esempio n. 26
0
    private InfluenceMap CreateInfluenceMap()
    {
//        double squareLength = (60 * 0.4);
        double squareLength = INFLUENCEMAP_SQUARELENGTH; //Maximum common divisor between 60, 100, 75, 50 (movement speeds)

        int          mapWidth     = (int)Math.Ceiling(1980 / squareLength);
        int          mapHeight    = (int)Math.Ceiling(1020 / squareLength);
        double       minInfluence = -100;
        double       maxInfluence = 100;
        InfluenceMap map          = new InfluenceMap(mapWidth, mapHeight, minInfluence, maxInfluence, new EuclideanDistanceSqr());

        var enemyUnits = currGameState.units
                         .Where(u => u.owner == Owner.Enemy);

        //Enemy units influence
        foreach (var enemy in enemyUnits)
        {
            Position enemyPos       = enemy.pos;
            double   enemyInfluence = GetEnemyInfluence(enemy);
            map.applyInfluence(enemyPos.x, enemyPos.y, enemyInfluence, GetEnemyInfluenceRadius(enemy), 0, 0);
        }

        return(map);
    }
Esempio n. 27
0
        static void Main(string[] args)
        {
            Console.WriteLine("Test Influence map");
            Stopwatch sw = new Stopwatch();

            sw.Start();
            IInfluenceMap map    = InfluenceMap.Test();
            string        result = map.DebugPrint();

            sw.Stop();
            Console.WriteLine(result);
            Console.WriteLine($"Took {sw.ElapsedMilliseconds / 1000f} seconds\n");

            float[] mapValues = map.GetValuesCopy();
            int     len       = map.width * map.height;

            // find highest and lowest values and normalise
            float min = mapValues.Min();
            float max = mapValues.Max();

            for (int i = 0; i < len; ++i)
            {
                // mapValues[i] = ...?;
            }

            using (Bitmap b = new Bitmap(map.width, map.height))
            {
                using (Graphics g = Graphics.FromImage(b))
                {
                    for (int y = 0; y < map.height; ++y)
                    {
                        for (int x = 0; x < map.width; ++x)
                        {
                            int   i   = GridUtilities.GridPosToIndex(x, y, map.width);
                            float val = mapValues[i];
                            if (val > 1)
                            {
                                val = 1;
                            }
                            if (val < 0)
                            {
                                val = 0;
                            }
                            Color c = new Color();
                            // convert float in min/max range to 0-255
                            // Color.FromArgb(255, 0, 0);
                            byte r = (byte)(255f * val);
                            Console.Write($"{r}, ");
                            Color.FromArgb(255, r, 0, 0);

                            // this doesn't work..? need to use Graphics class.. somehow?
                            b.SetPixel(x, y, c);
                        }
                    }
                    Console.Write($"\n");
                }
                b.Save(@"D:\test\influence_map.png", ImageFormat.Png);
            }
            Console.WriteLine($"Map is {map.width} by {map.height}");
            Console.ReadKey();
        }
Esempio n. 28
0
    // Use this for initialization
    void Start()
    {
        //Giocatore e nemico
        player = factions.BLUE;
        enemy = factions.RED;

        //Assegno il numero di province iniziale al giocatore e all'IA
        numPlayerProvinces = 16;
        numEnemyProvinces = 16;

        //Supporto
        playerSupport = GameObject.Find ("playerSupport").GetComponent<Support> ();
        enemySupport = GameObject.Find ("enemySupport").GetComponent<Support> ();

        //Array di provincie e gruppi unitòà
        provinces = FindObjectsOfType<Province> ();
        provinces = provinces.OrderBy (p => p.ID).ToArray ();
        strengthIndicators = Canvas.FindObjectsOfType<StrengthIndicator> ();
        strengthIndicators = strengthIndicators.OrderBy (i => i.ID).ToArray ();
        units = FindObjectsOfType<Unit> ();
        units = units.OrderBy (u => u.ID).ToArray ();

        //Settaggio indicatori di forza
        foreach (Unit u in units) {
            u.SetupIndicator ();
        }

        debugInfluenceMap = GameObject.FindGameObjectsWithTag("InfluenceDebug");

        //Box di selezione unità alleata e target attacco
        selectBox = GameObject.Instantiate((GameObject)Resources.Load("Prefabs/SelectBox"));

        targetBox = GameObject.Instantiate((GameObject)Resources.Load("Prefabs/TargetBox"));

        //Indicatore turno corrente
        turnText = Canvas.FindObjectOfType<Text> ();

        //Capitali blu e rossa
        blueCapital = 1;
        redCapital = 30;
        //Creazione grafo della mappa
        mapGraph = new Graph ();

        foreach (Province province in provinces) {

            mapGraph.AddNode (new Node (province.ID));
        }

        foreach (Province province in provinces){

            foreach (Province n in province.getNeighbours()) {
                mapGraph.AddVertex(province.ID,n.ID,1);
            }

        }

        //Inizializzazione IA
        influenceMap = InfluenceMap.getInstance ();

        influenceMap.BuildGraph ();

        strategicPlanner = StrategicPlanner.getInstance();

        turn = player;

        turnCounter = 0;

        //Inizia gioco
        if (turn == player)
            PlayerTurn ();
        else if (turn == enemy)
            EnemyTurn ();
    }
Esempio n. 29
0
 public InfluenceMapAStarPathfinding(NavMeshPathGraph graph, IHeuristic heuristic, InfluenceMap redMap, InfluenceMap greenMap) : base(graph, heuristic)
 {
     this.RedMap   = redMap;
     this.GreenMap = greenMap;
 }
Esempio n. 30
0
    public TurnAction think(out InfluenceMap turnInfluenceMap)
    {
        TurnAction chosenMove = new TurnAction();
        Unit       myQueen    = currGameState.MyQueen;

        turnInfluenceMap = CreateInfluenceMap();

        Site touchedSite = null;

        if (currGameState.touchedSiteId != -1)
        {
            touchedSite = currGameState.sites[currGameState.touchedSiteId];
        }

        IEnumerable <Site> mySites = currGameState.sites.Where(s => s.owner == Owner.Friendly);


        // ReSharper disable once ReplaceWithSingleCallToFirstOrDefault
        Site closestUnbuiltSite = SortSites_ByDistance(myQueen.pos, currGameState.sites)
                                  .Where(s => s.owner == Owner.Neutral &&
                                         currGameState.units.Where(u => u.owner == Owner.Enemy).Count(u => u.DistanceTo(s) < ENEMY_CHECK_RANGE) < TOO_MANY_UNITS_NEARBY)
                                  .FirstOrDefault();

        Site targetMoveSite = closestUnbuiltSite;

        List <Site> closestUnbuiltMines = SortSites_ByDistance(myQueen.pos, currGameState.sites)
                                          .Where(s => s.structureType == StructureType.None && s.owner == Owner.Neutral && IsSiteMinedOut(s.siteId) == false)
                                          .ToList();

        int owned_knight_barrackses = mySites.Count(ob => ob.structureType == StructureType.Barracks && ob.creepsType == UnitType.Knight);
        int owned_archer_barrackses = mySites.Count(ob => ob.structureType == StructureType.Barracks && ob.creepsType == UnitType.Archer);
        int owned_giant_barrackses  = mySites.Count(ob => ob.structureType == StructureType.Barracks && ob.creepsType == UnitType.Giant);
        int owned_mines             = mySites.Count(ob => ob.structureType == StructureType.Mine && ob.gold > 0);
        int owned_towers            = mySites.Count(ob => ob.structureType == StructureType.Tower && ob.owner == Owner.Friendly);

        int total_owner_barrackses = owned_archer_barrackses + owned_giant_barrackses + owned_knight_barrackses;

        bool touchingNeutralSite = touchedSite != null && touchedSite.owner == Owner.Neutral;
        bool touchingMyMine      = touchedSite != null && touchedSite.owner == Owner.Friendly &&
                                   touchedSite.structureType == StructureType.Mine;

        bool touchingMyTower = touchedSite != null && touchedSite.owner == Owner.Friendly &&
                               touchedSite.structureType == StructureType.Tower;

        bool prev_touchingMyMine = touchedSite != null && touchedSite.owner == Owner.Friendly &&
                                   touchedSite.structureType == StructureType.Mine;

        //If we are touching a site, we do something with it
        if (touchingNeutralSite)
        {
            //Build
            var chosenBuildMove = ChoseBuildMove(closestUnbuiltMines, touchedSite, owned_mines, owned_knight_barrackses, owned_archer_barrackses, owned_giant_barrackses, owned_towers, myQueen);
            chosenMove.queenAction = chosenBuildMove;
        }
        else if (touchingMyMine && IsMineMaxed(touchedSite) == false)
        {
            //Empower Mine
            chosenMove.queenAction = new BuildMine(currGameState.touchedSiteId);
        }
        else if (touchingMyTower && touchedSite.param1 <= 700)
        {
            //Emppower Tower
            chosenMove.queenAction = new BuildTower(currGameState.touchedSiteId);
        }

        if (chosenMove.queenAction is Wait)
        {
            if (closestUnbuiltMines.FirstOrDefault() != null && owned_mines < MAX_CONCURRENT_MINES)
            {
                //Go To Next Mine (Tries to filter our the mined out sites.
                chosenMove.queenAction = new Move(GetSiteInfo(closestUnbuiltMines.First()).pos);
            }
            else if (total_owner_barrackses < MAX_BARRACKSES_KNIGHTS + MAX_BARRACKSES_ARCER + MAX_BARRACKSES_GIANT || owned_towers < MAX_TOWERS)
            {
                //Go to next closest site
                chosenMove.queenAction = new Move(GetSiteInfo(closestUnbuiltSite).pos);
                //Run to angle if close to enemies. Running takes priority, so we do the computations last
            }
            else
            {
                if (flag)
                {
                    flag = false;
//                    MAX_CONCURRENT_MINES++;
//                    MAX_BARRACKSES_ARCER++;
                    MAX_BARRACKSES_KNIGHTS++;
//                    MAX_BARRACKSES_KNIGHTS++;
//                    MAX_BARRACKSES_GIANT++;
                    MAX_TOWERS++;
                }
            }
        }

        //Run to angle if close to enemies. Running takes priority, so we do the computations last
//        var enemyUnitsInMyQueenRange =
//            currGameState.units.Count(u => u.owner == Owner.Enemy && myQueen.DistanceTo(u) <= ENEMY_CHECK_RANGE);
//
//        //Run
//        if (enemyUnitsInMyQueenRange >= TOO_MANY_UNITS_NEARBY)
//        {
////            Move moveToAngle = RunToAngle(myQueen);
////            chosenMove.queenAction = RunToClosestTowerOrAngle(myQueen);
//        }

        IEnumerable <Site> myIdleBarracses = mySites
                                             .Where(site => site.structureType == StructureType.Barracks && site.param1 == 0);
        List <Site> barracksesToTrainFrom = new List <Site>();

        if (myIdleBarracses.Any())
        {
            //Train

            DecideUnitsToTrain();

            int remainingGold = currGameState.money;
            foreach (var barraks in myIdleBarracses)
            {
                int cost = 0;
                switch (barraks.creepsType)
                {
                case UnitType.Knight:
                    cost += KNIGHT_COST;
                    break;

                case UnitType.Archer:
                    cost += ARCHER_COST;
                    break;

                case UnitType.Giant:
                    cost += GIANT_COST;
                    break;
                }

                if (remainingGold >= cost)
                {
                    barracksesToTrainFrom.Add(barraks);
                    remainingGold -= cost;
                }
                else
                {
                    break;
                }
            }
            chosenMove.trainAction = new Train(barracksesToTrainFrom);
        }
        else
        {
            //Wait
            chosenMove.trainAction = new HaltTraing();
        }

        return(chosenMove);
    }
Esempio n. 31
0
        // Initialise at first step
        public void Init(IGameState state)
        {
            random = new Random();
            currentTasks = new Dictionary<string, CurrentTask>();
            nextTasks = new Dictionary<string, CurrentTask>();
            myHills = new List<Location>(state.MyHills);
            theirHills = new List<Location>();
            yummies = new List<Location>();
            timRobbins = new List<Location>();
            martinSheen = new List<Location>();
            viewRadius = (int)Math.Sqrt(state.ViewRadius2);
            heatMap = new HeatMap(viewRadius, state);

            influenceMaps = new LayeredInfluenceMap(state);
            influenceMaps["Enemies"] = new InfluenceMap(state, 4, 1);
            influenceMaps["Friends"] = new InfluenceMap(state, 1, 1);

            foreach (Location h in myHills)
            {
                heatMap.UpdateCell(h, -5f);

                Location tim;
                tim = h + new Location(-1, -1);
                if (state.GetIsPassable(tim))
                    timRobbins.Add(tim);

                tim = h + new Location(-1, 1);
                if (state.GetIsPassable(tim))
                    timRobbins.Add(tim);

                tim = h + new Location(1, -1);
                if (state.GetIsPassable(tim))
                    timRobbins.Add(tim);

                tim = h + new Location(1, 1);
                if (state.GetIsPassable(tim))
                    timRobbins.Add(tim);
            }
        }
Esempio n. 32
0
 void Start()
 {
     m_influenceMap = GetComponent <InfluenceMap>();
     m_mapSize      = m_influenceMap.GetSize();
     m_movement     = gameObject.GetComponent <SeekerMovement>();
 }