Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void KnightsTourRecursion(int, int, int);
- bool board[12][12];
- int found = 0;
- int main()
- {
- for(int i = 0;i<12;i++)
- {
- for(int x = 0;x<12;x++)
- {
- board[i][x] = false;
- }
- }
- for(int i = 2;i<10;i++)
- {
- for(int x = 2;x<10;x++)
- {
- board[i][x] = true;
- }
- }
- KnightsTourRecursion(2,2,1);
- return 0;
- }
- void KnightsTourRecursion(int X, int Y, int level)
- {
- if(board[X][Y] == true)
- {
- board[X][Y] = false;
- if(level == 64)
- {
- found++;
- board[X][Y] = true;
- cout << found << endl;
- char hold = cin();
- return;
- }
- int newlevel = level + 1;
- for(int i = 0;i<8;i++)
- {
- cout << level << endl;
- switch(i)
- {
- case 0:
- KnightsTourRecursion(X - 2, Y - 1, newlevel);
- break;
- case 1:
- KnightsTourRecursion(X - 2, Y + 1, newlevel);
- break;
- case 2:
- KnightsTourRecursion(X - 1, Y + 2, newlevel);
- break;
- case 3:
- KnightsTourRecursion(X + 1, Y + 2, newlevel);
- break;
- case 4:
- KnightsTourRecursion(X + 2, Y + 1, newlevel);
- break;
- case 5:
- KnightsTourRecursion(X + 2, Y - 1, newlevel);
- break;
- case 6:
- KnightsTourRecursion(X + 1, Y - 2, newlevel);
- break;
- case 7:
- KnightsTourRecursion(X - 1, Y - 2, newlevel);
- break;
- }
- }
- board[X][Y] = true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment