i have tried to look for a solution before i posted this and i cant get 1, please help me. https://pastebin.com/PsnMGsGx
/**
* Initializes the game's board with tiles numbered 1 through d*d - 1
* (i.e., fills 2D array with values but does not actually print them).
*/
void init(void)
{
// TODO
int i,j;
int k=d*d-1;
// blank space
blank_row=d-1;
blank_column=d-1;
for(i=0;i<d;i++)
{
for(j=0;j<d;j++)
{
board[i][j]=k--;
}
}
if(d%2!=0)
{
int temp=board[d-1][d-3];
board[d-1][d-3]=board[d-1][d-2];
board[d-1][d-2]=temp;
}
board[blank_row][blank_column]=0;
}
/**
* Prints the board in its current state.
*/
void draw(void)
{
printf("\n");
// TODO
for(int i=0;i<d;i++)
{
for(int j=0;j<d;j++)
{
if(board[i][j]==0)
{
printf("_\t");
}
else
printf("%2i\t",board[i][j]);
}
printf("\n \n");
}
}
bool move(int tile)
{//int row n column to track the position of blank space
int tile_row;
int tile_column;
for(int i=0;i<d;i++)
{
for(int j=0;j<d;j++)
{
if(board[i][j]==0)
{
blank_row=i;
blank_column=j;
}
if(board[i][j]==tile&&tile>0&&tile<d*d)
{
tile_row=i;
tile_column=j;
}
}
}
if((board[blank_row-1][blank_column]==tile) || (board[blank_row+1]
[blank_column]==tile) || (board[blank_row][blank_column-1]==tile) ||
(board[blank_row][blank_column+1]==tile))
{
metrytoexchange(&board[blank_row][blank_column],&board[tile_row]
[tile_column]);
return true;
}
return false;
}
/** * Returns true if game is won (i.e., board is in winning configuration), * else false. */
// TODO
bool won(void)
{
// TODO
int checker=1;
for(int i=0;i<d;i++)
{
for(int j=0;j<d;j++)
{
if (board[i][j]!=checker++)
{
return false;
}
}
}
return true;
}
void metrytoexchange(int *a,int *b)
{
int temp= *a;
*a = *b;
*b = temp;
}
but i get this sad faces from check50
:( 3x3 board: move up-up-left-down-down-left-up-up-right-down-down-right
did not find output "4-1-7|8-2-6|5-3..."
:( 3x3 board: make sure none of 2, 4, 5, 6, 7, 8 move tile
did not find output "Illegal move."
:( 3x3 board: move blank left (tile 1) then up (tile 4), then try to move
tiles 1, 2, 6, 8
did not find output "Illegal move."
:( 3x3 board: make sure game is winnable
did not find output "1-2-3|4-5-6|7-8..."
:( 4x4 board: make sure game is winnable
did not find output "1-2-3-4|5-6-7-8..."
See https://cs50.me/checks/dda85031d55230ee0ed5ce7626816452c88cdc3b for more
detail.