Best way to represent (store ) area of a region - java

Well I am developing a simulation where agents in tribes (groups) can compete for how much of the area they own in a map of a fixed size.(The map is 2D map). They compete through fighting with each other in groups and the winning group gets the owned by the other group.This simulation is written in java.
The main issue I am trying to get some ideas towards is how should I store how much of the map each group owns.At first I though of just using an instance of Dimension where it then each time a group of agents wins over an area it adds it to the Dimension.The issue however is that areas owned can be in any position in the map with gaps in-between areas as it can be seen in the picture below.(Sorry for the poor picture,was trying to draw the problem using gimp)
NOTE: The rectangles of different colours represent the areas owned by the agents whereas the circles in violet are the agents themselves.
Now another idea was to have an ArrayList of Dimension types holding all the area owned of the agents of specific tribe.
But I am thinking whether there is a better way to do this.

There's a one-to-many (technically a one-to-zero-or-many) relationship between each tribe and how many regions are owned by that tribe. You have 3 basic choices for representing any one-to-many relationship.
1. You can place a reference in each child to the parent
2. You can manage a list of children in each parent
3. You can manage a list of parent-child pairings separately
The question I'd ask yourself is what results are you trying to derive from your simulation? Start from there and work backwards. For example, if your goal is a report by tribe of what is owned, then it may be most efficient to manage a list of regions inside each tribe object. If your goal is a report of regions showing who owns each, then it may be simpler to reference the owning tribe inside the object of each region. It may also be reasonable to manage in both places if you're supporting multiple views.
The third option, managing the relationships outside of the objects themselves, is most useful for times when many-to-many relationships might also be supported, like allowing players to be members of multiple tribes.

if i can suggest you something, when i was working while ago on some graph related stuff, in one of papers i found idea how to convert graph to a map, sorry i cant remember title of that paper
but what i remember, is they were using voronoi diagram,
in this case you can store your map data as set of objects which holds coordinates of action performed by agent and team id
you can also introduces sales vlume, which might be used for resolving conflicts for ovrlaping area (90% sales in region belongs to A, so 90% region will be given to them as well)

Related

How to load a specific object from a SER-file

I'm saving my game world using serialization. The world is basically a big ArrayList containing each area map object. The number of area maps is fixed, but they vary greatly in size (between 5-30 mB each). So I don't want to have the entire world loaded in memory during runtime, only the specific area maps that the player's characters are located in.
Is it possible to load specific area maps without loading the entire world (or in other words: loading a specific object without deserializing the whole SER-file)? Likewise I need to save specific area maps (when all characters have left the area). Note that the size (in data) of the area map could have changed significantly, since the player could potentially move hundreds of objects from one area to another.
The point of this question is that I want to avoid storing each map in it's own SER-file. That would be A LOT of files, which will become even more with each save the player has. So my goal is to pack it up nicely in a single save-file.
What you could do is create a numbering system for each of your area maps. Afterwards, store an array containing these area maps in a serializable. Unload the serializable to obtain an array, and store it in some form of variable. You could then use your numbering system to select the map which you would want to use.
So to answer your question, I do not think it is possible, because the way a serializable is deserialized is it goes through all the serialized fields one by one. You cannot select something from the middle of a SER-file to deserialize.
Happy Programming :)

Options for storing huge tile map

I am creating a pseudo-turn-based online strategy browser game where many people play in the same world over a long period(months). For this, I want to have a map of 64000x64000 tiles = 4 billion tiles. I need about 6-10 bytes of data per tile, making up a total of around 30GB of data for storing the map.
Each tile should have properties such as type(water, grass, desert, mountain), resource(wood, cows, gold) and playerBuilt(road, building)
The client will only ever need access to about 100x100 tiles at the same time.
I have handled the map on client side under control. The problem that I'm faced with is how to store, retrieve and modify information from this map on the server side.
Required functionality:
Create, store, and modify 64000x64000 tilemap.
Show 100x100 part of the map to the client.
Make modifications on the map such as roads, buildings, and depleted resources.
What I have considered so far:
Procedural generation: Procedurally generating whichever part of the map is needed on the fly. Making sure that given the same seed, it always generates the same map. The main problem I have with this is that there will be modifications to the map during the game. Note: Less than 1% of the tiles would be modified during the game and it could be possible to store modifications with coordinates in an outside array. Loading them on top of the procedural generation.
Databases: Generating the map at the start of the game and storing it in a database. A friend advised me against this for such a huge tile map and told me that I'd probably want to store it in memory instead.
Keeping it all in memory on the server side: Keeping it in memory in a data structure. Seems like a nice way to do it if the map was smaller but for 4 billion tiles that would be a lot to keep in memory.
I was planning on using java+mysql for back-end for this project. I'm still in early phases and open to change technology if needed.
My question is: Which of the three approaches above seem viable and/or are there other ways to do it which I have not considered?
Depends on:
how much RAM you got (or player/users got)
Is most of the tile map empty (sparse) ? Opposite is dense.
Is there a default terrain (like empty or water ?)
If sparse, use a hashmap instead of a 2D array.
If dense it will be much more challenging and you may need to use a database or some special data structures + cache.
You may detect hot zones and keep them in memory for a while, dead zones (no players there, no activity ...) can be stored in the database and read on demand.
You may also load data in several passes: first just the terrain, then other objects... each layer could be stored in a different way. For example the terrain could be perlin noise generated + another layer which can be modified.

Google AppEngine HRD -- consistency vs contention?

I am trying to model a simple diagram editor that stores data into GAE's HRD datastore, and I am facing problems that I am wondering if you can give me some advices on. Basically, the editor's model are:
[Diagram] --contains--> [Shapes] -- contains--> [Text]
Initially, I put these into the same entity group, to make sure the data is consistent. By doing so, whenever I add new shapes or add text objects to existing shapes, they show up properly (as it's queried from datastore); however, I am having problem because the user could be adding many shapes quickly, and that leads to more than one update to the diagram object per second, which leads to write contention.
Alternatively, I could design like so:
[Diagram] [ Shape - contains diagramId] [ Text - contains shapeId]
which put them in different entity group, and when I create a new shape I just have to save the shape object itself. This solves the write contention problem, but the data is no longer consistent -- depending on how soon HRD commits the write, I might get stale data.
I tried combinations such as putting the diagrams in the cache, and retrieve from the HRD only if the cache doesn't contain the diagram; however, this is unpredictable as I can't be sure that the diagram would be in the cache (I expect many diagrams to be edited at the same time)...
What's the best practice on dealing with such issue? I am using Java and JDO, if that makes any difference...
Few notes:
HRD reads are strongly consistent if you use get and eventually consistent if you use query (as queries rely on indexes and those need time to be built). You can get around your problem by using get, if possible.
If Texts and Shapes are part of one Diagram and if you do not need to access them separatelly AND you do not need to search by Text's or Shape's properties, then you could just serialize Text and Shape inside a Diagram. I use Objectify and this is simply achieved with the #Serialize annotation on a field (don't know about JDO as I don't use it).

Collision detection with multi resolution map

I may have a problem imagining the best solution for a collision detection related problem. I'm writing a 2D top-down game in Java with many objects that could collide. I am planning to use the approach to create a multi resolution map, with specific objects in specific resolutions of map squares, so that I can go around the O(n²) problem and narrow down the objects in an area that could be colliding.
I have to keep a list of all objects that are residing in each map square. However, since many or sometimes all objects are moving, I have to keep these lists updated all the time.
I guess using every render cycle of an object to update the map square lists will be quite resource consuming and will probably destroy the advantage I gained by using multi resolution maps to narrow down the number objects that could be colliding with another object.
My question is now, how to keep track of all objects and filling them into the according map squares? Is there an easy way, or should I maybe choose another concept for the collision detection?
I might have forgotte some details, if there is some more information I should provide, please reply.
Thanks in advance
Best regards
i assume that you have non moving objects and moving objects. the static objects needs to register themselves only once in the multi resolution map. the moving objects have only to check if they belong now to another square if they really moved.
depending on how you do the actual collision detection you only need to recheck if the moving objects traveled a certain distance. that is the case when you check collisions with an object in the current and all surrounding squares.
the squares far away from the players square usually also don't need to be checked every single physics pass. there is usually no action going on anyway.

Easy way to implement dropped items in rogue-like game?

Basically I have a rogue game I'm making, and am trying to implement dropped items for when the enemy dies. I've tried a couple different methods on how to do this, and none have been successful.
I was just wondering if you have any ideas on how you would go around such a thing. Thanks!
I haven't gotten to items in my current wip Roguelike engine, but here is an outline of my current plans:
Both map tiles and entities act as containers for entities. When an entity in a tile suffers an item-dropping event (i.e. normal death) you could just append the contents of its inventory list onto the tile's contents list.
I also plan to add logic for tile/entity capacity though, so you can't carry walls off (usually?), and tiles can't contain infinitely large piles.. Also since you probably want to control item drop frequency and type it is probably best to give entities a method that returns a list of inventory they dropped.
+1 to https://gamedev.stackexchange.com/ though, I didn't know that existed.

Categories

Resources