• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Pick group vs array

Status
Not open for further replies.
I am making an AI for may map with GUI and am not sure which of these 2 methods would be fastest for the computer.

There can be up to 12 heroes in my map. Lets make 9 of them AI players. So when I code the AI, sould it be like this:
---
pick every unit in AI and do actions
set Temp_Unit to picked unit
if Temp_Unit then else...
---
or this:
---
for Temp_Int 1 to AI_Count do actions
if AI_Hero[Temp_Int] then else...
---

Please let me know if there is a better way as long as there is no JASS. I'll use custom scripts but no JASS.

Thanks for your time
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
custom script is Jass, so you are saying you are going to use what you are not going to use.

Nevertheless, it really doesnt matter, whichever works better for you in my opinion(there are no significant performance difference with 8-10 units)
 
Level 15
Joined
Aug 7, 2013
Messages
1,338
I would stick with an array.

Whatever the performance differences is, the array will let you easily reference any of the heroes instantly, e.g. AI_HERO[DREADLORD], in case you want to program behavior specific to each hero.

If you do the pick group, you'd need to do extra work to first find all those heroes again, and then figure out which one is the Dreadlord.
 
custom script is Jass, so you are saying you are going to use what you are not going to use.

Nevertheless, it really doesnt matter, whichever works better for you in my opinion(there are no significant performance difference with 8-10 units)

I'm aware that jass = custom script but there is a difference about how you put the commands in. Thanks for the info :)

I would stick with an array.

Whatever the performance differences is, the array will let you easily reference any of the heroes instantly, e.g. AI_HERO[DREADLORD], in case you want to program behavior specific to each hero.

If you do the pick group, you'd need to do extra work to first find all those heroes again, and then figure out which one is the Dreadlord.

'DRADLORD' should be an integer for example;
if unit type of AI_Hero[Temp_Int] = DREADLORD then...
or in the group's case
if unit type of Temp_Unit = DREADLORD then...

so both methods can make you reference to the hero at the same speed assuming that edo494 is right

If you want to know what its the best way to create a AI

It depends what you need to do in your AI

for me...
If you use ARRAY
this is the best for PURCHASE ITEMS, PICKING RANDOM HERO, RETREATING, ATTACK-MOVING

If you use UNIT Group
this is the best for USE SKILLS, CHECK HP / MP IN FOUNTAIN POINT

Ok but I can do all of them using the same structures with both methods. In my map, every hero has it's own base. They can have any 7 of 84 abilities, can purchase any item, retreats to player starting location (that includes HP check) but the attack/moving is the hardest part

Thanks to everyone for your help. It seems like both ways is even effective until proven wrong :p
 
Level 21
Joined
Mar 27, 2012
Messages
3,232
If you keep an indexed array (all units in the array are next to eachother, without gaps), then this will be more efficient than pick group as long as you have over 3 units.
Pick group is actually quite wasteful, as has been proven by benchmarks, so I'd suggest using an array.

EDIT: Messed up pick group and array with forgroup and firstofgroup loops. The point still stands though, because array reads are faster than function calls(forgroup, which you know as pick group, calls a function per every unit in the group)
 
An array search is what you described above in your first post.

for Temp_Int 1 to AI_Count do actions // This is the looping
if AI_Hero[Temp_Int] then else... // This is the searching to see if it is what you need.
// then you do actions.

I see thanks. The AI trigger fires twice a second through the whole game and I guess that is a lot :p. So sould I load AI_heros from hashtables instead?

If you keep an indexed array (all units in the array are next to eachother, without gaps), then this will be more efficient than pick group as long as you have over 3 units.
Pick group is actually quite wasteful, as has been proven by benchmarks, so I'd suggest using an array.

EDIT: Messed up pick group and array with forgroup and firstofgroup loops. The point still stands though, because array reads are faster than function calls(forgroup, which you know as pick group, calls a function per every unit in the group)

That makes sense thanks a lot Xonok. AI can have up to 11 units in my case so I'll use Arrays then or just hashtables if death recommend that.
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
it is good to make it run as fewest as possible, especially if you have heavy triggers attached to the timer. I think twice per second is sufficient for most thing. Also if you want Human-like AI, you dont want the AI to make actions 32 times per second, even humans can do that :D
 
for me in GUI
its better use 0.03125
this is the best faster than 0.03 lol

.03125 is slower than 0.03
.03125 is best to use because it provides a nice even basis for all your calculations. (32 FPS)
It is also the best for optimal triggers and effects.

For the time for AI I have seen a lot of different styles. Non of which can be considered the best. (personal preference)
This is the way I thought to be the best.
They use a 1 second timer for checking and giving actions to the units controlled by the AI.
They use a separate trigger to handle the attack / defense of those units.
The separate trigger runs 0.25 to 0.75 (the difference is used for difficulty as 0.25 is hard and gives the pc a fast response time. 0.5 is medium and gives a slightly faster response time. 0.75 is easy and give a slow response time.) You can tweak the time as those numbers are not always best for every map.
They also use health / mana triggers for healing / using potions to give the effect of forethought.
 
Status
Not open for further replies.
Top