Autotile
Description:
(hover your mouse over section headers)
You can skip this section if you are familiar with tiled graphics. INTRODUCTION
There are lots of 2D video games that use tiled graphics, which is a type of graphics, where the world is broken down into squares, N x N pixels, and each square has a texture, one of many N x N textures from a tileset


To speed up the creation of game maps/levels, autotiles were invented. With these, you can paint arbitrary shapes without switching tiles for corners, sides, etc. The program will do it automatically.




HOW DO AUTOTILES WORK The game engine smartly decides which tile should be placed and extracts it from a bigger texture with all possible cases.
Autotile itself is a big texture with all possible cases of tile placement. Each game engine has its own rules on how user should assemble their autotiles, but in this kata we will work with a layout that Godot game engine uses.


There are 47 different cases. The game engine picks a region from this texture and paints it where it belongs on your shape. Values from 1 to 47 are chosen according to tile surroundings. After a tile is placed, it should organically connect to other neighboring tiles. In the example, purple color represents the edge of a tile (and the shape that will be formed), whereas red represents the main part of the tile.
WHAT TO DO Create a function that takes a string that represents the game map and return a corresponding array of ints that represent tile cases.
Create a function autotile(grid)
Its argument is a string that represents a shape (or shapes) on a map of size N x M
, where X
is painted with autotile and .
is not.
Example Input:
..XX...
.XXXXX.
...XX..
....X..
Example Output:
[[0, 0, 1, 3, 0, 0, 0],
[0, 32, 38, 10, 6, 34, 0],
[0, 0, 0, 21, 18, 0, 0],
[0, 0, 0, 0, 24, 0, 0]]
You will have to return an array of size N x M
of integers from 1 to 47 that represent which case certain tiles belong to. Replace empty tiles with 0.
NOTES
- There are 100 random tests
- 2 < N < 30
- 2 < M < 30
- There are no tiles outside the given map, thus, the bordering tiles shouldn't connect to anything beyond the map.
Stats:
Created | Mar 14, 2023 |
Warriors Trained | 24 |
Total Skips | 0 |
Total Code Submissions | 43 |
Total Times Completed | 8 |
Python Completions | 8 |
Total Stars | 4 |
% of votes with a positive feedback rating | 100% of 5 |
Total "Very Satisfied" Votes | 5 |
Total "Somewhat Satisfied" Votes | 0 |
Total "Not Satisfied" Votes | 0 |
Total Rank Assessments | 5 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 6 kyu |