Regarding the blank tile in Game of Fifteen, can I avoid using a variable for the blank? In other words, can I just print an underscore when I reach zero in my array?
Welcome to SE, first of all. Now, for your problem, think that when you had made the draw function for the GoF, there you were printing the values of the tile using printf, so using that very printf's and one added if condition, you can do that, see the pseudo code below for printing the _(underscore) or a number as required
If(board[i][j] == 0)
{
printf(" _\n");
}
else if(board[i][j] < 0)
{
printf("%d\n", board[i][j]);
}
That's it, you're done. As for explanations, we check if the variable in the array is 0( or not) and in case, it is, we simply print the character " _" ie a space followed by an underscore.
Now that you know what to do and how to do it, I think you'll be able to implement it easily enough.
Happy Coding!
-
1
-
Wait, do we use printf("%2d", board[i][j]); or %d as above??? I'm confused... (stuck in PSET3 currently) – Happytreat Dec 11 '14 at 1:50
I think it's a bad idea to take board[i][j] = 0
for the blank tile. I took board[i][j] = 100
and it works!
You don't really have to use a variable to store the character for the blank tile. You may print it directly if some condition is met.
if this current value is 0
print an underscore