Author Topic: Making small rectangles inside of a larger one.  (Read 3588 times)

0 Members and 1 Guest are viewing this topic.

Offline Pixel_Outlaw

  • Pentium
  • *****
  • Posts: 1382
  • Karma: 83
    • View Profile
I'm just about done with my dungeon generator but I'm really stuck with adding rooms.

I'm using my own methods and I just need the last piece to the puzzle. That piece is creating rooms inside an array.

Basically I need an array. This array has the value 0 at cells that don't have any room in them and 1 for cells that would have a room in them. Room cells (1) are shown here as blue cells. Also no two rooms may touch, meaning that rooms need a 1 cell border between them. I just can't quite envision how this would be done. There should be a max number of rooms (once reached no more rooms are added). Also it would need to have a max room size and a minium room size. This is a very complex problem for me. Does anyone see any good methods?

« Last Edit: May 11, 2008 by Pixel_Outlaw »
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Making small rectangles inside of a larger one.
« Reply #1 on: May 11, 2008 »
You've picked another reasonably hard problem ;)   There's no 'best' solution to this, so you have to pick something that will work.  In general this problem is called 'the napsack problem'.  So you can ask google about that.

Do you know the room sizes and land size before you start?

If you do, then I have some stuff I used for Soduku and Boggle solving that might help - recursive stuff where you add one of the rooms and then pass the state down to an algorithm that knows where best to place new rooms.

Jim
Challenge Trophies Won:

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: Making small rectangles inside of a larger one.
« Reply #2 on: May 11, 2008 »
Dont know if this will work but it may be worth a shot. Go through though array and look for junctions, decide randomly whether this junction is going to become a room or just remain a junction. Once thats done for all junctions use the length of the passage that the junctions lie apon half the length minus a random number this gives you a length in one dimension, the rooms wont overlap for the most part, they will be like an overlay on top of the passages. if rooms do overlap they will combine to form non rectangular rooms

Challenge Trophies Won:

Offline Pixel_Outlaw

  • Pentium
  • *****
  • Posts: 1382
  • Karma: 83
    • View Profile
Re: Making small rectangles inside of a larger one.
« Reply #3 on: May 12, 2008 »
I know that you probably have a good idea rain_storm but what do you mean by junctions?
Challenge Trophies Won:

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: Making small rectangles inside of a larger one.
« Reply #4 on: May 12, 2008 »
I was assuming that you wanted to modify your maze generator to do this, was I mistaken?

Challenge Trophies Won:

Offline Pixel_Outlaw

  • Pentium
  • *****
  • Posts: 1382
  • Karma: 83
    • View Profile
Re: Making small rectangles inside of a larger one.
« Reply #5 on: May 12, 2008 »
Well this is for the maze generator yes but also I wanted to try using the A* algorithm to connect rooms. So the answer is yes but not specifically.
Challenge Trophies Won: