private void PathOpened(int x, int y, int newCost, SearchCell parent) { // Debug.Log(x+","+y); if (x < 0 || y < 0) { return; } if (x >= GameObject.Find("Main Camera").GetComponent <LoadMap>().m_cols || y >= GameObject.Find("Main Camera").GetComponent <LoadMap>().m_rows) { return; } if (GameObject.Find("Main Camera").GetComponent <LoadMap>().Grid[y][x] == 'b') { return; } int id = y * WORLD_SIZE + x; for (int i = 0; i < scPtr_visitedList.Count; i++) { if (id == scPtr_visitedList[i].m_id) { return; } } SearchCell newChild = new SearchCell(x, y, parent); newChild.G = newCost; newChild.H = parent.ManHattanDis(scPtr_goalCell); for (int i = 0; i < scPtr_openList.Count; i++) { if (id == scPtr_openList[i].m_id) { int newF = newChild.G + newCost + scPtr_openList[i].H; if (scPtr_openList[i].GetF() > newF) { scPtr_openList[i].G = newChild.G + newCost; scPtr_openList[i].scPtrParent = newChild; } else //if the new F is not better { return; } } } scPtr_openList.Add(newChild); }
private void SetStartAndGoal(SearchCell start, SearchCell goal) { SearchCell nullSc = new SearchCell(); nullSc.m_xcoord = -9999; scPtr_startCell = new SearchCell(start.m_xcoord, start.m_ycoord, nullSc); scPtr_goalCell = new SearchCell(goal.m_xcoord, goal.m_ycoord, goal); scPtr_startCell.G = 0; scPtr_startCell.H = scPtr_startCell.ManHattanDis(scPtr_goalCell); //m_startCell.parent = nullptr; scPtr_openList.Add(scPtr_startCell); }