Ejemplo n.º 1
0
        private void expandQueue(Queue <Point2D> queue, Point2D point, ImageData map, int[,] distances, int newVal)
        {
            int            x            = (int)point.X;
            int            y            = (int)point.Y;
            List <Point2D> nearbyPoints = new List <Point2D>();

            nearbyPoints.Add(new Point2D {
                X = x + 1, Y = y
            });
            nearbyPoints.Add(new Point2D {
                X = x - 1, Y = y
            });
            nearbyPoints.Add(new Point2D {
                X = x, Y = y + 1
            });
            nearbyPoints.Add(new Point2D {
                X = x, Y = y - 1
            });

            foreach (Point2D p in nearbyPoints)
            {
                if (p.X < 0 || p.X > map.Size.X - 1 || p.Y < 0 || p.Y > map.Size.Y - 1)
                {
                    continue;
                }
                if (Sc2Util.ReadTile(map, (int)p.X, map.Size.Y - (int)p.Y - 1) && distances[(int)p.X, (int)p.Y] == 100000000)
                {
                    queue.Enqueue(p);
                    distances[(int)p.X, (int)p.Y] = newVal;
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get a location to place a creep tumor
        /// </summary>
        /// <param name="startPoint">the location of the queen or tumor that spreads the creep. MUST BE A PATHABLE TILE</param>
        /// <param name="towards">the direction of the desired creepspread</param>
        /// <param name="range">how far from the startpoint it can spread to.</param>
        /// <returns>a location that is valid for a tumor to be placed. Null if none can be found</returns>
        public static Point2D GetTumorLocation(Point2D startPoint, Point2D towards, int range)
        {
            int[,] distances;
            if (towards == VBot.Bot.Map.EnemyStartLocations[0])
            {
                distances = VBot.Bot.Map.DistancesToEnemy;
            }
            else
            {
                distances = VBot.Bot.Map.GenerateDistances(towards);
            }

            Point2D closestPoint = null;
            int     minDist      = 100000000;

            List <Point> tumorLocations = GetAgents(Units.AllCreep).Select(a => a.Unit.Pos).ToList();

            for (int i = -range; i <= range; i++)
            {
                for (int j = -range; j < range + 1; j++)
                {
                    // check if it is creep
                    var     creepMap = VBot.Bot.Observation.Observation.RawData.MapState.Creep;
                    Point2D testLoc  = new Point2D {
                        X = startPoint.X + i, Y = startPoint.Y + j
                    };
                    if (!Sc2Util.ReadTile(creepMap, testLoc))
                    {
                        continue;
                    }

                    if (distances[(int)testLoc.X, (int)testLoc.Y] < minDist && !IsInRange(testLoc, tumorLocations, 5))
                    {
                        minDist      = distances[(int)testLoc.X, (int)testLoc.Y];
                        closestPoint = testLoc;
                    }
                }
            }
            if (closestPoint == null)
            {
                return(null);
            }
            return(closestPoint);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// checks if the bot has vision of a tile on the map.
 /// </summary>
 /// <param name="loc">A Point2D that you want to check the vision of</param>
 /// <returns>true if the bot actively has vision of the location, false otherwise</returns>
 public static bool HasVision(Point2D loc)
 {
     return(Sc2Util.ReadTile(VBot.Bot.Observation.Observation.RawData.MapState.Visibility, loc));
 }