public void Process_NoNeighbours_ReturnsMinPositionAndZeroMark() { var startingPosition = new Position(0, 0); int[,] result = new int[1, 1]; var findHighestMark = new FindHighestMarkNeighbourProcessor(); var parameters = new FloodParameters(startingPosition.X, startingPosition.Y) { NeighbourProcessor = findHighestMark.Process }; new FloodSpiller().SpillFlood(parameters, result); findHighestMark.PositionWithHighestMark.Should().Be(Position.MinValue); findHighestMark.HighestMark.Should().Be(0); }
public void Process_FloodIsSpilledAround_ReturnsLastProcessedNeighbourWithMarkHigherThanOthers() { var startingPosition = new Position(1, 1); int[,] result = new int[4, 4]; Predicate <int, int> qualifier = (x, y) => y != 3 || x == 0; var findHighestMark = new FindHighestMarkNeighbourProcessor(); var parameters = new FloodParameters(startingPosition.X, startingPosition.Y) { Qualifier = qualifier, NeighbourProcessor = findHighestMark.Process }; new FloodSpiller().SpillFlood(parameters, result); var expectedPosition = new Position(0, 3); int expectedHighestMark = 2; findHighestMark.PositionWithHighestMark.Should().Be(expectedPosition); findHighestMark.HighestMark.Should().Be(expectedHighestMark); }
public IFloodArea FetchWalkableFlood(Position center, int floodRange) { // performance: maybe we should keep a few last calculated results for center-floodRange pairs if (_cachedFloodArea == null) { _cachedFloodArea = new FloodArea(center, floodRange); } int expectedMatrixSize = floodRange * 2 + 1; if (_cachedFloodArea.ArraySize < expectedMatrixSize) { _cachedFloodArea.IncreaseMatrix(expectedMatrixSize); } if (_cachedFloodArea.Center != center) { _cachedFloodArea.Center = center; int boundsSize = floodRange * 2; _cachedFloodArea.Bounds = new Bounds(center.x - floodRange, center.y - floodRange, boundsSize, boundsSize); } var findHighestMark = new FindHighestMarkNeighbourProcessor(); var parameters = new FloodParameters(center.x, center.y) { Qualifier = (x, y) => _grid.IsWalkable(new Position(x, y)), BoundsRestriction = BoundsUtilities.ToFloodBounds(_cachedFloodArea.Bounds), NeighbourProcessor = findHighestMark.Process }; Position furthestPosition = center; _floodSpiller.SpillFlood(parameters, _cachedFloodArea.ValueMatrix); _cachedFloodArea.FurthestPosition = furthestPosition; return(_cachedFloodArea); }