predicate that returns true if the flood should progress through a given tile.
grid to apply flood to.
coordinate at which to begin flood.
by default, flood only progresses to directly adjacent tiles. Diagonals.yes causes the flood to progress across diagonals too.
1 import std.array; 2 import std.algorithm : equal; 3 4 // let the 'X's represent 'walls', and the other letters 'open' areas we'd link to identify 5 auto grid = rectGrid([ 6 // 0 1 2 3 4 5 <-col| row 7 [ 'X', 'X', 'X', 'X', 'X', 'X' ], // 0 8 [ 'X', 'a', 'a', 'X', 'b', 'X' ], // 1 9 [ 'X', 'a', 'a', 'X', 'b', 'X' ], // 2 10 [ 'X', 'X', 'X', 'X', 'X', 'c' ], // 3 11 [ 'd', 'd', 'd', 'X', 'c', 'X' ], // 4 12 [ 'd', 'd', 'd', 'X', 'X', 'X' ], // 5 13 ]); 14 15 // starting on a wall should return an empty result 16 assert(grid.floodTiles!(x => x == 'a')(RowCol(0,0)).empty); 17 assert(grid.floodTiles!(x => x == 'a')(RowCol(3,3)).empty); 18 19 // flood the 'a' room 20 assert(grid.floodTiles!(x => x == 'a')(RowCol(1,1)).equal(['a', 'a', 'a', 'a'])); 21 assert(grid.floodTiles!(x => x == 'a')(RowCol(1,2)).equal(['a', 'a', 'a', 'a'])); 22 assert(grid.floodTiles!(x => x == 'a')(RowCol(2,1)).equal(['a', 'a', 'a', 'a'])); 23 assert(grid.floodTiles!(x => x == 'a')(RowCol(2,2)).equal(['a', 'a', 'a', 'a'])); 24 25 // flood the 'a' room, but asking for a 'b' 26 assert(grid.floodTiles!(x => x == 'b')(RowCol(2,2)).empty); 27 28 // flood the 'b' room 29 assert(grid.floodTiles!(x => x == 'b')(RowCol(1,4)).equal(['b', 'b'])); 30 31 // flood the 'c' room 32 assert(grid.floodTiles!(x => x == 'c')(RowCol(4,4)).equal(['c'])); 33 34 // flood the 'd' room 35 assert(grid.floodTiles!(x => x == 'd')(RowCol(4,1)).equal(['d', 'd', 'd', 'd', 'd', 'd'])); 36 37 // flood the 'b' and 'c' rooms, moving through diagonals 38 assert(grid.floodTiles!(x => x == 'b' || x == 'c')(RowCol(4,4), Diagonals.yes) 39 .equal(['c', 'c', 'b', 'b']));
Returns a range that iterates through tiles based on a flood filling algorithm.