# Filling a room with random furniture

This is a rather complex question and I'm more hoping for general algorithms anyone might have heard of.

I wish to generate randomly sized rooms. Each of these rooms has a type and a corresponding list of furniture to be placed inside it (ie: kitchens can have fridges, both kitchens and living rooms can have TVs, etc). Each piece of furniture has it's own collider (cylinder, cube, mesh...). Are there any good algorithms to randomly lay them out?

The best idea I've managed so far is to subdivide the room into a grid the size of the smallest piece available. Then I would randomly place the furniture until every grid square is at least partially filled. However, this is hardly ideal and the rooms would more or less look like warehouses.

[Optional]How do I randomly place the furniture in such a way as to make it at least look slightly realistic?

I had to solve a similar problem for my game. I did it using templates. Basically, start by labeling your room with the following:

enum TileState
{
Floor, // An unoccupied free cell
Wall,  // A cell occupied by a wall
Edge,  // An unoccupied cell on the edge of the room (like a door)
Object // A cell occupied by an object
}


Then, you can create templates sort of like this:

// This template corresponds to an object in the corner.
TileState[][] cornertemplate = { { Wall,  Wall},
{ Wall, Object} };


Now, you can try a bunch of random x, y locations and rotations of the template, and see if the template is valid. In this context, a template is valid whenever all the Wall tiles are occupied by a wall, and all of the Object tiles are currently free (either Floor or Edge). Whenever the template is valid, create an object at the appropriate place.

You can make more complicated templates by overlaying them on top of each other, or stringing them together. For instance, you can require a chair always be next to a table. Here is a room I generated using this approach:

In this case, the tables had a template that required all the space around them to be free of walls. The bookshelves had to be up against at least one wall, and the lamps had to be in corners.

• @PedroCaetano www.dwarfcorp.com – mklingen Apr 16 '15 at 16:56
• Nice game! I watched the video. You (or someone else) talked about releasing the new alpha to the backers. So I presume there is no way in testing it out for me, since I didn't back and the campaign ended? – Martijn Courteaux May 31 '15 at 8:16