Refactor out common next square lookup code

BoardMath#intermediate_files and BoardMath#intermediate_ranks now share
one method, BoardMath#intermediate_squares which takes a block defining
how to lookup the next file or rank in the search for intermediate
squares.