void init(void)
{
int count = d*d-1;
for(int i=0; i < d; i++)
{
for(int j = 0;j< d;j++)
{
board[i][j] = count;
count--;
}
}
//if even number swap 1 and 2
if(d%2==1)
{
int temp = board[d-1][d-2];
board[d-1][d-2] = board[d-1][d-3];
board[d-1][d-3] = temp;
}
}
void draw(void)
{
for(int i=0; i < d; i++)
{
for(int a=0; a < d; a++)
{
/*if(board[i][a]==0)
{
board[i][a] = (char)'#';
printf("%c\t",board[i][a]);
}
else
{*/
printf("%i\t",board[i][a]);
//}
}
printf("\n");
}
}
bool move(int tile)
{
for(int i=0; i < d; i++)
{
for(int j = 0;j< d;j++)
{
if(board[i][j]==tile)
{
if(board[i][j+1]==0 && board[i][j] != board[i][d-1])
{
int temp = tile;
board[i][j] = 0;
board[i][j+1] = temp;
return true;
}
else if(board[i][j-1]==0 && board[i][j] != board[i][0])
{
int temp = tile;
board[i][j] = 0;
board[i][j-1] = temp;
return true;
}
else if(board[i+1][j]==0 && board[i][j] != board[d-1][j])
{
int temp = tile;
board[i][j] = 0;
board[i+1][j] = temp;
return true;
}
else if(board[i-1][j]==0 && board[i][j] != board[0][j])
{
int temp = tile;
board[i][j] = 0;
board[i-1][j] = temp;
return true;
}
else
{
return false;
}
}
}
}
return false;
}
Hello, I'm trying to solve GoF. It outputs the board with no problems, but when I try to move a tile; -For example: the tile 8 in a 3x3 board, it swaps ! It seems like the board is covered with invisible zeroes. How can I solve it ?