For my game Legions at War, checking moves of each piece was to slow so I cached all the tiles in an array on start. When a piece is moved I update the tiles that, that piece is threatening, then it's as easy as looping through the cache to see if the king was in danger.