The only way I can think of is to translate the points of the path into points on the coordinate plane. Then you could calculate the line of best fit. Using the slope of the line of best fit you could find the diagonality of the path if you know where the line starts (perfect diagonality would be a slope of -1 in this case).

I have not put much thought into it, this is just the first idea that popped into my head.

What is your goal in life? Or more specifically, what is your goal by solving this problem?

You haven't specified your question enough, either. Do you want the algorithm to punish walks that have more grey squares? Which of these are more diagonal?

What is your goal in life? Or more specifically, what is your goal by solving this problem?

You haven't specified your question enough, either. Do you want the algorithm to punish walks that have more grey squares? Which of these are more diagonal?

the grey squares are actually the paths traveled. the goal is to flood the board with one color. but i just want to measure how diagonal are the traveled paths. in this point, im not much interested in obtaining the goal but instead much on the diagonality measure.

the board is supposed to be coloured. but im just showing the path traveled so i did not colour it anymore.

APLX is a very complete implementation of the APL programming language from MicroAPL. The company stopped producing it in 2016 and it has been taken over by Dyalog. While Dyalog ...