Can you move this into its own loop? This is one of the few performance-sensitive pieces of code in the game, and I'm wary of having an additional branch for each square.