Trying to see how many locations certain map object can be placed on the map. All available locations that fit the tile area.

I'm using an array of arrays for each row of the "map" to make a virtual grid of what the map looks like. Each tile location will either have a 0 or a 1 to determine whether that tile is empty or if there is already an object occupying that tile.


The array would look something like this: The 1's display the inpenetrable border around the map. All the 0's are open spaces where an object, such as a tree, rock, or building can be placed.


1, 1, 1, 1, 1, 1, 1, 1, 1, 1

1, 0, 0 , 0, 0, 0, 0, 0, 0, 1

1, 0, 0 , 0, 0, 0, 0, 0, 0, 1

1, 0, 0 , 0, 0, 0, 0, 0, 0, 1

1, 0, 0 , 0, 0, 0, 0, 0, 0, 1

1, 0, 0 , 0, 0, 0, 0, 0, 0, 1

1, 0, 0 , 0, 0, 0, 0, 0, 0, 1

1, 0, 0 , 0, 0, 0, 0, 0, 0, 1

1, 0, 0 , 0, 0, 0, 0, 0, 0, 1

1, 1, 1, 1, 1, 1, 1, 1, 1, 1


What I'm trying to do is figure out if I have an object of 2x2 tile size, how many different locations this 2x2-tiled object will fit!


This is what I have so far:


for rowNumber in minRow...maxRow{
          
            var theRow = tiles[rowNumber]
                     
            for columnNumber in minColumn...maxColumn{
              
                if(theRow[columnNumber] == 0){
                  
                   //Do something
                }
              
            }
        }


I don't really know where to go from here. I know I could count the consecutivel amount of rows and columns that contained a 0 or were empty. If the successful rows = objectHeight and successful columns = objectWidth then I would be able to fit the 2x2 object. So I have no trouble attaining the location for one successful placement... But I want to know ALL the locations where my 2x2 object would fit.


In the given example my 2x2 object could fit 42 times in the diagram, this number would drastically change if there were a couple random locations where there was a 1 instead of 0. I don't know how to programatically achieve this number though. Any thoughts?

Trying to see how many locations certain map object can be placed on the map. All available locations that fit the tile area.
 
 
Q