Draft

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.

(hover over the tiles to hide numbers)

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

  1. There are 100 random tests
  2. 2 < N < 30
  3. 2 < M < 30
  4. There are no tiles outside the given map, thus, the bordering tiles shouldn't connect to anything beyond the map.

More By Author:

Check out these other kata created by оkabe

Stats:

CreatedMar 14, 2023
Warriors Trained24
Total Skips0
Total Code Submissions43
Total Times Completed8
Python Completions8
Total Stars4
% of votes with a positive feedback rating100% of 5
Total "Very Satisfied" Votes5
Total "Somewhat Satisfied" Votes0
Total "Not Satisfied" Votes0
Total Rank Assessments5
Average Assessed Rank
5 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
6 kyu
Ad
Contributors
  • оkabe Avatar
Ad