private void CheckAddOpenNodes(int col, int row, PathSearchNode _sNode) { // 判断新加入的点是否已经包含在开启或关闭列表中 if (IsInvolveOpenClose(col, row)) { return; } // 判断是否是起点 if (startPosition.Equal(col, row)) { return; } PathNode node = AutoPathMap.pathMap[col, row]; // 计算总体消耗 node.f = CalculateF(node); // 设置父元素 node.Parent = _sNode.node; PathSearchNode newNode = new PathSearchNode(col, row, node); if (node.type == NODE_TYPE.Normal) { openNodes.Add(newNode); } }
public void Search() { openNodes.Clear(); closeNodes.Clear(); closeNodes.Add(startPosition); PathSearchNode movePosition = startPosition; while (true) //for(int i = 0; i < 5; i++) { CalculateParentNodes(movePosition); movePosition = FindBestPath(); if (movePosition == null || movePosition.Equal(targetPosition)) { break; } } //Debug.Log("openNodes count ****** :" + openNodes.Count); //Debug.Log("closeNodes count ****** :" + closeNodes.Count); foreach (PathSearchNode n in closeNodes) { if (n.node.Parent != null) { Debug.Log(string.Format("close sort list col={0}, row={1}, node={2}, parent:{3}", n.col, n.row, n.node, n.node.Parent.ToString())); } } //foreach (PathSearchNode n in openNodes) //{ // Debug.Log(string.Format("open sort list col={0}, row={1}, f={2}, parent:{3}", n.col, n.row, n.node.f, n.node.Parent.ToString())); //} }