private bool[,] GetPathMapArray(ref PathMap pathMap, Point currentKeyPoint) { bool[,] mapArray = pathMap.PathMapArray; Point nextKeyPoint; SetEnterPass(pathMap, ref currentKeyPoint, ref mapArray); do { List <Point> nextKeyPoints = GetNextKeyPoints(pathMap, currentKeyPoint); if (IsExitPoint(pathMap)) { SetExit(pathMap, currentKeyPoint, ref nextKeyPoints); } if (IsImpasse(nextKeyPoints)) { currentKeyPoint = GetPreviousKeyPoint(); } else { nextKeyPoint = GetNextKeyPoint(nextKeyPoints); SetPassesToKeyPoint(ref mapArray, pathMap, currentKeyPoint, nextKeyPoint); currentKeyPoint = GetCurrentKeyPoint(nextKeyPoint); } } while (_keyPointsPath.Count > 0); return(mapArray); }
private void SetExit(PathMap pathMap, Point currentKeyPoint, ref List <Point> nextKeyPoints) { nextKeyPoints = new List <Point>(); _exitPoint = GetMapPoint(pathMap.KeyPoints, currentKeyPoint); _isExitExists = true; _keyPointsPath.Pop(); _currentPathLength -= 2; }
private bool IsPassableVector(PathMap pathMap, Point currentKeyPoint, Point passVector) { Point nextKeyPoint = new Point(currentKeyPoint.X + passVector.X, currentKeyPoint.Y + passVector.Y); return (Mathf.Abs(passVector.Y) != Mathf.Abs(passVector.X) && IsInPointsRange(nextKeyPoint, pathMap.KeyPoints) && !IsPassedKeyPoint(pathMap, nextKeyPoint)); }
private bool[,] SetPassesToKeyPoint( ref bool[,] mapArray, PathMap pathMap, Point currentKeyPoint, Point nextKeyPoint ) { SetPass(GetMapPoint(pathMap.KeyPoints, nextKeyPoint), ref mapArray); SetPass(GetNextMapPoint(pathMap.KeyPoints, nextKeyPoint, currentKeyPoint), ref mapArray); return(mapArray); }
private Point[,] GetKeyPoints(PathMap pathMap) { Point[,] keyPoints = pathMap.KeyPoints; for (int row = 1; row < pathMap.PathMapArray.GetLength(0) - 1; row += 2) { for (int col = 1; col < pathMap.PathMapArray.GetLength(1) - 1; col += 2) { keyPoints[(row - 1) / 2, (col - 1) / 2] = new Point(col, row); } } return(keyPoints); }
public PathMap GeneratePathMap(int height, int width, int pathLength) { PathMap pathMap = new PathMap(width, height, pathLength); pathMap.KeyPoints = GetKeyPoints(pathMap); Point enterKeyPoint = GetRandomPoint(pathMap.KeyPoints); pathMap.Enter = GetMapPoint(pathMap.KeyPoints, enterKeyPoint); pathMap.PathMapArray = GetPathMapArray(ref pathMap, enterKeyPoint); pathMap.Exit = _exitPoint; pathMap.isExitExists = _isExitExists; return(pathMap); }
private List <Point> GetNextKeyPoints(PathMap pathMap, Point currentKeyPoint) { List <Point> nextKeyPoints = new List <Point>(); for (int y = -1; y < 2; y++) { for (int x = -1; x < 2; x++) { if (IsPassableVector(pathMap, currentKeyPoint, new Point(x, y))) { nextKeyPoints.Add(new Point(currentKeyPoint.X + x, currentKeyPoint.Y + y)); } } } return(nextKeyPoints); }
private int[,] GanerateMapIds(PathMap pathMap, MapIds mapIds) { int[,] idsMap = new int[pathMap.PathMapArray.GetLength(0), pathMap.PathMapArray.GetLength(1)]; for (int y = 0; y < pathMap.PathMapArray.GetLength(0); y++) { for (int x = 0; x < pathMap.PathMapArray.GetLength(1); x++) { if (pathMap.PathMapArray[y, x] == false) { idsMap[y, x] = mapIds.WallsIds.ElementAt(UnityEngine.Random.Range(0, mapIds.WallsIds.Count() - 1)); } else { idsMap[y, x] = mapIds.PassId; } } } idsMap[pathMap.Enter.Y, pathMap.Enter.X] = mapIds.EnterId; idsMap[pathMap.Exit.Y, pathMap.Exit.X] = mapIds.ExitId; return(idsMap); }
private bool IsExitPoint(PathMap pathMap) { return(_currentPathLength >= pathMap.PathLength && !_isExitExists); }
private void SetEnterPass(PathMap pathMap, ref Point currentKeyPoint, ref bool[,] mapArray) { SetPass(pathMap.KeyPoints[currentKeyPoint.Y, currentKeyPoint.X], ref mapArray); _keyPointsPath.Push(currentKeyPoint); }
private bool IsPassedKeyPoint(PathMap pathMap, Point nextKeyPoint) { Point mapPoint = GetMapPoint(pathMap.KeyPoints, nextKeyPoint); return(pathMap.PathMapArray[mapPoint.Y, mapPoint.X] == true); }