예제 #1
0
        public Vector2Int GetRandomPos(RandomManager randomManager = null)
        {
            randomManager = randomManager ?? Client.instance.randomManager;
            int dx = rightTopX - leftBottomX;
            int dy = rightTopY - leftBottomY;
            int x, y;

            if (dx > 0)
            {
                x = leftBottomX + randomManager.RandomInt(0, Math.Abs(dx) + 1);
            }
            else if (dx < 0)
            {
                x = leftBottomX - randomManager.RandomInt(0, Math.Abs(dx) + 1);
            }
            else
            {
                x = leftBottomX;
            }
            if (dy > 0)
            {
                y = leftBottomY + randomManager.RandomInt(0, Math.Abs(dy) + 1);
            }
            else if (dy < 0)
            {
                y = leftBottomY - randomManager.RandomInt(0, Math.Abs(dy) + 1);
            }
            else
            {
                y = leftBottomY;
            }
            return(new Vector2Int(x, y));
        }
예제 #2
0
파일: StdioUtil.cs 프로젝트: uiopsczc/Test
        /// <summary>
        /// dir目录下创建prefix+yyyyMMddHHmmss+(随机数3位)+suffix文件
        /// </summary>
        /// <param name="dir"></param>
        /// <param name="prefix"></param>
        /// <param name="suffix"></param>
        /// <returns></returns>
        public static FileInfo CreateTimesliceFile(DirectoryInfo dir, string prefix, string suffix,
                                                   RandomManager randomManager = null)
        {
            randomManager = randomManager ?? Client.instance.randomManager;
            int i = 0;

            do
            {
                string dateTime = DateTimeUtil.NowDateTime().ToString(StringConst.String_yyyyMMddHHmmssSSS);
                string rand     = new StringBuilder(randomManager.RandomInt(0, 1000) + "").ToString();
                string stem     = dateTime
                                  + rand.FillHead(3, CharConst.Char_c);
                string fileName = prefix + stem + suffix;

                var file = new FileInfo(dir.SubPath(fileName));
                if (file.Exists)
                {
                    continue;
                }
                file.Create().Close();
                return(file);
            } while (i++ < 10000);

            throw new IOException(dir.FullName + "中无法创建唯一文件");
        }
예제 #3
0
        //获取P点四周为的可以通过的点
        public static Vector2Int?FindAroundFreePoint(AStarMapPath astarMapPath, Vector2Int basePoint,
                                                     List <Vector2Int> exceptPointList, int[] canPassObstacleTypes,
                                                     int[] canPassTerrainTypes, RandomManager randomManager = null)
        {
            randomManager = randomManager ?? Client.instance.randomManager;
            if (!IsInRange(astarMapPath.GetFinalGrids(), basePoint))
            {
                return(null);
            }
            if (CanPass(astarMapPath, basePoint.x, basePoint.y, canPassObstacleTypes, canPassTerrainTypes) &&
                (exceptPointList == null || !exceptPointList.Contains(basePoint)))
            {
                return(basePoint);
            }

            int max = Math.Max(Math.Max(basePoint.x, astarMapPath.Width() - basePoint.x),
                               Math.Max(basePoint.y, astarMapPath.Height() - basePoint.y));

            for (int i = 1; i <= max; i++)
            {
                List <Vector2Int> list = GetAroundFreePointList(astarMapPath, basePoint, i, canPassObstacleTypes,
                                                                canPassTerrainTypes);
                if (exceptPointList != null)
                {
                    list.RemoveElementsOfSub(exceptPointList);
                }
                if (list.Count > 0)
                {
                    return(list[randomManager.RandomInt(0, list.Count)]);
                }
            }

            return(null);
        }
예제 #4
0
파일: StdioUtil.cs 프로젝트: uiopsczc/Test
        /// <summary>
        /// dir目录下创建prefix+yyyyMMddHHmmssSSS(len决定取yyyyMMddHHmmssSSS的多少位)+suffix文件
        /// </summary>
        /// <param name="dir">目录</param>
        /// <param name="prefix">前缀</param>
        /// <param name="suffix">后缀</param>
        /// <param name="length"></param>
        /// <returns></returns>
        private static FileInfo CreateTimelyFile(DirectoryInfo dir, string prefix, string suffix, int length,
                                                 RandomManager randomManager = null)
        {
            randomManager = randomManager ?? Client.instance.randomManager;
            int i = 0;

            do
            {
                string dateTime = DateTimeUtil.NowDateTime().ToString(StringConst.String_yyyyMMddHHmmssSSS);
                string rand     = new StringBuilder(randomManager.RandomInt(0, 1000).ToString()).ToString();
                string stem     = (dateTime + rand.FillHead(3, CharConst.Char_0))
                                  .Substring(0, length);

                DirectoryInfo timelyDirectoryInfo = dir.CreateSubdirectory(stem);
                timelyDirectoryInfo.Create();
                if (timelyDirectoryInfo.Exists)
                {
                    string fileName = prefix + stem + suffix;
                    var    fileInfo = new FileInfo(timelyDirectoryInfo.SubPath(fileName));
                    if (fileInfo.Exists)
                    {
                        continue;
                    }
                    fileInfo.Create().Close();
                    return(fileInfo);
                }

                throw new IOException(string.Format("无法创建目录:", timelyDirectoryInfo.FullName));
            } while (i++ < 10000);

            throw new IOException(string.Format("{0}中无法创建唯一文件", dir.FullName));
        }
예제 #5
0
파일: Scene.cs 프로젝트: uiopsczc/Test
        // 随机获取地图上一点
        public Vector2Int GetRandomPos(int[] canPassObstacleTypes, int[] canPassTerrainTypes,
                                       RandomManager randomManager = null)
        {
            randomManager = randomManager ?? Client.instance.randomManager;
            int width  = GetWidth();
            int height = GetHeight();
            int x      = randomManager.RandomInt(0, width);
            int y      = randomManager.RandomInt(0, height);

            Vector2Int result = new Vector2Int(x, y);

            if (canPassObstacleTypes != null || canPassTerrainTypes != null)
            {
                if (canPassObstacleTypes == null)
                {
                    canPassObstacleTypes = AStarMapPathConst.Air_Can_Pass_Obstacle_Types;
                }
                if (canPassTerrainTypes == null)
                {
                    canPassTerrainTypes = AStarMapPathConst.Air_Can_Pass_Terrain_Types;
                }
                Vector2Int?freePoint = AStarUtil.FindAroundFreePoint(GetMapPath(), result, null, canPassObstacleTypes,
                                                                     canPassTerrainTypes, randomManager);
                if (freePoint != null)
                {
                    result = freePoint.Value;
                }
            }

            return(result);
        }
예제 #6
0
 public Vector2Int?GetRandomMovePoint(Vector2Int basePoint, Vector2Int goalPoint,
                                      int maxRadiusBetweenTargetPointAndGoalPoint, int[] canPassObstacleTypes,
                                      int[] canPassTerrainTypes, RandomManager randomManager = null)
 {
     return(AStarUtil.GetRandomMovePoint(this, basePoint, goalPoint,
                                         maxRadiusBetweenTargetPointAndGoalPoint,
                                         canPassObstacleTypes, canPassTerrainTypes, randomManager));
 }
예제 #7
0
        //获取P点四周为+-out_count的可以通过的点
        public static Vector2Int?FindAroundFreePoint(AStarMapPath astarMapPath, Vector2Int basePoint, int outCount,
                                                     int[] canPassObstacleTypes,
                                                     int[] canPassTerrainTypes, RandomManager randomManager = null)
        {
            randomManager = randomManager ?? Client.instance.randomManager;
            if (!IsInRange(astarMapPath.GetFinalGrids(), basePoint))
            {
                return(null);
            }

            List <Vector2Int> list = GetAroundFreePointList(astarMapPath, basePoint, outCount, canPassObstacleTypes,
                                                            canPassTerrainTypes);

            if (list.Count > 0)
            {
                return(list[randomManager.RandomInt(0, list.Count)]);
            }
            return(null);
        }
예제 #8
0
        /// <summary>
        ///   随机一个total以内的队列(队列里面的元素不会重复)
        /// </summary>
        /// <param name="self"></param>
        /// <param name="isIncludeTotal">是否包括total</param>
        /// <param name="isZeroBase">是否从0开始</param>
        /// <returns></returns>
        public static List <int> Random(this int self, float outCount, bool isUnique, bool isIncludeTotal = false,
                                        bool isZeroBase = true, RandomManager randomManager = null)
        {
            randomManager = randomManager ?? Client.instance.randomManager;
            var result       = new List <int>();
            var toRandomList = new List <int>();            //要被随机的List

            for (var i = isZeroBase ? 0 : 1; i < (isIncludeTotal ? self + 1 : self); i++)
            {
                toRandomList.Add(i);
            }

            for (var i = 0; i < outCount; i++)
            {
                var index = randomManager.RandomInt(0, toRandomList.Count);
                result.Add(isUnique ? toRandomList.RemoveAt2(index) : toRandomList[index]);
            }

            return(result);
        }
예제 #9
0
파일: AStarImpl.cs 프로젝트: uiopsczc/Test
        //返回的是不带offset的point
        public Vector2Int GetRandomCanPassPoint(RandomManager randomManager = null)
        {
            randomManager = randomManager ?? Client.instance.randomManager;
            var canPassPointList = new List <Vector2Int>();

            for (int x = 0; x < astarMapPath.Width(); x++)
            {
                for (int y = 0; y < astarMapPath.Height(); y++)
                {
                    if (CanPass(x, y))
                    {
                        canPassPointList.Add(new Vector2Int(x, y));
                    }
                }
            }

            int randomIndex = randomManager.RandomInt(0, canPassPointList.Count);

            return(canPassPointList[randomIndex]);
        }
예제 #10
0
        public static Vector2Int?GetRandomMovePoint(AStarMapPath astarMapPath, Vector2Int basePoint,
                                                    Vector2Int goalPoint, int maxRadiusBetweenTargetPointAndGoalPoint, int[] canPassObstacleTypes,
                                                    int[] canPassTerrainTypes, RandomManager randomManager = null)
        {
            randomManager = randomManager ?? Client.instance.randomManager;
            int outCount = randomManager.RandomInt(AStarMapPathConst.Random_Move_Distance_Min,
                                                   AStarMapPathConst.Random_Move_Distance_Max + 1);
            List <Vector2Int> list = GetAroundFreePointList(astarMapPath, basePoint, outCount, canPassObstacleTypes,
                                                            canPassTerrainTypes);

            while (list.Count > 0)
            {
                int        removeIndex = randomManager.RandomInt(0, list.Count);
                Vector2Int targetPoint = list[removeIndex];
                list.RemoveAt(removeIndex);
                if (Vector2Int.Distance(goalPoint, targetPoint) <= maxRadiusBetweenTargetPointAndGoalPoint)
                {
                    return(targetPoint);
                }
            }

            return(null);
        }
예제 #11
0
        //获取range范围内的可以通过的格子
        public static Vector2Int?FindRangeFreePoint(AStarMapPath astarMapPath, int x1, int y1, int x2, int y2,
                                                    List <Vector2Int> exceptPointList,
                                                    int[] canPassObstacleTypes, int[] canPassTerrainTypes, RandomManager randomManager = null)
        {
            randomManager = randomManager ?? Client.instance.randomManager;
            List <Vector2Int> list = GetRangeFreePointList(astarMapPath, x1, y1, x2, y2, exceptPointList,
                                                           canPassObstacleTypes, canPassTerrainTypes);

            if (exceptPointList != null)
            {
                list.RemoveElementsOfSub(exceptPointList);
            }

            if (list.Count > 0)
            {
                return(list[randomManager.RandomInt(0, list.Count)]);
            }
            return(null);
        }
예제 #12
0
 //获取range范围内的可以通过的格子
 public static Vector2Int?FindRangeFreePoint(AStarMapPath astarMapPath, int x1, int y1, int x2, int y2,
                                             int[] canPassObstacleTypes, int[] canPassTerrainTypes, RandomManager randomManager = null)
 {
     return(FindRangeFreePoint(astarMapPath, x1, y1, x2, y2, null,
                               canPassObstacleTypes, canPassTerrainTypes, randomManager));
 }
예제 #13
0
 //获取range范围内的可以通过的格子
 public Vector2Int?FindRangeFreePoint(int x1, int y1, int x2, int y2,
                                      List <Vector2Int> exceptPointList,
                                      int[] canPassObstacleTypes, int[] canPassTerrainTypes, RandomManager randomManager = null)
 {
     return(AStarUtil.FindRangeFreePoint(this, x1, y1, x2, y2, exceptPointList, canPassObstacleTypes,
                                         canPassTerrainTypes, randomManager));
 }
예제 #14
0
 //获取P点四周为+-out_count的可以通过的点
 public Vector2Int?FindAroundFreePoint(Vector2Int basePoint, int outCount, int[] canPassObstacleTypes,
                                       int[] canPassTerrainTypes, RandomManager randomManager = null)
 {
     return(AStarUtil.FindAroundFreePoint(this, basePoint, outCount, canPassObstacleTypes,
                                          canPassObstacleTypes, randomManager));
 }
예제 #15
0
 public void SetRandomManager(RandomManager randomManager)
 {
     this._randomManager = randomManager;
 }
예제 #16
0
파일: StdioUtil.cs 프로젝트: uiopsczc/Test
 /// <summary>
 /// dir目录下创建prefix+yyyyMMddHH+suffix文件
 /// </summary>
 /// <param name="dir"></param>
 /// <param name="prefix"></param>
 /// <param name="suffix"></param>
 /// <param name="len"></param>
 /// <returns></returns>
 public static FileInfo CreateHourlyFile(DirectoryInfo dir, string prefix, string suffix,
                                         RandomManager randomManager = null)
 {
     return(CreateTimelyFile(dir, prefix, suffix, 10, randomManager));
 }