Esempio n. 1
0
        public override List <Point> Run(Grid CurrentGrid)
        {
            base.Run(CurrentGrid);
            Iteration -= 0.9;
            List <Point> ChangedPoints = new List <Point>();

            for (int i = FrontPoints.Count - 1; i >= 0; i--)

            {
                Point frontalPoint = FrontPoints[i];
                if (CurrentGrid.Cells[frontalPoint.X, frontalPoint.Y].Time < Iteration)
                {
                    List <Point> nList = _Neighborhood.GetNeighborhood(frontalPoint.X, frontalPoint.Y, Grid.SizeX, Grid.SizeY)
                                         .Where(v => CurrentGrid.GetCellState(v.X, v.Y) == 0).ToList();
                    foreach (Point newFrontalPoint in nList)
                    {
                        Cell cell = CurrentGrid.Cells[newFrontalPoint.X, newFrontalPoint.Y];
                        cell.ChangeState(2);
                        cell.Id             = CurrentGrid.Cells[frontalPoint.X, frontalPoint.Y].Id;
                        cell.OriginPosition = CurrentGrid.Cells[frontalPoint.X, frontalPoint.Y].OriginPosition;
                        cell.Time           = CalculateTime(cell.OriginPosition.X, cell.OriginPosition.Y, newFrontalPoint.X, newFrontalPoint.Y);
                        ChangedPoints.Add(newFrontalPoint);
                    }
                    FrontPoints.AddRange(nList);
                    CurrentGrid.Cells[frontalPoint.X, frontalPoint.Y].ChangeState(1);
                    FrontPoints.RemoveAt(i);
                    Change = true;
                    ChangedPoints.Add(frontalPoint);
                }
            }
            Change = Change || FrontPoints.Count > 0;
            return(ChangedPoints);
        }
Esempio n. 2
0
 void CalculateNextGridFromCoordinates(int startX, int startY, int endX, int endY)
 {
     for (int i = FrontPoints.Count - 1; i >= 0; i--)
     {
         Point p = FrontPoints[i];
         if (CurrentGrid.Cells[p.X, p.Y].Time < Iteration)
         {
             List <Point> nList = NManager.GetNeighborhood(p.X, p.Y, Grid.SizeX, Grid.SizeY, BoundaryConditions.Fixed)
                                  .Where(v => CurrentGrid.GetCellState(v.X, v.Y) == 0).ToList();
             foreach (Point p2 in nList)
             {
                 CurrentGrid.Cells[p2.X, p2.Y].ChangeState(2);
             }
             FrontPoints.AddRange(nList);
             CurrentGrid.Cells[p.X, p.Y].ChangeState(1);
             FrontPoints.RemoveAt(i);
             NumberOfFreeCells--;
         }
     }
 }