From 3eb8e6086cfeebf7d85743cea3d3b17c34e87aa5 Mon Sep 17 00:00:00 2001 From: Tiehuis Date: Mon, 17 Mar 2014 18:45:32 +1300 Subject: [PATCH] Changes to the block spawning so either a 2 or 4 is spawned each turn with a 3:1 ratio --- 2048_curses.c | 4 ++-- 2048_no_curses.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/2048_curses.c b/2048_curses.c index 6a39edf..ed20983 100644 --- a/2048_curses.c +++ b/2048_curses.c @@ -182,14 +182,14 @@ int space_left() 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 */ void rand_block() { if (space_left()) { int x_p, y_p; 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 { endwin(); diff --git a/2048_no_curses.c b/2048_no_curses.c index 0b87647..956d79e 100644 --- a/2048_no_curses.c +++ b/2048_no_curses.c @@ -181,14 +181,14 @@ int space_left() 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 */ void rand_block() { if (space_left()) { int x_p, y_p; 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 { printf("\n"