Download the sourcecode from GitHub.
Principal code of the new algorithm.
//-- 12 //-- +.+.+ //-- ..+.. //-- ++Q++ //-- ..+.. //-- +.+.+ int twelfth = N % 12; int[] tmpBoard = new int[N + 4]; Array.Clear(tmpBoard, 0, tmpBoard.Length); int nIndex = 0; // Diagonal knight from 2 for (int i = 2; i <= N; i += 2) tmpBoard[nIndex++] = i; if (twelfth == 3 || twelfth == 9) { tmpBoard[0] = 0; tmpBoard[nIndex++] = 2; } for (int i = 1; i <= N; i += 4) { if (twelfth == 8) { tmpBoard[nIndex++] = i + 2; tmpBoard[nIndex++] = i; } else { tmpBoard[nIndex++] = i; tmpBoard[nIndex++] = i + 2; } } if (twelfth == 2) { for (int i = 0; i <= N; i++) { if (tmpBoard[i] == 1) tmpBoard[i] = 3; else if (tmpBoard[i] == 3) tmpBoard[i] = 1; if (tmpBoard[i] == 5) tmpBoard[i] = 0; } tmpBoard[nIndex++] = 5; } if ((twelfth == 3) || (twelfth == 9)) { for (int i = 0; i <= N; i++) if (tmpBoard[i] == 3 || tmpBoard[i] == 1) tmpBoard[i] = 0; tmpBoard[nIndex++] = 1; tmpBoard[nIndex] = 3; } nIndex = 0; for (int i = 0; i < tmpBoard.Length; i++) if (tmpBoard[i] != 0 && tmpBoard[i] <= N) m_Board[nIndex++] = tmpBoard[i] - 1;