How to represent a two-dimensional orthogonal grid (Python)

Basically, I have a set of "rooms" (user class). All rooms are connected, and each room is defined in relation to one or more other rooms. I am looking for some system to organize these rooms in a 2D grid and designate an arbitrary room as a source.

class room(exits={}) : #Other code in here, not relevant exits = {} room_list = {} room_list['room_1'] = room(exits={'north':'room_2'}) room_list['room_2'] = room(exits={'south':'room_1','west':'room_3'}) room_list['room_3'] = room(exits={'east':'room_2'}) 

Therefore, I would like to somehow represent these rooms in a grid, except for just the connection between the rooms.

+4
source share
1 answer

Although the question is not very clear, it seems that you need something like GraphViz [1]. This is basically a block diagram layout automation program that is completely isomorphic to your problem. There is a Python interface PyGraphViz [2], which may be useful to you.

If you want to create your own layout engine (comparable to GraphViz), make sure that you check the multidimensional scaling algorithm [3], which is used by the neato component of GraphViz.

[1] http://www.graphviz.org/

[2] http://networkx.lanl.gov/pygraphviz/

[3] http://en.wikipedia.org/wiki/Multidimensional_scaling

I can give more focused help if you provide more detailed information about the problem. An approximate drawing (sketch) of what you want to get will be good.

+2
source

Source: https://habr.com/ru/post/1336734/


All Articles