# Algorithm for tiling a surface with no adjacent tiles

I am looking for an algorithm that does as follows:

Given a 2D grid of X,Y and a number of tiles T, places a tile in each cell of the grid such that the surrounding tiles are not the same.

This should also ideally be capable of providing a random seed to randomize the output.

I understand that for not all values of X, Y and T this is possible, but is there an existing algorithm that will do what I'm looking for? I'm currently using a naive hand-rolled implementation that doesn't always provide the best results.

Is something like a constraint solver what I need?

• What do you mean by "best results?" How large are these grids? Commented Oct 16, 2014 at 17:10
• "Not best results" in that sometimes adjacent tiles appear. The grid can be any size, i.e. user-defined. Commented Oct 16, 2014 at 20:09
• Sounds like a Coloring problem. There is a lot of research and options as to how to solve them.
– Sign
Commented Oct 17, 2014 at 19:55
• I don't think I understand the question. If you want a grid to be tiled with non-adjacent tiles, just use a checkerboard pattern. What am I not seeing? Commented Oct 17, 2014 at 22:17
• The pattern needs to be random. Think tiling a surface in a 3D scene with different tiles in order to hide repeating patterns. Along those lines. Commented Oct 20, 2014 at 0:27