Wave function collapse: Difference between revisions
Content added Content deleted
m (→{{header|C}}: hopefully easier to read now) |
m (→{{header|C}}) |
||
Line 45: | Line 45: | ||
char *wfc(char *blocks, int *bdim /* 5,3,3 */, int *tdim /* 8,8 */) { |
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 N= tdim[0]*tdim[1], td0= tdim[0], td1= tdim[1]; |
||
int *adj= calloc(N*4, sizeof (int)); |
int *adj= calloc(N*4, sizeof (int)); /* indices in R of the four adjacent blocks */ |
||
for (int i= 0; i<td0; i++) { |
for (int i= 0; i<td0; i++) { |
||
for (int j=0; j<td1; j++) { |
for (int j=0; j<td1; j++) { |
||
Line 55: | Line 55: | ||
} |
} |
||
int bd0= bdim[0], bd1= bdim[1], bd2= bdim[2]; |
int bd0= bdim[0], bd1= bdim[1], bd2= bdim[2]; |
||
char *horz= malloc(bd0*bd0); |
char *horz= malloc(bd0*bd0); /* blocks which can sit next to each other horizontally */ |
||
for (int i= 0; i<bd0; i++) { |
for (int i= 0; i<bd0; i++) { |
||
for (int j= 0; j<bd0; j++) { |
for (int j= 0; j<bd0; j++) { |
||
Line 66: | Line 66: | ||
} |
} |
||
} |
} |
||
char *vert= malloc(bd0*bd0); |
char *vert= malloc(bd0*bd0); /* blocks which can sit next to each other vertically */ |
||
for (int i= 0; i<bd0; i++) { |
for (int i= 0; i<bd0; i++) { |
||
for (int j= 0; j<bd0; j++) { |
for (int j= 0; j<bd0; j++) { |
||
Line 78: | Line 78: | ||
} |
} |
||
} |
} |
||
char *allow= malloc(4*(bd0+1)*bd0); |
char *allow= malloc(4*(bd0+1)*bd0); /* all block constraints, based on neighbors */ |
||
memset(allow, 1, 4*(bd0+1)*bd0); |
memset(allow, 1, 4*(bd0+1)*bd0); |
||
for (int i= 0; i<bd0; i++) { |
for (int i= 0; i<bd0; i++) { |
||
Line 90: | Line 90: | ||
free(horz); |
free(horz); |
||
free(vert); |
free(vert); |
||
⚫ | |||
int *todo= calloc(N, sizeof (int)); |
int *todo= calloc(N, sizeof (int)); |
||
char *wave= malloc(N*bd0); |
char *wave= malloc(N*bd0); |
||
Line 97: | Line 96: | ||
int min; |
int min; |
||
int *possible= calloc(bd0, sizeof (int)); |
int *possible= calloc(bd0, sizeof (int)); |
||
⚫ | |||
for (int i= 0; i<N; i++) R[i]= bd0; |
for (int i= 0; i<N; i++) R[i]= bd0; |
||
while (1) { |
while (1) { |