-2

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

closed as too broad by gnat, Jörg W Mittag, Useless, Bart van Ingen Schenau, BobDalgleish Mar 15 at 14:08

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    As written, this is overly broad. Please edit your question and focus on a specific question. Are you trying to identify approaches for tracking objects through a given space? And your mentioning of bees would imply three dimensions, not just two. – GlenH7 Mar 15 at 12:07
  • 3
    I think you first need to model the problem you want to solve properly. Something like an A* search makes only sense if you have something like a location graph of your garden, and things like obstacles or different terain (which should be mostly independent from the idea of having insects in there). So first, you make a decision if, for example, you want your locations to be restricted to a quadratic raster of a certain resolution, or if you prefer a continous model. Then you pick a suitable data structure for this. ... – Doc Brown Mar 15 at 12:37
  • ... Currently, it seems you try it the other way round, use some data structures you heard of and try to shoehorn your garden model into these data structures. I doubt that order of approaching the problem will work well. – Doc Brown Mar 15 at 12:41
  • 3
    And the general answer, as Doc Brown made perfectly clear IMO, is that the solution depends on what you want your rocks and insects to do, how they interact with the terrain, what sort of terrain you have, etc. Your ArrayList solution is modelling it as a giant chess board, which means insects must teleport from one discrete square to the next. Is that OK? I don't know and I'm not sure you do either. You have to decide what behaviour you want to model, not just what objects will exist. – Useless Mar 15 at 13:02
  • 1
    This sounds like a perfect use for a game engine. – Adam B Mar 15 at 14:52
2

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.