diff --git a/src/experimental/_impl/_tiles_wfc_impl.scad b/src/experimental/_impl/_tiles_wfc_impl.scad index 96ff60d8..f9b21f23 100644 --- a/src/experimental/_impl/_tiles_wfc_impl.scad +++ b/src/experimental/_impl/_tiles_wfc_impl.scad @@ -1,6 +1,5 @@ use ; use ; -use ; use ; use ; use ; @@ -33,7 +32,6 @@ function _weights_of_tiles(weights, symbols, leng, i = 0) = - wf_weights(wf) - wf_eigenstates(wf) - wf_eigenstates_at(wf, x, y) - - wf_is_all_collapsed(wf, notCollaspedCoords) - wf_collapse(wf, x, y) - wf_entropy(wf, x, y) - wf_coord_min_entropy(wf, notCollaspedCoords) @@ -55,14 +53,6 @@ function wf_weights(wf) = wf[2]; function wf_eigenstates(wf) = wf[3]; function wf_eigenstates_at(wf, x, y) = wf_eigenstates(wf)[y][x]; -function wf_is_all_collapsed(wf, notCollaspedCoords) = - is_undef(notCollaspedCoords) ? - every( - wf_eigenstates(wf), - function(row) every(row, function(states) len(states) == 1) - ) : - every(notCollaspedCoords, function(coord) len(wf_eigenstates_at(wf, coord.x, coord.y)) == 1); - function wf_collapse(wf, x, y) = let( weights = wf_weights(wf), @@ -125,12 +115,11 @@ function wf_not_collapsed_coords(wf, notCollaspedCoords) = function wf_coord_min_entropy(wf, notCollaspedCoords) = let( - coords = wf_not_collapsed_coords(wf, notCollaspedCoords), - entropyCoord = coords[0], + entropyCoord = notCollaspedCoords[0], entropy = wf_entropy(wf, entropyCoord.x, entropyCoord.y) - (rand() / 1000), - min_coord = _wf_coord_min_entropy(wf, coords, len(coords), entropy, entropyCoord) + min_coord = _wf_coord_min_entropy(wf, notCollaspedCoords, len(notCollaspedCoords), entropy, entropyCoord) ) - [min_coord, coords]; + min_coord; function _wf_coord_min_entropy(wf, coords, coords_leng, entropy, entropyCoord, i = 1) = i == coords_leng ? entropyCoord : @@ -220,18 +209,19 @@ function _doDirs(tm, stack, cx, cy, current_tiles, dirs, leng, i = 0) = function tilemap_generate(tm, notCollaspedCoords) = let(wf = tilemap_wf(tm)) - wf_is_all_collapsed(wf, notCollaspedCoords) ? collapsed_tiles(wf) : + len(notCollaspedCoords) == 0 ? collapsed_tiles(wf) : let( - coord_notCollaspedCoords = wf_coord_min_entropy(wf, notCollaspedCoords), - x = coord_notCollaspedCoords[0].x, - y = coord_notCollaspedCoords[0].y - ) - tilemap_generate(tilemap_propagate([ + min_coord = wf_coord_min_entropy(wf, notCollaspedCoords), + x = min_coord.x, + y = min_coord.y, + ntm = tilemap_propagate([ tilemap_width(tm), tilemap_height(tm), tilemap_compatibilities(tm), wf_collapse(wf, x, y) - ], x, y), coord_notCollaspedCoords[1]); + ], x, y) + ) + tilemap_generate(ntm, wf_not_collapsed_coords(tilemap_wf(ntm))); function neighbor_dirs(x, y, width, height) = [ diff --git a/src/experimental/tile_wfc.scad b/src/experimental/tile_wfc.scad index 91155f83..905fc374 100644 --- a/src/experimental/tile_wfc.scad +++ b/src/experimental/tile_wfc.scad @@ -5,7 +5,6 @@ use <../util/rand.scad>; function tile_wfc(size, sample) = let( tm = tilemap(size[0], size[1], sample), - wf = tilemap_wf(tm), // random start x = floor(rand(size[0] * 0.25, size[0] * 0.75)), y = floor(rand(size[1] * 0.25, size[1] * 0.75)), @@ -13,10 +12,11 @@ function tile_wfc(size, sample) = tilemap_width(tm), tilemap_height(tm), tilemap_compatibilities(tm), - wf_collapse(wf, x, y) - ], x, y) + wf_collapse(tilemap_wf(tm), x, y) + ], x, y), + notCollapsedCoords = wf_not_collapsed_coords(tilemap_wf(first_collasped_propagated)) ) - tilemap_generate(first_collasped_propagated); + tilemap_generate(first_collasped_propagated, notCollapsedCoords); /*