Method AggregateNeighborhood
AggregateNeighborhood<TPoint, TResultCell>(IGrid<TPoint>, Func<TPoint, IEnumerable<TPoint>>, Func<IEnumerable<TPoint>, TResultCell>)
Creates a new grid where the neighbors of a point are aggregated to the grid changing the type of the points.
public static IGrid<TPoint, TResultCell> AggregateNeighborhood<TPoint, TResultCell>(IGrid<TPoint> grid, Func<TPoint, IEnumerable<TPoint>> getNeighborHood, Func<IEnumerable<TPoint>, TResultCell> aggregator)
Parameters
gridIGrid<TPoint>Grid in which the operations are performed.
getNeighborHoodFunc<TPoint, IEnumerable<TPoint>>This function is used to get all the neighborhood of a given point.
aggregatorFunc<IEnumerable<TPoint>, TResultCell>This function is used to aggregate a list of point into a grid.
Returns
- IGrid<TPoint, TResultCell>
Type Parameters
TPointThe type of the points of the grid.
TResultCellThe type of the points of the resulting grid.
Examples
Suppose we have a grid with a count of enemies in each cell, and we want a grid that has in each cell, the sum of the enemies in neighboring cells. We can use the following to do that:
var closeEnemyCount = AggregateNeighborhood(
grid,
p => GetNeighbors(p),
list => list.Sum());
AggregateNeighborhood<TPoint, TCell>(IGrid<TPoint, TCell>, Func<TPoint, IEnumerable<TPoint>>, Func<IEnumerable<TPoint>, TCell>)
Creates a new grid where the neighbors of a point are aggregated to the grid changing the type of the points.
public static void AggregateNeighborhood<TPoint, TCell>(IGrid<TPoint, TCell> grid, Func<TPoint, IEnumerable<TPoint>> getNeighborHood, Func<IEnumerable<TPoint>, TCell> aggregator)
Parameters
gridIGrid<TPoint, TCell>Grid in which the operations are performed.
getNeighborHoodFunc<TPoint, IEnumerable<TPoint>>This function is used to get all the neighborhood of a given point.
aggregatorFunc<IEnumerable<TPoint>, TCell>This function is used to aggregate a list of point into a grid.
Type Parameters
TPointThe type of the points of the grid.
TCellThe type of the cells of the grid.
Examples
Suppose we have a grid with a count of enemies in each cell, and we want a grid that has in each cell, the sum of the enemies in neighboring cells. We can use the following to do that:
var closeEnemyCount = AggregateNeighborhood(
grid,
p => GetNeighbors(p),
list => list.Sum());