B
B
bootch2011-08-03 22:43:04
Data Structures
bootch, 2011-08-03 22:43:04

What structure should be used to store a map of playing fields with complex borders?

There is a map of playing fields (see pic). There is an active field. You can move through any blue border. You can't move through the red ones.
33c6f904.png
The question is how to store this in memory? There will be a large number of fields (several hundred thousand), resource requirements are high. In principle, to store a map, it is enough to simply write down the coordinates of the upper right corners (this will completely determine it, although the question of red / blue borders remains), but then moving between fields will consume a lot of resources.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
T
TheHorse, 2011-08-03
@bootch

Cell: struct {
x, y, height, width: float/double/int/bool (joked about bool)
neighbors: list of cell;
isLeftRed, isRightRed, itTopRed, isBottomRed: bool;
}
Each cell stores information about its position, links to neighbors and a set of parameters indicating the admissibility of crossing a specific border (not shown in the example, and I hope that there are no cases when for some cell one of the borders can be crossed only in a specific position ).
According to this structure, you can easily and quickly determine where you can go, where you can’t. It is not difficult to optimize the structure for less OP consumption by compressing all the parameters into a certain set of bytes.
And then a very large map can fit into 10 mb, which, I believe, is a sufficient result.

E
ertaquo, 2011-08-04
@ertaquo

Maybe just lines? Line intersections are quite easy to check, and it will be more flexible - it will be possible to build any shapes, not just rectangles.

R
ramilexe, 2011-08-03
@ramilexe

Can only store red borders? Those through which it is forbidden to walk.

V
Vitaly Zheltyakov, 2011-08-04
@VitaZheltyakov

No need to invent bicycles, use the standard scheme:
- A map with borders to the php file. Contact directly, no search required. Each cell has its own serial number, the parameters of the possibility of movement and communication with other cells.
- The position of objects on the map (and players too) in memcached, it is possible with duplication in the database.
— Profit

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question