Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove duplicated tiles after rotations #25

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,28 @@ function setup() {
createCanvas(800, 800);

// Loaded and created the tiles
tiles[0] = new Tile(tileImages[0], ["AAA", "AAA", "AAA", "AAA"]);
tiles[1] = new Tile(tileImages[1], ["BBB", "BBB", "BBB", "BBB"]);
tiles[2] = new Tile(tileImages[2], ["BBB", "BCB", "BBB", "BBB"]);
tiles[3] = new Tile(tileImages[3], ["BBB", "BDB", "BBB", "BDB"]);
tiles[4] = new Tile(tileImages[4], ["ABB", "BCB", "BBA", "AAA"]);
tiles[5] = new Tile(tileImages[5], ["ABB", "BBB", "BBB", "BBA"]);
tiles[6] = new Tile(tileImages[6], ["BBB", "BCB", "BBB", "BCB"]);
tiles[7] = new Tile(tileImages[7], ["BDB", "BCB", "BDB", "BCB"]);
tiles[8] = new Tile(tileImages[8], ["BDB", "BBB", "BCB", "BBB"]);
tiles[9] = new Tile(tileImages[9], ["BCB", "BCB", "BBB", "BCB"]);
tiles[10] = new Tile(tileImages[10], ["BCB", "BCB", "BCB", "BCB"]);
tiles[11] = new Tile(tileImages[11], ["BCB", "BCB", "BBB", "BBB"]);
tiles[12] = new Tile(tileImages[12], ["BBB", "BCB", "BBB", "BCB"]);

for (let i = 2; i < 14; i++) {
const initialTiles = [
new Tile(tileImages[0], ["AAA", "AAA", "AAA", "AAA"]),
new Tile(tileImages[1], ["BBB", "BBB", "BBB", "BBB"]),
new Tile(tileImages[2], ["BBB", "BCB", "BBB", "BBB"]),
new Tile(tileImages[3], ["BBB", "BDB", "BBB", "BDB"]),
new Tile(tileImages[4], ["ABB", "BCB", "BBA", "AAA"]),
new Tile(tileImages[5], ["ABB", "BBB", "BBB", "BBA"]),
new Tile(tileImages[6], ["BBB", "BCB", "BBB", "BCB"]),
new Tile(tileImages[7], ["BDB", "BCB", "BDB", "BCB"]),
new Tile(tileImages[8], ["BDB", "BBB", "BCB", "BBB"]),
new Tile(tileImages[9], ["BCB", "BCB", "BBB", "BCB"]),
new Tile(tileImages[10], ["BCB", "BCB", "BCB", "BCB"]),
new Tile(tileImages[11], ["BCB", "BCB", "BBB", "BBB"]),
new Tile(tileImages[12], ["BBB", "BCB", "BBB", "BCB"]),
];

for (const tile of initialTiles) {
const rotations = [tile];
for (let j = 1; j < 4; j++) {
tiles.push(tiles[i].rotate(j));
rotations.push(tile.rotate(j));
}
tiles.push(...Tile.removeDuplicates(rotations));
}

// tiles[2] = tiles[1].rotate(1);
Expand Down
9 changes: 9 additions & 0 deletions tile.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,13 @@ class Tile {
}
return new Tile(newImg, newEdges);
}

static removeDuplicates(arrayOfTiles) {
const uniqueTilesMap = {};
for (const tile of arrayOfTiles) {
const key = tile.edges.join(","); // ex: "ABB,BCB,BBA,AAA"
uniqueTilesMap[key] = tile;
}
return Object.values(uniqueTilesMap);
}
}