0

This question is part of a procedural generated dungeon algorithm I'm trying. I want to randomly generate a graph (representing rooms and corridors), assign size to each vertices/rooms and plot them on a 2d plane. One requirement is I don't want the edges/corridors to overlap with rooms. Example pic

I have no idea how to place these rooms without knowing their spatial relationship first.

陳冠曄
  • 9
  • 1

1 Answers1

2

This is a broad question. Probably too broad for StackOverflow but I can give you a few ideas.

If you don't want the corridors to overlap then you need to randomly generate a planar graph. One way to do this (among many ways) would be to randomly generate points, find the Delaunay triangulation of the points, and let the vertices of the triangulation be the rooms and the edges of the triangles be the corridors.

Once you have a planar graph laying it out as a 2D dungeon is a problem in the domain of graph drawing algorithms. There are many graph drawing algorithms for many kinds of graph drawings, e.g. orthogonal graph drawings, etc. You would do well to explore this literature.

If you generate your graph via Delaunay triangulation as I suggested above, one graph drawing will be implied by the triangulation. You may need to scale up the triangulation relative to the size of the rooms you want, but it will always be possible to do so if you do not mind arbitrarily long corridors. It won't look much like a dungeon but you may be able to tweak it until it does via heuristics. Or choose another graph drawing algorithm.

jwezorek
  • 8,592
  • 1
  • 29
  • 46