Esempio n. 1
0
        public void SetCriticalZone(Vector2i center, int radius2)
        {
            List <Vector2i> circle = Vector2i.GenerateCircle(radius2)
                                     .Select(v => Vector2i.Wrap(v + center, width, height))
                                     .ToList();

            foreach (Vector2i c in circle)
            {
                map[c.x, c.y].isCritical = true;
            }
        }
Esempio n. 2
0
        public void AddEnemy(Vector2i position, int id)
        {
            foreach (StampTile s in stamp)
            {
                Vector2i pos = Vector2i.Wrap(position + s.offset, Width, Height);

                EnemyPresence enemy;
                enemy.enemyId     = id;
                enemy.probability = s.probability;

                map[pos.x, pos.y].enemies.Add(enemy);
            }
        }
Esempio n. 3
0
        private void MoveAnt(Ant ant, IEnumerable <Vector2i> moves)
        {
            Vector2i src = ant.position;

            foreach (Vector2i move in moves)
            {
                Vector2i dst = Vector2i.Wrap(src + move, width, height);

                if (!occupied[dst.x, dst.y])
                {
                    occupied[dst.x, dst.y] = true;
                    ant.direction          = GetDirection(move);
                    ant.hasMoved           = true;
                    return;
                }
            }
        }
Esempio n. 4
0
        public void CalculateVisibility()
        {
            foreach (Ant ant in this.MyAnts)
            {
                foreach (Vector2i offset in Offsets)
                {
                    Vector2i pos = ant.position + offset;
                    pos = Vector2i.Wrap(pos, Width, Height);

                    map[pos.x, pos.y].isVisible = true;

                    if (map[pos.x, pos.y].terrain == Terrain.Unknown)
                    {
                        map[pos.x, pos.y].terrain = Terrain.Land;
                    }
                }
            }
        }
Esempio n. 5
0
        private void BuildGraph(AttackGraph graph, List <Ant> ours, List <Ant> theirs, TacticalMap map)
        {
            for (int i = 0; i < ours.Count; i++)
            {
                Ant myAnt = ours[i];

                //
                //  Get all tiles on tactical map that our ant can navigate on
                //
                IEnumerable <TacticalMap.Tile> tiles =
                    Vector2i.AllDirections
                    .Select(direction => Vector2i.Wrap(myAnt.position + direction, map.Width, map.Height))
                    .Select(p => map[p.x, p.y]);
                //
                //  Identify enemies
                //
                IEnumerable <int> enemies = IdentifyEnemies(tiles);

                foreach (int enemyId in enemies)
                {
                    graph.AddNodeGroup(i, enemyId, BuildLinksAssociatedToEnemy(enemyId, tiles));
                }
            }
        }
Esempio n. 6
0
        public void MoveOffensive(GameState state)
        {
            //
            //  Make a list of enemy ants
            //
            theirs = state.EnemyAnts;

            //
            //  Update tactical map
            //
            map.Reset();
            map.SetLand(state);
            for (int i = 0; i < theirs.Count; i++)
            {
                map.AddEnemy(theirs[i].position, i);
            }


            //
            //  Make a list of offensive friendly ants
            //
            ours.Clear();
            foreach (Ant ant in state.MyAnts)
            {
                bool isInBattle = Vector2i.AllDirections
                                  .Select(d => Vector2i.Wrap(ant.position + d, map.Width, map.Height))
                                  .Select(coord => map[coord.x, coord.y].enemies.Count)
                                  .Where(count => count > 0)
                                  .Any();

                if (isInBattle)
                {
                    ours.Add(ant);
                }
            }


            //
            //  Build a node graph, identifying which ants can attack which ants
            //
            graph.Clear();
            BuildGraph(graph, ours, theirs, map);


            //
            //  Optimize the node graph
            //
            MaximizeEngagement();
            for (int i = 0; i < 2; i++)
            {
                OptimizeOnce();
            }


            //
            //  Move ants in most optimal way
            //
            for (int i = 0; i < ours.Count; i++)
            {
                ours[i].direction = graph.GetDirection(i);
                ours[i].hasMoved  = true;
            }
        }
Esempio n. 7
0
        public override void DoTurn(GameState state)
        {
            try
            {
                Cook(state);

                //Log.Debug(explorationMap.map[59,75].isCritical);


                attackManager.MoveOffensive(state);

                ClearOccupied();

                foreach (Ant ant in state.MyAnts)
                {
                    if (ant.hasMoved)
                    {
                        Vector2i p = ant.position + Vector2i.AllDirections[(int)ant.direction];
                        p = Vector2i.Wrap(p, state.Width, state.Height);
                        occupied[p.x, p.y] = true;
                    }
                }


                foreach (Ant ant in state.MyAnts)
                {
                    if (ant.hasMoved)
                    {
                        continue;
                    }

                    int x = ant.position.x;
                    int y = ant.position.y;


                    if (food.GetDistance(x, y) < DistanceToFood)
                    {
                        MoveAnt(ant, food.GetDescent(x, y));
                    }
                    else if (defense.GetDistance(x, y) < DefenseDistance)
                    {
                        MoveAnt(ant, defense.GetDescent(x, y));
                    }
                    else if (enemy.GetDistance(x, y) < DistanceToNest)
                    {
                        MoveAnt(ant, enemy.GetDescent(x, y));
                    }
                    else
                    {
                        MoveAnt(ant, exploration.GetDescent(x, y));
                    }
                }


                foreach (Ant ant in state.MyAnts)
                {
                    IssueOrder(ant.position, ant.direction);
                }
            }
            catch (Exception e)
            {
                Log.Debug(e.ToString());
            }
        }
Esempio n. 8
0
 public Vector2i Wrap(Vector2i v)
 {
     return(Vector2i.Wrap(v, width, height));
 }