aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/main.c b/src/main.c
index 59a1fc0..13c2ed1 100644
--- a/src/main.c
+++ b/src/main.c
@@ -63,32 +63,31 @@ void collapse_this(int i)
exit(EXIT_FAILURE);
}
- // this bad
- int n = 0;
- do {
- n = rand() % TILES;
- if(!(is_set(i, n)))
- continue;
+ small_t possibilities[TILES];
+ size_t psz = 0;
- collapse(i, n);
- } while(!(has_collapsed(i)));
+ for(size_t n = 0; n < TILES; n++)
+ if(is_set(i, n)) possibilities[psz++] = n;
+
+ size_t t = possibilities[rand() % psz];
+ collapse(i, t); // collapse a random tile
// apply a bitmask, based on the direction
if(i / SWIDTH != 0) // up
if(!(has_collapsed(i-SWIDTH)))
- mask(i-SWIDTH, n, 0);
+ mask(i-SWIDTH, t, 0);
if(i % SWIDTH != (SWIDTH - 1)) // right
if(!(has_collapsed(i+1)))
- mask(i+1, n, 1);
+ mask(i+1, t, 1);
if(i % SWIDTH != 0) // left
if(!(has_collapsed(i-1)))
- mask(i-1, n, 2);
+ mask(i-1, t, 2);
if(i / SWIDTH != (SHEIGHT - 1)) // down
if(!(has_collapsed(i+SWIDTH)))
- mask(i+SWIDTH, n, 3);
+ mask(i+SWIDTH, t, 3);
}
void manage_arguments(int argc, char **argv)
@@ -132,6 +131,7 @@ error:
int main(int argc, char **argv)
{
+ // SEED = 4;
SEED = time(0);
manage_arguments(argc, argv);