将地图中一个不能到达的点和可以到达的点连通
作者:互联网
/// <summary>
/// 当地图有死路是改变地图使地图不出现死路
/// </summary>
/// <param name="canPassPoint">地图中可以到达的点集合</param>
/// <param name="cannotPassPoint">地图中不可到达的点集合</param>
/// <param name="map"></param>
private static void ChangeMapWhenImpasse(HashSet<Tuple<Int32, Int32>> canPassPoint, HashSet<Tuple<Int32, Int32>> cannotPassPoint, Dictionary<String, SmallgameExploreTypeConfig> map)
{
foreach (var point in cannotPassPoint)
{
var mindistance = canPassPoint.Select(item => Math.Pow(point.Item1 - item.Item1, 2) + Math.Pow(point.Item2 - item.Item2, 2)).Min();
var minPoint = canPassPoint.Where(item => Math.Pow(point.Item1 - item.Item1, 2) + Math.Pow(point.Item2 - item.Item2, 2) == mindistance).First();
var startFloor = Math.Min(point.Item1, minPoint.Item1);
var endFloor = Math.Max(point.Item1, minPoint.Item1);
var startNum = Math.Min(point.Item2, minPoint.Item2);
var endNum = Math.Max(point.Item2, minPoint.Item2);
var blankArea = SmallgameExploreTypeConfigBLL.GetItem((int)ExploreType.NotBarrier).Where(item => item.Num == (int)NotBarrierExploreTypeNum.Blank).First();
for (int floor = startFloor; floor <= endFloor; floor++)
{
var key = GetKey(floor, minPoint.Item2);
if (map[key].IsPass == false)
{
map[key] = blankArea;
}
}
for (int num = startNum; num <= endNum; num++)
{
var key = GetKey(point.Item1, num);
if (map[key].IsPass == false)
{
map[key] = blankArea;
}
}
}
}
标签:不能到达,连通,point,Item2,Item1,地图,item,var,Math 来源: https://blog.csdn.net/qq_41592617/article/details/119445596