// Base constructor public RoadGenerator(Vector2 origin, Vector2 destination, float maxSlope, float bridgePenalty) { // Obtain all extra needed information this.resolution = TerrainChunk.resolution; this.mapSize = TerrainCharacteristicsManager.Instance.mapSize; this.terrainAreas = TerrainCharacteristicsManager.Instance.getTerrainAreasDeepCopy(); object map = TerrainCharacteristicsManager.Instance.getChunkMap (new Vector2 (-1, -1)); if (map is Color[][]) this.map = (Color[][])map; else if (map is Color) // Optimized if only one color this.optimizedTerrainArea = terrainAreas[(Color)map]; this.waterBodies = UpperLayersManager.Instance.getWaterBodiesProcessedLayer (); this.maxSlope = maxSlope; this.bridgePenalty = bridgePenalty; origin = new Vector2 (Mathf.Round (origin.x * resolution), Mathf.Round (origin.y * resolution)); destination = new Vector2 (Mathf.Round (destination.x * resolution), Mathf.Round (destination.y * resolution)); openList = new SortedList<float, List<Vector2>> (); openNodes = new Dictionary<Vector2, ANode> (); float originY = getHeightValue (origin); Vector3 origin3 = new Vector3 (origin.x, Mathf.Abs(originY), origin.y); this.destination = new Vector3 (destination.x, Mathf.Abs(getHeightValue (destination)), destination.y); closedNodes = new Dictionary<Vector2, ANode> (); if (isInsideMapBoundaries(origin)) { ANode originNode = new ANode (origin3, originY < 0, this.destination, null, bridgePenalty); openList [Vector3.Distance (origin3, destination)] = new List<Vector2> () { origin }; openNodes [origin] = originNode; } }
public ANode(GraphNode <V> n, ANode <V> c, int g, int h) { this.node = n; this.cameFrom = c; this.gCost = g; this.hCost = h; }
public static bool TryReadStrings(ANode node, ref string[] variable, params string[] names) { foreach (string s in names) { ANode n = node[s]; if (n == null) { continue; } if (n is Array) { variable = n.AsArray.Children.Select(x => x.Value).ToArray(); } else if (n is Data) { variable = new[] { n.Value }; } else { Debug.LogError("Dev.JSON.TryReadStrings: Error at \"" + s + "\": Array or Data expected!"); continue; } return(true); } return(false); }
public static void CalGValue(this ANode node, ANode startNode, int offset = 1, int unitPrice = 1) { int xDistance = Mathf.Abs(node.x - startNode.x) / offset; int yDistance = Mathf.Abs(node.y - startNode.y) / offset; node.G = (xDistance + yDistance) * unitPrice; }
private void ShowContextMenu(ANode node) { if (_tree == null || !_tree.Nodes.Contains(node)) { return; } GenericMenu menu = new GenericMenu(); if (node is AFlowNode) { if (node != _tree.Root) { menu.AddItem(new GUIContent("Make Root"), false, RootCallback, node); } else { menu.AddDisabledItem(new GUIContent("Make Root")); } menu.AddItem(new GUIContent("Connect"), false, ConnectCallback, node); } else { menu.AddDisabledItem(new GUIContent("Make Root")); menu.AddDisabledItem(new GUIContent("Connect")); } menu.AddSeparator(""); menu.AddItem(new GUIContent("Delete"), false, DeleteCallback, node); menu.ShowAsContext(); }
/// 最小スコアのノードを取得する. public ANode SearchMinScoreNodeFromOpenList() { // 最小スコア int min = 9999; // 最小実コスト int minCost = 9999; ANode minNode = null; foreach (ANode node in _openList) { int score = node.GetScore(); if (score > min) { // スコアが大きい continue; } if (score == min && node.Cost >= minCost) { // スコアが同じときは実コストも比較する continue; } // 最小値更新. min = score; minCost = node.Cost; minNode = node; } return(minNode); }
public static bool TryReadClassesChildren(ANode suposedClass, Dictionary <string, ANode> destination, IEnumerable <string> exceptions = null) { Class nodeC = suposedClass as Class; if (nodeC == null) { Debug.LogError("Dev.JSON.GetClassesChildrenExcept: Argument is not a class!"); return(false); } bool res = false; for (int i = 0; i < nodeC.Count; ++i) { string name = nodeC.GetChildNameAt(i); if (exceptions == null || !exceptions.Contains(name)) { res = true; if (destination.ContainsKey(name)) { destination[name] = nodeC.GetChildAt(i); } else { destination.Add(name, nodeC.GetChildAt(i)); } } } return(res); }
public override ANode Add(string aKey, ANode aItem, bool allowNulls = true) { if (aItem == null) { if (allowNulls) { aItem = new Data("null"); } else { Debug.LogError("Dev.JSON.ANode.Add: Nulls are not allowed as values! Key: " + aKey); return(this); } } if (!string.IsNullOrEmpty(aKey)) { if (_dict.ContainsKey(aKey)) { _dict[aKey] = aItem; } else { _dict.Add(aKey, aItem); } } else { _dict.Add(Guid.NewGuid().ToString(), aItem); } return(this); }
public static AnimationEvent ReadAnimationEvent(JSON.ANode node) { AnimationEvent e = new AnimationEvent { time = node["time"].AsFloat, functionName = node.GetOneOf("functionName").Value }; ANode sPar = node.GetOneOf("stringParameter", "stringParam"); if (sPar != null) { e.stringParameter = sPar.Value; } ANode fPar = node.GetOneOf("floatParameter", "floatParam"); if (fPar != null) { e.floatParameter = fPar.AsFloat; } ANode iPar = node.GetOneOf("intParameter", "intParam"); if (iPar != null) { e.intParameter = iPar.AsInt; } return(e); }
int GetCost(ANode a, ANode b) { int x = Mathf.Abs(a.GetGridX - b.GetGridX); int y = Mathf.Abs(a.GetGridY - b.GetGridY); return(x > y ? m_diagonalCost * y + m_straightCost * (x - y) : m_diagonalCost *x + m_straightCost *(y - x)); }
/// 指定の座標にあるノードをオープンする. public ANode OpenNode(int x, int y, int cost, ANode parent, int[,] map) { // 座標をチェック. if (x < 0 || map.GetLength(0) <= x || y < 0 || map.GetLength(1) <= y) { // 領域外. return(null); } if (map[x, y] == 1) { // 通過できない. return(null); } if (map[x, y] == 2) { // 通過できない. return(null); } // ノードを取得する. var node = GetNode(x, y, map); if (node.IsNone() == false) { // 既にOpenしているので何もしない return(null); } // Openする. node.Open(parent, cost); AddOpenList(node); return(node); }
void CreateGrid() { grid = new ANode[gridSizeX, gridSizeY]; Vector3 worldBottomLeft = transform.position - Vector3.right * gridWorldSize.x / 2 - Vector3.forward * gridWorldSize.y / 2; for (int x = 0; x < gridSizeX; x++) { for (int y = 0; y < gridSizeY; y++) { Vector3 worldPoint = worldBottomLeft + Vector3.right * (x * nodeDiameter + nodeRaidus) + Vector3.forward * (y * nodeDiameter + nodeRaidus); bool walkable = !(Physics.CheckSphere(worldPoint, nodeRaidus, unwalkableMask)); int movementPenalty = 0; Ray ray = new Ray(worldPoint + Vector3.up * 50, Vector3.down); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100, walkableMask)) { walkableRegionsDictionary.TryGetValue(hit.collider.gameObject.layer, out movementPenalty); } if (!walkable) { movementPenalty += obstacleProximityPenalty; } grid[x, y] = new ANode(walkable, worldPoint, x, y, movementPenalty); } } BlurPenaltyMap(3); }
/// ステータスをOpenにする. public void Open(ANode parent, int cost) { //Debug.Log (string.Format("Open: ({0},{1})", X, Y)); _status = eStatus.Open; _cost = cost; _parent = parent; }
public List <ANode> GetNeighbours(ANode node) { List <ANode> neighbours = new List <ANode>(); for (int x = -1; x <= 1; x++) { for (int y = -1; y <= 1; y++) { if (x == 0 && y == 0) { continue; } int checkX = node.gridX + x; int checkY = node.gridY + y; if (checkX >= 0 && checkX < gridSizeX && checkY >= 0 && checkY < gridSizeY) { neighbours.Add(grid[checkX, checkY]); } } } return(neighbours); }
int GetManhattanDistance(ANode a_nodeA, ANode a_nodeB) { int ix = Mathf.Abs(a_nodeA.iAGridX - a_nodeB.iAGridX); //x1-x2 int iy = Mathf.Abs(a_nodeA.iAGridY - a_nodeB.iAGridY); //y1-y2 return(ix + iy); //Return the sum }
private static void AddElement(ANode ctx, string token, string tokenName, bool tokenIsString) { if (tokenIsString) { if (token == "@#$%EMPTYSTRING") { token = ""; } if (ctx is Array) { ctx.Add(new Data(token)); } else { ctx.Add(tokenName, new Data(token)); // assume dictionary/object } } else { Data number = Numberize(token, tokenName); if (ctx is Array) { ctx.Add(number); } else { ctx.Add(tokenName, number); } } }
private List <ANode> GetNeighbours(ANode node) { List <ANode> neighbours = new List <ANode>(); Vector2Int checkPosition = new Vector2Int(node.x, node.y - 1); if (_map.IsPositionViable(checkPosition)) { neighbours.Add(grid[checkPosition.x, checkPosition.y]); } checkPosition.x = node.x; checkPosition.y = node.y + 1; if (_map.IsPositionViable(checkPosition)) { neighbours.Add(grid[checkPosition.x, checkPosition.y]); } checkPosition.x = node.x - 1; checkPosition.y = node.y; if (_map.IsPositionViable(checkPosition)) { neighbours.Add(grid[checkPosition.x, checkPosition.y]); } checkPosition.x = node.x + 1; checkPosition.y = node.y; if (_map.IsPositionViable(checkPosition)) { neighbours.Add(grid[checkPosition.x, checkPosition.y]); } return(neighbours); }
public override Solution <TMove> Solve(AGame <TMove> game, ANode <TMove> finalState) { Solution <TMove> r = null; int count = this.GetStepCount(game); for (int k = 0; k < count; k++) { var partFinalState = this.BuildSolutionStep(game, finalState, k + 1); base.FilterNode = this.BuildFilterNode(game, finalState, k + 1, partFinalState); Solution <TMove> partial = base.Solve(game, partFinalState); System.Diagnostics.Debug.WriteLine($"Finished step {k + 1} of {count}"); if (partial.Last != null) { game.State = partial.Last; } else { System.Diagnostics.Debug.WriteLine("Could not reach exact solution, is puzzle feasible?"); return(r); } r += partial; } return(r); }
protected virtual void OnSelectedNode(ANode node) { if (_HeroCharacter != null) { _HeroCharacter.MoveToNode(node); } }
public static void CalHValue(this ANode node, ANode targetNode, int offset = 1, int unitPrice = 1) { int xDistance = Mathf.Abs(targetNode.x - node.x) / offset; int yDistance = Mathf.Abs(targetNode.y - node.y) / offset; node.H = (xDistance + yDistance) * unitPrice; }
public ANode <Location> Dequeue() { ANode <Location> node = this.queue.First(); this.queue.Remove(node); return(node); }
/// 最小スコアのノードを取得する. public ANode SearchMinScoreNodeFromCloseList(Vector2Int goalPos) { // 最小スコア int min = 9999; // 最小実コスト int minCost = 9999; ANode minNode = null; foreach (ANode node in _closeList) { //Debug.Log (string.Format("({0},{1}) cost={2} score={3}", node.X, node.Y, node.Cost, node.GetScore())); int score = node.CalcHeuristic(false, goalPos); if (score > min) { // スコアが大きい continue; } if (score == min && node.Cost >= minCost) { // スコアが同じときは実コストも比較する continue; } // 最小値更新. min = score; minCost = node.Cost; minNode = node; } return(minNode); }
public void InsertNewNodeInOpenList(ANode <TMove> newNode) { // Insertion pour respecter l'ordre du cout total le plus petit au plus grand if (this.graph.Opened.Count == 0) { this.graph.Opened.Add(newNode); } else { var N = this.graph.Opened[0]; bool trouve = false; int i = 0; do { if (newNode.TotalCost < N.TotalCost) { this.graph.Opened.Insert(i, newNode); trouve = true; } else { i++; if (this.graph.Opened.Count == i) { N = null; this.graph.Opened.Insert(i, newNode); } else { N = this.graph.Opened[i]; } } } while ((N != null) && (trouve == false)); } }
/// 周りをOpenする. public void OpenAround(ANode parent) { var xbase = parent.X; // 基準座標(X). var ybase = parent.Y; // 基準座標(Y). var cost = parent.Cost; // コスト. cost += 1; // 一歩進むので+1する. if (_allowdiag) { // 8方向を開く. for (int j = 0; j < 3; j++) { for (int i = 0; i < 3; i++) { var x = xbase + i - 1; // -1~1 var y = ybase + j - 1; // -1~1 OpenNode(x, y, cost, parent); } } } else { // 4方向を開く. var x = xbase; var y = ybase; OpenNode(x - 1, y, cost, parent); // 右. OpenNode(x, y - 1, cost, parent); // 上. OpenNode(x + 1, y, cost, parent); // 左. OpenNode(x, y + 1, cost, parent); // 下. } }
/// 指定の座標にあるノードをオープンする. public ANode OpenNode(int x, int y, int cost, ANode parent) { // 座標をチェック. if (_layer.IsOutOfRange(x, y)) { // 領域外. return(null); } if (_layer.Get(x, y) > 1) { // 通過できない. return(null); } // ノードを取得する. var node = GetNode(x, y); if (node.IsNone() == false) { // 既にOpenしているので何もしない return(null); } // Openする. node.Open(parent, cost); AddOpenList(node); return(node); }
public NodeDrawer(ANode node, bool isRoot = false) { _id = gNodeDrawerIdIncremental++; _node = node; _isRoot = isRoot; _rect = new Rect(0f, 0f, gSize.x, gSize.y); _currentIcon = _defaultIconPath; }
public void Initialize(params char[] values) { Root = null; foreach (var value in values) { Insert(value); } }
public static void CalFValue(this ANode node) { if (node.G == 0 && node.H == 0) { return; } node.F = node.G + node.H; }
// Base constructor public ANode(Vector3 point, bool inWaterBody, Vector3 destination, ANode preceding, float bridgePenalty) { this.point = point; this.inWaterBody = inWaterBody; this.destination = destination; this.preceding = preceding; this.bridgePenalty = bridgePenalty; }
public ANode(Vector2 vector, float costFromStart, float costToGoal, ANode parent) { this.vector = vector; this.costFromStart = costFromStart; this.costToGoal = costToGoal; TotalCost = costToGoal + costFromStart; this.parent = parent; }
// 노드를 기반으로 선형연결리스트처럼 노드를 이어줌 public IEnumerator SearchPath(Vector3 startPos, Vector3 endPos) { yield return(null); bool isSuccess = false; m_startNode = m_buildGrid.GetNode(startPos); m_endNode = m_buildGrid.GetNode(endPos); if (m_startNode.IsWalkable && m_endNode.IsWalkable) { List <ANode> openNode = new List <ANode>(); HashSet <ANode> closeNode = new HashSet <ANode>(); openNode.Add(m_startNode); while (openNode.Count > 0) { ANode current = openNode[0]; for (int i = 1; i < openNode.Count; ++i) { if (openNode[i].GetFCost < current.GetFCost || openNode[i].GetFCost == current.GetFCost && openNode[i].HCost < current.HCost) { current = openNode[i]; } } openNode.Remove(current); closeNode.Add(current); if (current == m_endNode) { isSuccess = true; break; } foreach (ANode node in m_buildGrid.GetNeighbourNode(current)) { if (!node.IsWalkable || closeNode.Contains(node)) { continue; } int currentNeighbourCost = current.GCost + GetCost(node, m_endNode); if (currentNeighbourCost < node.GCost || !openNode.Contains(node)) { node.GCost = currentNeighbourCost; node.HCost = GetCost(node, m_endNode); node.PrevNode = current; if (!openNode.Contains(node)) { openNode.Add(node); } } } } } AStarMng.Instance.CompleteProcess(isSuccess ? GetPath(startPos, endPos) : null); }
public bool FindPath(Cell start, Cell target) { ANode startNode = grid[start.GetPosition().x, start.GetPosition().y]; ANode targetNode = grid[target.GetPosition().x, target.GetPosition().y]; List <ANode> openSet = new List <ANode>(); List <ANode> closedSet = new List <ANode>(); openSet.Add(startNode); while (openSet.Count > 0) { ANode currentNode = openSet[0]; for (int i = 1; i < openSet.Count; i++) { if ((openSet[i].fCost() < currentNode.fCost() || openSet[i].fCost() == currentNode.fCost()) && openSet[i].hCost < currentNode.hCost) { currentNode = openSet[i]; } } openSet.Remove(currentNode); closedSet.Add(currentNode); visited.Add(currentNode); if (currentNode == targetNode) { path = RetracePath(startNode, targetNode); return(true); } foreach (ANode neighbour in GetNeighbours(currentNode)) { if (!(neighbour.walkable) || closedSet.Contains(neighbour)) { continue; } int newMovementCostToNeighbour = currentNode.gCost + GetDistance(currentNode, neighbour); if (newMovementCostToNeighbour < neighbour.gCost || !openSet.Contains(neighbour)) { neighbour.gCost = newMovementCostToNeighbour; neighbour.hCost = GetDistance(neighbour, targetNode); neighbour.parent = currentNode; if (!openSet.Contains(neighbour)) { openSet.Add(neighbour); } } } } return(false); }
private AGrid() { mGrid = new ANode[82, 82]; for (int i = 0; i < 82; i++) { for (int j = 0; j < 82; j++) { mGrid[i, j] = new ANode(new Vector2(i, j)); } } }
protected TreeNode(ANode aNode, int kind, Database database) : base(aNode, kind, database) { }
//Should only be called from Node.Get() internal ProcessingInstruction(ANode aNode, Database database) : base(aNode, Data.PI, database) { }
private void DebugResult(ANode node, bool result) { foreach(NodeDrawer drawer in _nodeDrawers) { if(drawer.Node == node) { drawer.SetDebugInfo(result); return; } } }
private void NodeLeftClicked(ANode node) { if (_tree == null || !_tree.Nodes.Contains(node)) { return; } Selection.activeObject = node; if(_startConnection != null) { if(_startConnection != node && _tree.ConnectNodes(_startConnection, node)) { AssetDatabase.SaveAssets(); } _startConnection = null; } }
/// <summary> /// Removes child node. /// </summary> /// <param name="node">Child node to remove.</param> /// <returns>True if removing succeed. Otherwise false.</returns> public abstract bool RemoveNode(ANode node);
//Should only be called from Node.Get() internal Document(ANode aNode, Database database) : base(aNode, Data.DOC, database) { }
/// 指定の座標にあるノードをオープンする. public ANode OpenNode(int x, int y, int cost, ANode parent) { // 座標をチェック. if(_layer.IsOutOfRange(x, y)) { // 領域外. return null; } if(_layer.Get(x, y) > 1) { // 通過できない. return null; } // ノードを取得する. var node = GetNode(x, y); if(node.IsNone() == false) { // 既にOpenしているので何もしない return null; } // Openする. node.Open(parent, cost); AddOpenList(node); return node; }
//Should only be called from Node.Get() internal Comment(ANode aNode, Database database) : base(aNode, Data.COMM, database) { }
//Should only be called from Node.Get() internal Attribute(ANode aNode, Database database) : base(aNode, Data.ATTR, database) { }
protected ContainerNode(ANode aNode, int kind, Database database) : base(aNode, kind, database) { }
private void ShowContextMenu(ANode node) { if (_tree == null || !_tree.Nodes.Contains(node)) { return; } GenericMenu menu = new GenericMenu(); if(node is AFlowNode) { if(node != _tree.Root) { menu.AddItem(new GUIContent("Make Root"), false, RootCallback, node); } else { menu.AddDisabledItem(new GUIContent("Make Root")); } menu.AddItem(new GUIContent("Connect"), false, ConnectCallback, node); } else { menu.AddDisabledItem(new GUIContent("Make Root")); menu.AddDisabledItem(new GUIContent("Connect")); } menu.AddSeparator(""); menu.AddItem(new GUIContent("Delete"), false, DeleteCallback, node); menu.ShowAsContext(); }
/// ステータスをOpenにする. public void Open(ANode parent, int cost) { Debug.Log (string.Format("Open: ({0},{1})", X, Y)); _status = eStatus.Open; _cost = cost; _parent = parent; }
/// <summary> /// Adds new node as a child. /// </summary> /// <param name="node">Node to be added as child.</param> /// <returns>True if adding succeed. Otherwise false.</returns> public abstract bool AddNode(ANode node);
/// ノード生成する. public ANode GetNode(int x, int y) { var idx = _layer.ToIdx(x, y); if(_pool.ContainsKey(idx)) { // 既に存在しているのでプーリングから取得. return _pool[idx]; } // ないので新規作成. var node = new ANode(x, y); _pool[idx] = node; // ヒューリスティック・コストを計算する. node.CalcHeuristic(_allowdiag, _xgoal, _ygoal); return node; }
protected override void OnRun() { Vector2 destination2D = new Vector2 (destination.x, destination.z); ANode endNode = null; if (isInsideMapBoundaries (destination2D)) { while (openList.Count != 0) { // Pop open list Vector2 current = openList.Values [0] [0]; ANode currentNode = openNodes [current]; openList.Values [0].RemoveAt (0); if (openList.Values [0].Count == 0) openList.RemoveAt (0); openNodes.Remove (current); closedNodes [current] = currentNode; if (current != destination2D) { Vector2[] adjacents = { new Vector2 (current.x, current.y + 1), new Vector2 (current.x + 1, current.y), new Vector2 (current.x, current.y - 1), new Vector2 (current.x - 1, current.y) }; foreach (Vector2 adj in adjacents) { if ((currentNode.preceding == null || adj != currentNode.preceding.point2D) && isInsideMapBoundaries(adj)) { if (openNodes.ContainsKey (adj) || closedNodes.ContainsKey (adj)) { // Update the node ANode adjNode = openNodes.ContainsKey (adj) ? openNodes [adj] : closedNodes [adj]; if (Mathf.Abs (adjNode.point.y - currentNode.point.y) <= maxSlope) { if (currentNode.G + Vector3.Distance (currentNode.point, adjNode.point) * ((currentNode.inWaterBody || adjNode.inWaterBody) ? bridgePenalty : 1f) < adjNode.G) { adjNode.preceding = currentNode; } } } else { // Create the node float adjY = getHeightValue (adj); Vector3 adj3D = new Vector3 (adj.x, Mathf.Abs (adjY), adj.y); if (Mathf.Abs (adj3D.y - currentNode.point.y) <= maxSlope) { ANode newNode = new ANode (adj3D, adjY < 0, destination, currentNode, bridgePenalty); float newF = newNode.F; if (!openList.ContainsKey (newF)) openList [newF] = new List<Vector2> (); openList [newF].Add (newNode.point2D); openNodes [newNode.point2D] = newNode; } } } } } else { endNode = currentNode; break; } } } output = new List<Vector3> (); while (endNode != null) { output.Add (endNode.point / resolution); endNode = endNode.preceding; } }
//Should only be called from Node.Get() internal Element(ANode aNode, Database database) : base(aNode, Data.ELEM, database) { }
/// <summary> /// オープンノードリスト追加メソッド /// <para> 指定したノードをオープンリストに追加する。 /// </summary> /// <param name="node">オープンノードリストに追加するノード</param> public void AddOpenNodeList(ANode addNode) { _openList.Add(addNode); }
/// ノードをオープンリストに追加する. public void AddOpenList(ANode node) { _openList.Add(node); }
/// <summary> /// ノード生成メソッド /// <para> ノードを生成する。</para> /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <returns>作成したノード</returns> public ANode GetNode(int x, int y) { // 座標をインデックスに変換する var idx = _layer.ToIdx(x, y); if(_nodeList.ContainsKey(idx)) { // インデックスがノードリストに既に存在している場合はそれを返す return _nodeList[idx]; } // インデックスがノードリストに存在しない場合は新規で作成し、連想配列に追加する var node = new ANode(x, y); _nodeList[idx] = node; // ノードのヒューリスティック・コストを計算する node.CalcHeuristic(_allowdiag, _xgoal, _ygoal); return node; }
/// 周りをOpenする. public void OpenAround(ANode parent) { var xbase = parent.X; // 基準座標(X). var ybase = parent.Y; // 基準座標(Y). var cost = parent.Cost; // コスト. cost += 1; // 一歩進むので+1する. if(_allowdiag) { // 8方向を開く. for(int j = 0; j < 3; j++) { for(int i = 0; i < 3; i++) { var x = xbase + i - 1; // -1~1 var y = ybase + j - 1; // -1~1 OpenNode(x, y, cost, parent); } } } else { // 4方向を開く. var x = xbase; var y = ybase; OpenNode (x-1, y, cost, parent); // 右. OpenNode (x, y-1, cost, parent); // 上. OpenNode (x+1, y, cost, parent); // 左. OpenNode (x, y+1, cost, parent); // 下. } }
/// <summary> /// 周囲ノードOpenメソッド /// <para> 周囲のノードをOpenにする。 /// </summary> /// <param name="parentNode">親ノード</param> public void OpenAround(ANode parentNode) { // 基準座標XとY var xbase = parentNode.X; var ybase = parentNode.Y; // コスト var cost = parentNode.Cost; cost += 1; // 一歩進むので+1する. if(_allowdiag) { // 斜め移動ありの場合(8方向を開く) for(int j = 0; j < 3; j++) { for(int i = 0; i < 3; i++) { var x = xbase + i - 1; // -1~1 var y = ybase + j - 1; // -1~1 // 上下左右+斜めのパネルをオープンにし、オープンノードリストに追加する OpenNode(x, y, cost, parentNode); } } } else { // 斜め移動なしの場合(4方向を開く) var x = xbase; var y = ybase; // 上下左右のパネルをオープンにし、オープンノードリストに追加する OpenNode (x-1, y, cost, parentNode); // 右. OpenNode (x, y-1, cost, parentNode); // 上. OpenNode (x+1, y, cost, parentNode); // 左. OpenNode (x, y+1, cost, parentNode); // 下. } }
/// ノードをオープンリストから削除する. public void RemoveOpenList(ANode node) { _openList.Remove(node); }
/// <summary> /// 指定座標ステータスOpenメソッド /// <para> 通過不能オブジェクト判定、およびパネルステータスがNONEか否かを</para> /// <para> 判定し、判定を通ったノードのステータスをOpenにする。</para> /// <para> また、オープンノードリスト(_openList)への追加も本メソッド内にて行う。</para> /// </summary> /// <param name="x">指定座標X</param> /// <param name="y">指定座標Y</param> /// <param name="cost">コスト</param> /// <param name="parentNode">親ノード</param> /// <returns></returns> public ANode OpenNode(int x, int y, int cost, ANode parentNode) { // 座標をチェック if(_layer.IsOutOfRange(x, y)) { // 領域外の場合はOpenリストに追加できないためメソッドを抜ける return null; } if(_layer.Get(x, y) > 1) { // 通過不能オブジェクトで通れない場合はOpenリストに追加できないためメソッドを抜ける return null; } // ノードをノードリストから取得する。無ければ作成する var node = GetNode(x, y); if(node.IsNone() == false) { // パネルのステータスがNONE以外の場合はOpenリストに追加できないためメソッドを抜ける return null; } // ノードをOpenし、オープンノードリストへそのノードを追加する node.Open(parentNode, cost); AddOpenNodeList(node); return node; }
/// <summary> /// オープンノードリスト削除メソッド /// <para> 指定したノードをオープンリストから削除する。</para> /// </summary> /// <param name="node">オープンノードリストから削除するノード</param> public void RemoveOpenNodeList(ANode deleteNode) { _openList.Remove(deleteNode); }
//Should only be called from Node.Get() internal Text(ANode aNode, Database database) : base(aNode, Data.TEXT, database) { }