public override void Update(GameTime gameTime) { if (!IsActive) { return; } foreach (var currentAdjacentCell in grid.GetValidAdjacentCells(currentCell)) { if (currentAdjacentCell.State != GridCellState.Open) { currentAdjacentCell.State = GridCellState.Open; currentAdjacentCell.Parent = currentCell; currentAdjacentCell.H = Heuristic.GetEstimate(currentAdjacentCell.Position, grid.Destination.Position) * 10; currentAdjacentCell.H += GetTieBreaker(currentAdjacentCell); //currentAdjacentCell.H *= 1 + 1/1000f; currentAdjacentCell.G = currentCell.G + (currentCell.IsOrthagonalWith(currentAdjacentCell) ? 10 : 14); openList.Insert(currentAdjacentCell.F, currentAdjacentCell); } } if (openList.Count == 0) //A path cannot be found { IsActive = false; return; } totalVisited++; currentCell = openList.RemoveMin(); currentCell.State = GridCellState.Closed; if (grid.Destination.State == GridCellState.Closed) //A path has been found { var path = currentCell.GetPath(); IsActive = false; PathFound(this, new PathFoundEventArgs(path, path.Count(),totalVisited -1)); } base.Update(gameTime); }