Update new_col.c

This commit is contained in:
Jason Bou-Samra
2024-07-18 20:18:35 +10:00
committed by GitHub
parent c8e6eb91ee
commit 97b9aa4456
+3 -3
View File
@@ -3,17 +3,17 @@ int new_column() {
totcol_avail = 0; totcol_avail = 0;
for (i = 0; i < 8; i++) { for (i = 0; i < 8; i++) {
for (j = 0; j < 18; j++) { for (j = 0; j < 18; j++) {
if (grid[0][j][i] == 0) { colcnt[i]++;} // empty space in each column if (grid[0][j][i] == 0) { colcnt[i]++;} // count empty spaces in each column
} }
} }
for (i = 0; i < 8; i++) { for (i = 0; i < 8; i++) {
if (colcnt[i] > 2) {totcol_avail++;} // total available columns if (colcnt[i] > 2) {totcol_avail++;} // count total available columns
} }
if (totcol_avail == 0) { if (totcol_avail == 0) {
printf("game over\n");} else { // no more columns available printf("game over\n");} else { // no more columns available
randc = randombytes_uniform(totcol_avail) + 0; // choose random number from available columns randc = randombytes_uniform(totcol_avail) + 0; // choose random number from available columns
int avl = -1; int avl = -1;
for (i = 0; randc != avl; i++) { // translate avail column to actual column for (i = 0; randc != avl; i++) { // translate random num from avail column to actual column
if (colcnt[i] > 2) {avl++;} if (colcnt[i] > 2) {avl++;}
actual_col = i; // might need to move this down to next brace actual_col = i; // might need to move this down to next brace
} }