Hi,
I am just learning how to program in C, so please bear with me if I'm asking really trivial questions. I'm basically writing code for a puzzle known as the 15-puzzle. The board itself is comprised of 4 rows and 4 columns, so it has a length of 16. I am currently writing the functionvoid initialize tiles() which initializes the pixel data for each tile. So it's basically supposed to look like View image: 15puzzle initially.
I'm not really sure how to approach this. I have written myself some skeleton code for what I think I should do, but a little guidance would be much appreciated! Thanks!
Code:
/*
* Initialize the pixel data of each tile.
*
* Background colors should be initialized to the following, where B = black,
* R = red, and W = white:
* W R W R
* R W R W
* W R W R
* R W R B
*
* The tiles' digits should be initialized to the following:
* 01 02 03 04
* 05 06 07 08
* 09 10 11 12
* 13 14 15
*
* the tens digit and units digit of a two-digit number n can be
* calculated as follows:
* tens_digit = n / 10
* tens_digit = n % 10
*
* Global variables used: tile_data.
*
* Functions called: initialize_tile.
*/
void initialize_tiles(int tile_data[][]){
int col, row;
/* TO DO: loop through each tile in global array: int tile_data[]
determine background color for each tile: (red or white)
determine the 2 digits to place on each tile: (01, 02, ..., 15)
determine color for the digits
once determined - call: initialize_tile() with the above info
*/
/* pseudocode:
int column, row;
int color;
int tile_index, digit1, digit2;
FOR each column on board
FOR each row on board
// calculate color for tile
IF [(column + row) % 2] = 0 THEN color = WHITE
ELSE color = RED
// calculate digits for tile
tile_index = column + row * 4
digit1 = (tile_index + 1) / 10
digit2 = (tile_index + 1) % 10
// finally, call initialize tile with data calculated above
CALL initialize_tile() with tile_index, digit1, digit2, color, BLACK
}
}
// set all pixels to BLACK for blank tile
FOR each pixel in tile
tile_data[15][pixel] = BLACK;
*/
}
do I use use color as well as tile_index, digit1, and digit2 as parameters? any help would be great, thanks!