CodingTrain / CodingTrain/Wave-Function-Collapse

Simple way to remove duplicated tiles to improve performance

オープン
#24 コメント 6 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
JavaScript
スター
218
フォーク
64
PR マージ指標
30日以内にマージされた PR はありません

説明

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:

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

調査の方向性

ファイルやテストは指定されていません。まず tile の生成および回転のロジックを特定し、現在の tile 数と生成時間を、提案されている重複排除処理と比較します。重複する回転済み tile が削除され、結果として得られる一意な tile の集合が変わらなければ完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
javascript
領域
performance
issue の種類
リファクタリング
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。