I'm currently programming a game in Java with the JMonkey engine - a 3D space combat game - and I'm quite interested in AI, so I wanted to do some kind of learning system. I had the idea of having factions maintain spatial memory of where they last saw ships - over time, they would estimate where a ship they saw a while ago might be (based on its last seen speed and direction, maximum speed...) by giving each area in space a probability and a danger rating and so on. This info could be used to plot safe paths for trading, plan patrol routes, and such. The specifics of this aren't at concern here (though if you have comments I would still like to hear them) - what I'm worried about is that my implementation might not be the best. Here is the essence of the problem:
public class SectorGraph
{
/*
* The world graph, containing knowledge and estimations of ship locations. Because
* coordinates could be positive or negative, we split this up into eight different
* ArrayLists for each side of each axis' origin a point could be on. Each world node
* is a cube defined by its minimum position (and a constant size, see Globals class)
* Each of these spaces is split into an arraylist for each dimension, so for example
* to look up WorldNode 3, -63, 109 we would do: PosNegPosNodes.get(3).get(62).get(108).
*/
private ArrayList<ArrayList<ArrayList<WorldNode>>> PosPosPosNodes;
private ArrayList<ArrayList<ArrayList<WorldNode>>> PosPosNegNodes;
private ArrayList<ArrayList<ArrayList<WorldNode>>> PosNegPosNodes;
private ArrayList<ArrayList<ArrayList<WorldNode>>> PosNegNegNodes;
private ArrayList<ArrayList<ArrayList<WorldNode>>> NegPosPosNodes;
private ArrayList<ArrayList<ArrayList<WorldNode>>> NegPosNegNodes;
private ArrayList<ArrayList<ArrayList<WorldNode>>> NegNegPosNodes;
private ArrayList<ArrayList<ArrayList<WorldNode>>> NegNegNegNodes;
New ArrayLists are created and inserted on demand. This all seems a bit messy, but I can't think of a better way to do it with the possibility of positions going off infinitely in any direction. I have three values that can be changed to make it more efficient: a maximum lifetime for a WorldNode before it is cleaned up, and a time period between updates of the graph, and a size for each world node (cube side length).
However, it does seem like there's still going to be a lot of time jumping through lists and filling lists with nulls (for example if we insert a fresh node at (0, 1000, 1000) and there's nothing around it, we need to insert a lot of ArrayLists just to get there). I first thought of just having a list of nodes, but that seemed like it would get even worse with having to step through a very long list.
Any comments or suggestions regarding this? Would perhaps some kind of Map that maps a coordinate to a world node possibly be better? Any ideas would be great.
Thanks,
-Joe

New Topic/Question
Reply




MultiQuote




|