Pregunta

I want to develop a virtual garden with a lot of kind of insects like ants, bees, etc...

For example, if I want to create an area of 10x10m².

I can implement this with ArrayList<ArrayList<Insect>> area an put all the insects in a specific position. With this approach, my space is limit of the array size, but I think that is more easy implementing A* algorithms for the behavior of insects, and of course I want to create a 10x10m² area I need to define if each position of the ArrayList is in M, CM, DM, MM, etc..., and this could use a lot of memory

Or I can implementing a int x, y; in each insect, and a class for observe where insects are in each time. With this I think that when I'll when representing the insects in a GUI It'll be easiest. so maybe with this approach use algorithms like A* for search, the shortest path between a insect and another insect is more hardest

The idea too is that you can use this as a library for implementing with a lot of type of GUI libraries.

What do you think?

Do you know another approach to this problem?

Thanks

¿Fue útil?

Solución

You give four possible resolutions. The number of positions in 10x10m² at

 m = 100 
dm = 10000
cm = 1000000
mm = 100000000

None of which are excessive. Even with mm you could still keep the positional data under a gigabyte.

Teleporting from one mm to the next is going to be hard to notice unless someone is zoomed in to far. On a digital computer you're never going to get away from this. All you can do is hide that the simulation isn't truly analog.

There are some memory saving tricks you could use. If the garden is sparsely populated it's a shame to throw a gigabyte at remembering where 5 insects are. You could make each insect an object that remembers where it is. However, this creates it's own problems. How do insects know if they're colliding with each other? Now to move each insect has to first ask every other insect where it is.

This issue is called collision detection. It has a lot of implications for the data structure you use. There are a lot of solutions here that I don't have time to talk about but just knowing the name should get you started.

If you want to get into 3D I suggest you start by reading up on Ray Casting.

Licenciado bajo: CC-BY-SA con atribución
scroll top