private void CheckRightCell(Cell cell, ref List <Cell> adjacenedCells) { Cell rightCell; if (cell.GetX() < _grid.GetLength(1) - 1) { rightCell = _grid[cell.GetX() + 1, cell.GetY()]; if (!rightCell.IsWall() && !_closedList.Contains(rightCell)) { rightCell.Parent = cell; adjacenedCells.Add(rightCell); } } }
private void CheckLeftCell(Cell cell, ref List <Cell> adjacenedCells) { Cell leftCell; if (cell.GetX() > 0) { leftCell = _grid[cell.GetX() - 1, cell.GetY()]; if (!leftCell.IsWall() && !_closedList.Contains(leftCell)) { leftCell.Parent = cell; adjacenedCells.Add(leftCell); } } }
private void CheckBottomCell(Cell cell, ref List <Cell> adjacenedCells) { Cell bottomCell; if (cell.GetY() < _grid.GetLength(0)) { bottomCell = _grid[cell.GetX(), cell.GetY() + 1]; if (!bottomCell.IsWall() && !_closedList.Contains(bottomCell)) { bottomCell.Parent = cell; adjacenedCells.Add(bottomCell); } } }
private void CheckTopCell(Cell cell, ref List <Cell> adjacenedCells) { Cell topCell; if (cell.GetY() - 1 > 0) { topCell = _grid[cell.GetX(), cell.GetY() - 1]; if (!topCell.IsWall() && !_closedList.Contains(topCell)) { topCell.Parent = cell; adjacenedCells.Add(topCell); } } }
public bool IsNextTo(Cell other) { #region Validation if (other == null) { throw new ArgumentNullException("Cell invalid"); } #endregion int xDiff = Math.Abs(this.GetX() - other.GetX()); int yDiff = Math.Abs(this.GetY() - other.GetY()); return(xDiff + yDiff < 2 && xDiff + yDiff != 0); }
private int CalculateManhattanHeuristics(Cell cell1, Cell cell2) { return(Math.Abs(cell1.GetX() - cell2.GetX()) + Math.Abs(cell1.GetY() - cell2.GetY())); }