Wave function collapse: Difference between revisions

m
m (→‎{{header|C}}: hopefully easier to read now)
Line 45:
char *wfc(char *blocks, int *bdim /* 5,3,3 */, int *tdim /* 8,8 */) {
int N= tdim[0]*tdim[1], td0= tdim[0], td1= tdim[1];
int *adj= calloc(N*4, sizeof (int)); /* indices in R of the four adjacent blocks */
for (int i= 0; i<td0; i++) {
for (int j=0; j<td1; j++) {
Line 55:
}
int bd0= bdim[0], bd1= bdim[1], bd2= bdim[2];
char *horz= malloc(bd0*bd0); /* blocks which can sit next to each other horizontally */
for (int i= 0; i<bd0; i++) {
for (int j= 0; j<bd0; j++) {
Line 66:
}
}
char *vert= malloc(bd0*bd0); /* blocks which can sit next to each other vertically */
for (int i= 0; i<bd0; i++) {
for (int j= 0; j<bd0; j++) {
Line 78:
}
}
char *allow= malloc(4*(bd0+1)*bd0); /* all block constraints, based on neighbors */
memset(allow, 1, 4*(bd0+1)*bd0);
for (int i= 0; i<bd0; i++) {
Line 90:
free(horz);
free(vert);
int *R= calloc(N, sizeof (int));
int *todo= calloc(N, sizeof (int));
char *wave= malloc(N*bd0);
Line 97 ⟶ 96:
int min;
int *possible= calloc(bd0, sizeof (int));
int *R= calloc(N, sizeof (int)); /* tile expressed as list of block indices */
for (int i= 0; i<N; i++) R[i]= bd0;
while (1) {
6,962

edits