optimized game_over function to use a single inner loop