i can't figure out why i get the sad faces on move and won.Help will be appreciated.i am an able to post the code right in this forum. https://pastebin.com/RXwnUqaz
*/
bool move(int tile)
{//to do
int blank_space=0;
for(int i=0;i<d;i++)
{
for(int j=0;j<d;j++)
{
if(board[i][j]==blank_space)
{
//iterate to check the position of of blank tile;left to right up and down
if not return false
if( (i-1)>=0 && board[i-1][j]==tile)
{
int temp=board[i-1][j];
board[i-1][j]=board[i][j];
board[i][j]=temp;
return true;
}
if((j-1)>=0 && board[i][j-1]==tile)
{
int temp=board[i][j];
board[i][j]=board[i][j-1];
board[i][j-1]=temp;
return true;
}
if((i+1)<=(d-1) && board[i+1][j]==tile)
{
int temp=board[i][j];
board[i][j]=board[i+1][j];
board[i+1][j]=temp;
return true;
}
if((j+1)<=(d-1) && board[i][j+1]==tile)
{
int temp=board[i][j];
board[i][j]=board[i][j+1];
board[i][j+1]=temp;
return true;
}
}
}
}
return false;
}
/**
* Returns true if game is won (i.e., board is in winning configuration),
* else false.
*/
bool won(void)
{
// TODO
int checker=1;
for(int i=0;i<=d;i++)
{
for(int j=0;j<=d;j++)
{
if (checker!=board[i][j] && board[d-1][d-1]==0)
{
return false;
}
checker++;
}
}
return true;
}
{}
button to format code. It just adds four spaces in front of the selected text (or removes them if all the selected lines start with four spaces). However, it won't fix your badly indented code, just turn it into a code block with fixed-width font, preserved whitespace and some syntax highlighting. – Blauelf Sep 4 '17 at 11:23