I have a question. Say I have a picture of an ant
bitblt'ed onto the form. I want that ant to be able to turn a full 360 degrees and walk in whichever direction it is facing.
the only problem is, with what i know, i can only get the ant to walk a choppy sort of line in the 8 cardinal directions. (up down left right and the in-between angles)
I was wondering if there was a (fairly) easy way to do this?
(so I don't have to draw a HUGE number of ants just to do the animation)
also. is there a way to define an "invisible" circle around the "ant" and check to see if "food" is within that circle, and if it is, the ant would walk in that direction...
In case you were wondering, i'm working on an a-life program, and right now it's pretty good, but the graphics just show little dots on the form where the life forms are, and I'm really trying to get the graphics a little better.
Reality is relative,
Nothing is impossible,
Caffiene is the only thing keeping me alive.
Directdraw can rotate (I'm pretty sure) so if you arent doing that, you may want to switch. Either that or find some other code to do the work for you, but you may end up with rotatiojn holes.
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
(Just a heads-up)
As for the food thing, just use a 2D distance function(abs(square root of (((point1.x - point2.x) squared) + ((point1.y - point2.y) squared)))) to check each food thing. If the distance is less then the radius of the circle, theres food.
About the graphics: DirectDraw can't rotate. Well, maybe it can, but it's hardware dependant, and believe me, there are only a few video cards available which handle 2D rotation...
You can however gain enough speed with DirectDraw to calculate the rotations yourself, and draw each pixel (although that would be dramatically slow if you have more than 25 ants probably, depending on their size)...
But since I get the impression that this program is not really about graphics, you can also draw all the ants facing each direction either using a graphics program and load it into your program, or rotate the ants bitmap at loading time, then draw the rotated bitmaps... which is probably the easiest and fastest way...
Teaudirenopossum.Musasapientumfixaestinaure. (I can't hear you. There's a banana in my ear)
ok the program is working pretty good
(it's even simulating socilogical behavior among the
ants even through i didn't program it to do so)
the only problem is that in the beginning of the program (starting with 30 ants) the ants all take off to find the farthest possible food source within the sight radius (SightRAD)
Using the calculations you gave me for determining sight radius, and putting the location into Ant(x).FoodX, Ant(X).FoodY, how can I determine which piece of food is the closest? i want to stop half the ants from starving to death before they reach the food.
Reality is relative,
Nothing is impossible,
Caffiene is the only thing keeping me alive.
one more wierd thing they seem to be doing on their own is the forming of ant colonies in the area with the largest amount of food. no matter how scattered they were to begin with the survivors all end up grouping in that spot, resulting in a massive population explosion and a stable food source (the more intelligent ones can actually farm food)
even though the farmers are extremely rare (5%) they work together to support the entire colony. remember... I didn't program them to do this... they just did.
wierd, huh?
Reality is relative,
Nothing is impossible,
Caffiene is the only thing keeping me alive.
Thats pretty dern cool. Id love to see that, if you wouldnt care about posting the source. As for the closest food source, using the 2D distance function, just loop through the food sources, storing the lowest so far, (start that variable out at something like 25000), as an index (so you actually know what was the lowest), and store the distance as well (to compare the other food sources). when youve done that, whatever index you have is the closest. Hope you understood all of that =).
sounds cool, a demonstration of the law of survival of the fittest.
Instead of using a sight radius, you could use smell, each dot that has been near another with food next to it, will increase until achieving a certain value, depending on how much food that is on a dot. then dots close to a smelling dot will increase (this has to be slow) until achieving a value a bit lower than the previous. This way your ants can orient to bigger food deposits by prefering to move to the most smelling dot.
Use
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
i would be glad to, but my coding is quite messy and I tend to use the longest code to achieve the same results because i don't really know the shortest way to put things.
BTW. I tried out that code (at least the way my mind translated it) and it seems to work.
an interesting result is that the sight radius seems to be working right (for the most part) and since that is random for each ant, the blind ones will just wander around and starve to death until they actually walk into food. (which is exactly what i'd hoped for)
I havn't fixed up the graphics yet, so they are still just green dots on a black background.
If you still want me to post the code (it'd make a good laugh i'm sure) then I'd be happy to. (at least then i could find out if I used the calculations you game me correctly or if I used them in such a way as to get a result that is just completely wrong...)
Reality is relative,
Nothing is impossible,
Caffiene is the only thing keeping me alive.
if you've come this far, it's just the next step. Good luck to you
Use
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
Please, post the code. I would love to see that, and i (and im sure anyone else) would be glad to check over the code, and see what optimizations can be made, etc.
please keep in mind that i'm sort of new to this, so if you see glaring mistakes, please be gentle...
also. their behavior has changed since my first post. they now typically form several small colonies instead of one huge one, but i havn't let it run continuously for nearly as long as I did the first time (it ran for 1 1/2 hours and had 993 total ants the first time)
Reality is relative,
Nothing is impossible,
Caffiene is the only thing keeping me alive.
Feel free to tweak the coding as much as you like, i'd be interested in what results you guys might get with it or things you guys might get it to do that I just havn't thought of.
Reality is relative,
Nothing is impossible,
Caffiene is the only thing keeping me alive.
I noticed that no-one posted what they thought of the code.
That's kind of what I was afraid of...
I guess it was just that bad.
I had hoped people could give me some pointers on streamlining the code to make it faster and easier to read as well
as pointing out major mistakes within the code,
but I guess it's just too poorly written to fix it.
oh well. maybe I should just re-write it.
though I hope to add hunter type ants that prey on the
grazer/farmer ants and give them the ability to fight each other.
I might just add a small percent chance that if no food is available they can try to use each other as food (which might make a split between predators and prey.)
any Ideas on whether this might work?
I also thought about adding a settings menu which would allow the user to decide on the percentage of farmers/dumb ants/predators
and maybe adding gender to the ants and giving her a particular "scent" which at certain times would be released around her
and would attract male ants for breeding.
any thoughts on this idea?
Reality is relative,
Nothing is impossible,
Caffiene is the only thing keeping me alive.
Sorry I havent commented yet, Ive been busy with lots of stuff. Anyway, I really havent gotten a lot of time to look at your code yet, but one thing to point out is your code's spacing. When you code, try to indent lines in groups. For example:
Code:
Private Sub Hello()
For i = 0 to 10
If Something(i) = 10 Then
'//Do Something
End If
Next i
End Sub
This makes code a million and one times more readable. Another thing is to have descriptive variable names, or to add a comment when you define it. And define every variable at the beginning of a sub. A really good habit to get into is to have "Option Explicit" the first line in every form, module, and kitchen sink. This forces you to define all of your variables with the "Dim" Statement.
I just had an idea for a way to improve this.
Those of you who have seen my code could help me with
the best way of implementing this...
I was thinking of adding a sort of "status window" which would tell the total population, the total ammount of food, the most recent population jump/decline, the number of ants with each intelligence level, maybe even the largest colony of ants.
(a fast way to do this would be to use a group of food as the center of a circle and use some arbitrary number as the radius for that circle, and simply count the number within the circle)
any ideas for this? I don't know how to do this ATM, but I think I might be able to figure it out with some help.
(interesting though that i'm listening to a radio program about nanotechnology while working on A-Life...)
Reality is relative,
Nothing is impossible,
Caffiene is the only thing keeping me alive.