public List <MapCellAStar> GetSuccessors() { List <MapCellAStar> successors = new List <MapCellAStar>(); for (short xd = -1; xd <= 1; xd++) { for (short yd = -1; yd <= 1; yd++) { if (!ServerManager.GetMap(MapId).IsBlockedZone(X + xd, Y + yd)) { MapCellAStar n = new MapCellAStar(this, this._goalcell, (short)(X + xd), (short)(Y + yd), MapId); if (!n.IsMatch(this.parentcell) && !n.IsMatch(this)) { successors.Add(n); } } } } return(successors); }
public int IndexOf(MapCellAStar n) { for (int i = 0; i < _list.Count; i++) { MapCellAStar cellInTheList = (MapCellAStar)_list[i]; if (cellInTheList.IsMatch(n)) { return(i); } } return(-1); }
public List <MapCell> AStar(MapCell cell1, MapCell cell2) { List <MapCell> SolutionPathList = new List <MapCell>(); SortedCostMapCellList OPEN = new SortedCostMapCellList(); SortedCostMapCellList CLOSED = new SortedCostMapCellList(); MapCellAStar cell_start = new MapCellAStar(null, null, cell1.X, cell1.Y, cell1.MapId); MapCellAStar cell_goal = new MapCellAStar(null, null, cell2.X, cell2.Y, cell2.MapId); OPEN.Push(cell_start); while (OPEN.Count > 0) { MapCellAStar cell_current = OPEN.Pop(); if (cell_current.IsMatch(cell_goal)) { cell_goal.parentcell = cell_current.parentcell; break; } List <MapCellAStar> successors = cell_current.GetSuccessors(); foreach (MapCellAStar cell_successor in successors) { int oFound = OPEN.IndexOf(cell_successor); if (oFound > 0) { MapCellAStar existing_cell = OPEN.CellAt(oFound); if (existing_cell.CompareTo(cell_current) <= 0) { continue; } } int cFound = CLOSED.IndexOf(cell_successor); if (cFound > 0) { MapCellAStar existing_cell = CLOSED.CellAt(cFound); if (existing_cell.CompareTo(cell_current) <= 0) { continue; } } if (oFound != -1) { OPEN.RemoveAt(oFound); } if (cFound != -1) { CLOSED.RemoveAt(cFound); } OPEN.Push(cell_successor); } CLOSED.Push(cell_current); } MapCellAStar p = cell_goal; while (p != null) { SolutionPathList.Insert(0, p); p = p.parentcell; } return(SolutionPathList); }