#include #include #include #include "dice.h" void main (void) { int aa = 0; apmatrix table(8,8,0); //for (int c = 0;c < 8;c++) for (int d = 0;d < 7;d++) table [d][d] = 0; apvector possibleMoves(8,false); table[0][0] = 1; int x = 0,y = 0,moves = 1, open = 0; bool done = false; do { if (x+2 <= 7) { if (y+1 <= 7) if (table[x+2][y+1] == 0) {possibleMoves[0]=true;open++;} if (y-1 >= 0) if (table[x+2][y-1] == 0) {possibleMoves[1]=true;open++;} } if (x-2 >= 0) { if (y+1 <= 7) if (table[x-2][y+1] == 0) {possibleMoves[2]=true;open++;} if (y-1 >= 0) if (table[x-2][y-1] == 0) {possibleMoves[3]=true;open++;} } if (x+1 <= 7) { if (y+2 <= 7) if (table[x+1][y+2] == 0) {possibleMoves[4]=true;open++;} if (y-2 >= 0) if (table[x+1][y-2] == 0) {possibleMoves[5]=true;open++;} } if (x-1 >= 0) { if (y+2 <= 7) if (table[x-1][y+2] == 0) {possibleMoves[6]=true;open++;} if (y-2 >= 0) if (table[x-1][y-2] == 0) {possibleMoves[7]=true;open++;} } if (open == 0) done = true; else { moves++; int g = 0,h = 0,i = 0; dice die(open); g = die.roll(); do { if (possibleMoves[i] == true) h++;i++; } while (h < g); i--; switch (i) { case 0 : table[x+2][y+1] = moves;x += 2;y++;break; case 1 : table[x+2][y-1] = moves;x += 2;y--;break; case 2 : table[x-2][y+1] = moves;x -= 2;y++;break; case 3 : table[x-2][y-1] = moves;x -= 2;y--;break; case 4 : table[x+1][y+2] = moves;x++;y += 2;break; case 5 : table[x+1][y-2] = moves;x++;y -= 2;break; case 6 : table[x-1][y+2] = moves;x--;y += 2;break; case 7 : table[x-1][y-2] = moves;x--;y -= 2;break; } open = 0; for (int k=0;k<8;k++) possibleMoves[k] = false; } } while (!done); for (int a = 0;a < 8;a++) { for (int b = 0;b < 8;b++) { cout << table[b][a]; if (table[b][a] > 9) cout << " "; else cout << " "; } cout << "\n"; } }