I have a board game notation for the game of Hnefatafl which I need to rotate clockwise. In the game of Hnefatafl we use a 11x11 board with files from A to K and ranks numbered from 1 to 11. So, here are the first three moves from the notation:
"1.k8-i8 g7-j7; 2.k5-j5 h6-h9; 3.k7-k9 f8-c8;"
After the rotation the notation must be like this:
"1.h1-h3 g5-g2; 2.e1-e2 f4-i4; 3.g1-i1 h6-h9;"
How can I rotate the board and normalize the notation by using a JavaScript function?
When you rotate the board, you can see that anything that used to be in file A is now in rank 11; anything that was in file K is now in rank 1, etc.
In general, take the rank letter's ordinal position and subtract it from 11.
Likewise, the old ranks can get mapped in a similar way
So if your coordinates are of the form:
then you can just transform them using a function like this:
Then you can just transform them to the new coordinate system.
Sample implementation
Output: