Changes to the block spawning so either a 2 or 4 is spawned each turn with a 3:1 ratio

This commit is contained in:
Tiehuis 2014-03-17 18:45:32 +13:00
parent d10bf180ca
commit 3eb8e6086c
2 changed files with 4 additions and 4 deletions

View File

@ -182,14 +182,14 @@ int space_left()
return 0; return 0;
} }
/* places a random block onto the grid */ /* places a random block onto the grid - either a 4, or a 2 with a chance of 1:3 respectively */
/* could do this in a much smarter fashion by finding which spaces are free */ /* could do this in a much smarter fashion by finding which spaces are free */
void rand_block() void rand_block()
{ {
if (space_left()) { if (space_left()) {
int x_p, y_p; int x_p, y_p;
while (g[x_p = rand() % SZ][y_p = rand() % SZ]); while (g[x_p = rand() % SZ][y_p = rand() % SZ]);
g[x_p][y_p] = 2; g[x_p][y_p] = (rand() & 3) ? 2 : 4;
} }
else { else {
endwin(); endwin();

View File

@ -181,14 +181,14 @@ int space_left()
return 0; return 0;
} }
/* places a random block onto the grid */ /* places a random block onto the grid - either a 4, or a 2 with a ratio of 1:3 respectively */
/* do this in a smarter fashion */ /* do this in a smarter fashion */
void rand_block() void rand_block()
{ {
if (space_left()) { if (space_left()) {
int x_p, y_p; int x_p, y_p;
while (g[x_p = rand() % SZ][y_p = rand() % SZ]); while (g[x_p = rand() % SZ][y_p = rand() % SZ]);
g[x_p][y_p] = 2; g[x_p][y_p] = (rand() & 3) ? 2 : 4;
} }
else { else {
printf("\n" printf("\n"