>> ZAMYLA CHAN: Let's have fun with 15.
15 is the first game that you get to implement.
And it's interactive.
Now, not to worry.
You don't have to write the whole thing yourself.
>> Look at the distribution code.
Because a lot of the game structure is already set up for you.
It accepts and parses a command line argument from the user, and creates a
board based on that input.
>> It checks if the game is won, and exits once the user's won the game.
And to win the game, it gets input from the user and
calls the move function.
So we're going to be implementing four functions for the game of 15--
init, draw, move, and won.
>> First, let's tackle init.
In init, for initialize, we represent the board in a 2D integer array.
And this is a global variable called board with dimensions max and max, the
maximum dimensions of the board.
Now, the actual dimension of the board is given by the user, represented in
the integer d, which could be less than max.
But in C, you can't resize arrays.
So you're stuck with that maximum dimension.
>> Your job in init is to populate the values of the board
with the correct values.
Now, we've seen 1D arrays.
But how do 2D arrays work?
There's an index of the row, 0 index, as always, and
then also of the column.
>> And you'll fill your grid in in descending values, just like this.
Grid 0, 0, row 0, column 0, is 8.
Grid 0, 1 is 7.
This is for an example where d, little d, is 3.
Now, the board in 15 must also contain a blank tile, if you've ever played
with the physical game.
>> But board is an integer array.
So all values have to be integers.
So it's up to you to decide an integer value to represent a blank tile.
>> To initialize your board, you can use loop structures to contain the
starting state of the board, where board i, j represents the element at
row i and column j.
They start in descending order.
And remember that if the number of tiles is odd, then you're going to
have to swap the location of 2 and of 1.
So there we have our initialized board.