CodingTrain / CodingTrain/Wave-Function-Collapse

Simple way to remove duplicated tiles to improve performance

Open
#24 6 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
218
Forks
64
PR merge metrics
No merged PRs in 30d

Description

Hi :smiley: We can write a function to get only the unique tiles in an array :

```js
function removeDuplicatedTiles(tiles) {
const uniqueTilesMap = {};
for (const tile of tiles) {
const key = tile.edges.join(","); // ex: "ABB,BCB,BBA,AAA"
uniqueTilesMap[key] = tile;
}
return Object.values(uniqueTilesMap);
}
```

So we can apply rotations to all the tiles and then keep only the unique ones :
```js
const initialTileCount = tiles.length;
for (let i = 0; i < initialTileCount; i++) {
for (let j = 1; j < 4; j++) {
tiles.push(tiles[i].rotate(j));
}
}
tiles = removeDuplicatedTiles(tiles);
```

In our case, we have **13** images. By rotating all of them, we get **52**. And by removing the duplicates, we get down to **33**.

On my PC, the generation time goes from **23s** to **14s** :rocket:

Contributor guide

No contributing guide indexed for this repository

Research direction

No files or tests are named. Start by locating the tile-generation and rotation logic, then compare the current tile counts and generation time with the proposed deduplication step; done means duplicate rotated tiles are removed without changing the resulting unique tile set.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
performance
Issue type
Refactor
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.