list of lists ?

BlitzMax Forums/BlitzMax Programming/list of lists ?

Paul "Taiphoz"(Posted 2011) [#1]
I'v got a feature i am about to code into the project iv started, and I wanted to get opinions and ideas before i do it.

Essentially I have a unit that wanders the map, every few seconds it drops a marker/scent once it finds what its looking for it travels back along its cent trail re-marking(increasing the cent value).

Other units that then come accross a node in this trail can then tell by its cent value how important it is, each further unit that uses the trail and finds what its looking for increases the value.

So.

global trails:Tlist = createlist()
Type Tcent
  field x
  field y
  field value
  field prev
  field next
  field chainID
end type


So thats the easy way I came up with, as a unit starts to make a cent trail it marks each node with a unique ID/number so that later I can tell which nodes are part of what trail.

Each node being added to the trails list as their made.

problem is each time I think about this I think a structure of having a list for all trails, filled with lists of individual trails might be better.

AllTrails > Trail > Cent Marker.

not sure which is best. thoughts?


Jesse(Posted 2011) [#2]
how would the unit go about finding the scent? Would it iterate through the whole list of lists until the specific scent is found(searching for the one with in range)?
that sounds like overkill.

Last edited 2011


Paul "Taiphoz"(Posted 2011) [#3]
Yeah hence the post, the method above will work but with tons of over head cos its looping through lots of possible cent nodes that it does not need to bother with.

anyway need some ideas...


Jesse(Posted 2011) [#4]
why don't you add a field to the map tiles that include a list that only would contain the scents pertaining to that tile?
the scent would be added to the tile only after the scent has been dropped.

Last edited 2011


Paul "Taiphoz"(Posted 2011) [#5]
Ah nah wont work, my map area is 100*100 and the tiles are 64*64 but the game sprites are tiny in comparison. a single tile might have 3 or 4 trails going through it.

I wonder if I can do an array of trails with trails being a list of cent spots.

for x:trail = eachin Alltrails[1] ??? would that work


Jesse(Posted 2011) [#6]

Ah nah wont work, my map area is 100*100 and the tiles are 64*64 but the game sprites are tiny in
comparison. a single tile might have 3 or 4 trails going through it.


if that is the case you can also subdivide the tiles(not literally but computational wise) in to what ever you want. you can create tiles with in a tile down to 1 by 1 pixel if you need too. and assign lists to each that includes only dropped scents.


for x:trail = eachin Alltrails[1] ??? would that work


that works too.

Last edited 2011

Last edited 2011


Czar Flavius(Posted 2011) [#7]
What type are prev and next? You can make them references to other scent objects, so any unit that finds one scent can easily follow the trail.


Jesse(Posted 2011) [#8]
I was assuming those were his intentions.
but it has to pick up the scent some how.

Last edited 2011


Paul "Taiphoz"(Posted 2011) [#9]
yeah prev and nex would be pointers to the next object in the trail and the prev object in the trail.

I thought that if a unit hits a trail mid point it would want/need to know what way home was and what way the destination was , it can then just goto the next cent marker, and once arrived ask it where to go next.


Czar Flavius(Posted 2011) [#10]
Always have next as leading to the destination and prev as leading to the origin. Or a flag field.


Paul "Taiphoz"(Posted 2011) [#11]
Yeah that's the plan . Well I think I'm gona go with the array of lists idea and see how it gies unless some o e has a better idea


Czar Flavius(Posted 2011) [#12]
I don't really understand the array idea.


Paul "Taiphoz"(Posted 2011) [#13]
well, let me try and explain a bit better then..

I have a unit, a scout if you will that I give the command go find food to, it will then go off in a set direction wandering a little as it goes, as it travels every second or so it will drop a cent marker, basically building up a trail or path , if it finds food it will head back along its path, as it passes each marker it dropped it will add to it.

Once its back at base, other units departing from the base to get food will look at all the food paths' or trails, and then will go down the trail with the highest scoring cent trail, if they walk along the trail and find food as they walk back they will mark the trail again giving it a higher score.

So the trails with the most food will get the biggest scores, and more units will use them.

The potential is that a player might have a number of scouts out looking for food, water and or enemy units, so there can be a number of trails to track.

So my thought initially was that I could store each trail or path in a list of type cent mark, but then it hit me that if I have 20 paths and I need to iterate through each of them to check for proximity to units it might end up with a lot of over head.

So I was thinking if I could have a list that held all individual path lists it would be way more efficiant, or the array idea.

So if I use an array I could sat it at 50, and each element in the array would be a list of cent markers, that way when it comes time to scan through them or a specific list or list type, I only need to loop through that specific array element.

or am I barking up the wrong tree, I bet there is an easier more efficient way which is why im posting here to think the idea out.


Shortwind(Posted 2011) [#14]
I believe Jesse is on the right track for what your trying to accomplish. It really depends on how "smart" your going to make your entities. We are going to assume these are completely blind and pretty dim witted entities. They can only smell, drop scent trails, and have no idea how to determine if a home scent trail is theirs or a friends. (Kinda like a dumb ant.) They can only smell one tile away, no further. An example is easiest to show one method that would work.

Do as Jesse suggests and break down your "scent" layer as follows:

100x100 map with 64x64 pixel tiles = 640x640 trail layer.

Create an array 640,640 (x,y for simpleness).

x=x-coordinate
y=y-coordinate

Let's assume this is the list of objects on our map:

Empty = 0
Home Trail = 1
Food = 2
Water = 4
Enemy = 8
...
These are simple flags. This way multiple scents can be assigned to each tile.

Ex:
18,18 is empty, but two entities have crossed this tile. One was out looking for something and dropped a home trail scent. Another was following a food trail. So after each leave the tile would be:

18,18 = 3

[Edit]
I forgot to add in the strength calculation. Oops.

For our strength we will have a second array that represents our objects. For this example we need str(640,640,4).

So, after the entities move we would do the following:
str(18,18,1)=255 (the home trail)
str(18,18,2)=1+previous value

[End Edit]

For the trails, as the entity moves around, if the square it's going to move to is empty it would assign the square it's standing on with it's home trail flag.

Ex:
15,15 = 1 + previous value (if someone else had been here.)

Again, if no one had been there before this would be 1 for home trail. If someone had crossed who had found water, it would be 5.

Now once the entity finds food, it searches for the trail home flag. Changes the square it's standing on and moves. You can remove the home trail flag at this point, or have it fade over time.

All entities would look at this scent layer as they move around the map. If they are directed to follow a food trail, they only need to look on the scent layer for a food scent. There are only 8 squares to search (if you let them look all around), and if they find more than 1 square with food, they would follow the strongest one.

Hope this helps,
shortwind

Last edited 2011


Czar Flavius(Posted 2011) [#15]
Is your map divided into cells/tiles like a grid? Or is it free-form?


Paul "Taiphoz"(Posted 2011) [#16]
here is the map..

http://www.youtube.com/watch?v=lEomn-ccZAE


Czar Flavius(Posted 2011) [#17]
Each cell has a list of scent nodes that it contains. When an ant is on a cell, it iterates through the scents and picks the one with the highest value. (Or, whenever a scent is added to the list, sort it by value and the ants always pick the first scent in the list). The scent will then lead the ant either forwards or backwards as it chooses.

The video looks very nice, a cool game!


Paul "Taiphoz"(Posted 2011) [#18]
just theory crafting this cent stuff just now cos at the moment I'm focusing on the above editor, still need to add two aditional layers to it to handle collision objects, and stuff over the ground like tree branches, or ant kites lol.

this thread will help when I come to start coding the AI and stuff.