The puzzle depends on a two-dimensional map in memory of values ranging from one to four (zero is a blank space.) There are no blanks in an initialization. When I initialize the game, I use a for loop that iterates through the map and places a value from one to four in each cell. If the chosen value is zero, it simply substitutes the arbitrary constant of 3.
The problem is, the random() function in SGDK appears to generate the same results with every call. I've tried two different emulators, which do give differing results, but the same results every time I reset the console. Is this to be expected?
Here is a screenshot of the game so far. It's nothing more than a simple test board. These same values appear on the board with every bootup in the respective emulators.
My main question is if I'm using the random() function properly or if there were something else I was supposed to do beforehand, or if this is expected behavior. If so, how could I make a small pseudorandom routine that yields varied values on every board refresh?
Here is the relevant piece of code:
Code: Select all
int x;
int y;
int c;
for (x = 0; x != BOARD_X; x++) {
for (y = 0; y != BOARD_Y; y++) {
c = random() % 4;
if (c != 0) { board[x][y].id = c; } else { board[x][y].id = 3; }
board[x][y].selected = 0;
}
}