Updated calculate_fg function to include boundary cells

I changed some parts of the structure, instead of looking through the
array twice (4 for loops), I changed it to just 2 and put a condition
where I check the flag, just checking we don't go out of bounds, even
though I'm not even sure if the conditions where correct in the first
place. I also have a question here, should the F[0][0] and G[0][0]
should be set to something? Maybe this is the part that the guy was
telling us was wrong...also please check the conditions for the boundary
cells.