Salve a tutti ragazzi vorrei aiuto per questo programma che non sono riuscito a far funzionare, in pratica non riesco a fargli fare un giro completo. Ho seguito le istruzioni del Deitel & Deitel es 6.24 pg 279.
#include <stdio.h>
#include <stdlib.h>
#define DIM 8
int main()
{
int currentRow = 0, currentColumn = 0, moveNumber;
int pass, row, col, temp;
int i=0, j=0, count = 0, k;
int board[DIM][DIM] = { 0 };
int accessibility[DIM][DIM] = { 0 };
int horizontal[DIM] = { 2, 1, -1, -2, -2, -1, 1, 2 };
int vertical[DIM] = { -1, -2, -2, -1, 1, 2, 2, 1 };
int probability [DIM]= { 0 };
for(i=0 ; i<DIM ; i++){
for(j=0 ; j<DIM ; j++){
k = 0;
do {
currentRow = i;
currentColumn = j;
currentRow += vertical[k];
currentColumn += horizontal[k];
if(currentRow >= 0 && currentRow <= 7 && currentColumn >= 0 && currentColumn <= 7)
accessibility[i][j]+= 1;
k++;
} while (k != 8);
}
}
currentRow = 0;
currentColumn = 0;
do {
i = 0;
pass = 1;
row = currentRow;
col = currentColumn;
for(j=0;j<DIM;j++){
probability[i] = 0;
}
do{
if(i == 8)
break;
currentRow += vertical[i];
currentColumn += horizontal[i];
if(currentRow >= 0 && currentRow <= 7 && currentColumn >= 0 && currentColumn <= 7 && board[ currentRow ][ currentColumn ] == 0){
probability[i] = accessibility[currentRow][currentColumn];
}
i++;
currentRow = row;
currentColumn = col;
if (i == 7){
i = 0;
for(j=0;j<DIM;j++){
if (probability[i] <= probability[j])
i = j;
}
pass = 0;
currentRow += vertical[i];
currentColumn += horizontal[i];
}
} while(pass != 0);
if(i == 8)
break;
count++;
board[row][col] = 1;
printf("#%d: x= %d - y= %d\n", count, currentColumn, currentRow);
} while(count != 64);
printf("\n");
for(i = 0; i < DIM; ++i)
{
for(j = 0; j < DIM; ++j)
printf("%d\t", board[ i ][ j ]);
printf("\n");
}
printf("\n");
for(i = 0; i < DIM; ++i)
{
for(j = 0; j < DIM; ++j)
printf("%d\t", accessibility[ i ][ j ]);
printf("\n");
}
return 0;
}
grazie a tutti!