当前位置: 首页>>代码示例>>C#>>正文


C# Position.GetDistance方法代码示例

本文整理汇总了C#中Position.GetDistance方法的典型用法代码示例。如果您正苦于以下问题:C# Position.GetDistance方法的具体用法?C# Position.GetDistance怎么用?C# Position.GetDistance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Position的用法示例。


在下文中一共展示了Position.GetDistance方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PFSquadAttraction

        /// <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;
        }
开发者ID:albertouri,项目名称:emapf-starcraft-ai,代码行数:32,代码来源:UnitAgent.cs

示例2: PFMapCenterAttraction

 /// <summary>
 /// Calculates the magnitude of the specified field relative to the center of the map.
 /// </summary>
 /// <param name="field"></param>
 /// <param name="force"></param>
 /// <param name="forceStep"></param>
 /// <param name="rangePercentage"></param>
 /// <returns></returns>
 public double PFMapCenterAttraction(Position field, double force, double forceStep, int rangePercentage)
 {
     double distance = field.GetDistance(MyMath.GetMapCenterPosition());
     return distance <= MyMath.GetPercentageOfMaxDistancePixels(rangePercentage)
                 ? force//0
                 : force - forceStep * distance;
 }
开发者ID:albertouri,项目名称:emapf-starcraft-ai,代码行数:15,代码来源:UnitAgent.cs

示例3: CalculateMapEdgeRepulsion

		/// <summary>
		/// Calculates the repulsion factor/magnitude of the specified field relative to the edges of the map.
		/// </summary>
		/// <param name="field"></param>
		/// <param name="force"></param>545455555555555555555555555555555111111111
		/// <param name="forceStep"></param>
		/// <param name="range">How close units are allowed to get to the edge of the map, before they are repulsed</param>
		/// <returns></returns>
		public static double CalculateMapEdgeRepulsion(Position field, double force, double forceStep, int range)
		{
			double magnitude = 0;
			if (field.X <= range) //Distance to wall left.
				magnitude += -(force - forceStep * field.GetDistance(new Position(0, field.Y)));

			if (field.Y <= range) //Distance to wall top.
				magnitude += -(force - forceStep * field.GetDistance(new Position(field.X, 0)));

			if (field.X >= Game.MapWidthTiles * tileSize - range) //Distance to wall right.
				magnitude += -(force - forceStep * field.GetDistance(new Position(Game.MapWidthTiles * tileSize, field.Y)));

			if (field.Y >= Game.MapHeightTiles * tileSize - range) //Distance to wall bottom.
				magnitude += -(force - forceStep * field.GetDistance(new Position(field.X, Game.MapHeightTiles * tileSize)));

			return magnitude < 0 ? magnitude : 0;
		}
开发者ID:albertouri,项目名称:emapf-starcraft-ai,代码行数:25,代码来源:MyMath.cs


注:本文中的Position.GetDistance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。