Esempio n. 1
0
        // Triangulate the polygon.
        //
        // For a nice, detailed explanation of this method,
        // see Ian Garton's Web page:
        // http://www-cgrl.cs.mcgill.ca/~godfried/teaching/cg-projects/97/Ian/cutting_ears.html
        public List<Triangle> Triangulate()
        {
            // Copy the points into a scratch array.
            Position[] pts = new Position[Points.Length];
            Array.Copy(Points, pts, Points.Length);

            // Make a scratch polygon.
            Polygon pgon = new Polygon(pts);

            // Orient the polygon clockwise.
            pgon.OrientPolygonClockwise();

            // Make room for the triangles.
            List<Triangle> triangles = new List<Triangle>();

            // While the copy of the polygon has more than
            // three points, remove an ear.
            while (pgon.Points.Length > 3)
            {
                // Remove an ear from the polygon.
                pgon.RemoveEar(triangles);
            }

            // Copy the last three points into their own triangle.
            triangles.Add(new Triangle(pgon.Points[0], pgon.Points[1], pgon.Points[2]));

            return triangles;
        }
Esempio n. 2
0
        /// <summary>
        /// Calculates the magnitude of the specified position on the map relative to the centroid of the squad 
        /// (being close to the other units in the squad will give the best magnitude/attraction).
        /// </summary>
        /// <param name="squad"></param>
        /// <param name="possibleNextPosition"></param>
        /// <param name="force"></param>
        /// <param name="forceStep"></param>
        /// <param name="rangePercentage">How big the Range to the centroid of all the Units positions in the Squad/Group</param>
        /// <returns>The magnitude of squad attraction. 0 if a unit is inside the specified range and gives a negative linear drop-off the further away the unit is from the group.</returns>
        public double PFSquadAttraction(List<UnitAgent> squad, Position possibleNextPosition, double force, double forceStep, int rangePercentage)
        {
            var unitPositions = new Position[squad.Count];

            if (SWIG.BWAPI.bwapi.Broodwar.self().getUnits() != null && SWIG.BWAPI.bwapi.Broodwar.self().getUnits().Count > 0)
            {
                int i = 0;
                foreach (UnitAgent meleeUnitAgent in squad)
                {
                    unitPositions[i] = meleeUnitAgent.MyUnit.Position;
                    i++;
                }

                var meleeUnitPolygon = new Polygon(unitPositions);
                double distance = possibleNextPosition.GetDistance(meleeUnitPolygon.FindCentroid());
                return distance <= MyMath.GetPercentageOfMaxDistancePixels(rangePercentage)
                           ? force//0
                           : force - forceStep * distance;
            }
            Logger.Logger.AddAndPrint("Enemy unit list is null or has zero elements in CalculatePFValueForCollisionWithEnemyUnits");
            return 0;
        }