From 80a5445c3121b3464542e0bd849a19a523ac87b6 Mon Sep 17 00:00:00 2001 From: Jason Bou-Samra <154414066+bou-samra@users.noreply.github.com> Date: Thu, 18 Jul 2024 19:59:07 +1000 Subject: [PATCH] Create new_col.c --- src/new_col.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/new_col.c diff --git a/src/new_col.c b/src/new_col.c new file mode 100644 index 0000000..81bd309 --- /dev/null +++ b/src/new_col.c @@ -0,0 +1,22 @@ +// randomly choose from remaining available columns to drop next brick into +int new_column() { + totcol_avail = 0; + for (i = 0; i < 8; i++) { + for (j = 0; j < 18; j++) { + if (grid[0][j][i] == 0) { colcnt[i]++;} // empty space in each column + } + } + for (i = 0; i < 8; i++) { + if (colcnt[i] > 2) {totcol_avail++;} // total available columns + } + if (totcol_avail == 0) { + printf("game over\n");} else { // no more columns available + randc = randombytes_uniform(totcol_avail) + 0; // choose random number from available columns + int avl = -1; + for (i = 0; randc != avl; i++) { // translate avail column to actual column + if (colcnt[i] > 2) {avl++;} + actual_col = i; // might need to move this down to next brace + } + } + return actual_col; // return the random column +}