Abstract BFS in GridModel

Breadth first search of connected cells in GridModel is abstracted, so that the actions that deal with connected cells can be specified in individual functions without repeating implementation of search.