- Joined
- May 10, 2024
- Messages
- 57
Hi. I'm working on AI for my map. AI editor does not fit. I decided to write custom AI and discovered that computation power is too poor to make it right.
Basic AI:
1. Pick 1 unit.
2. Find nearby enemy/ally units.
3. Analyze situation and order to attack/retreat/cast spell/etc.
Let's say we have 4 players. 100 units in total on the map including creeps.
2. To find nearby units I need to iterate over all units on the map and compare distance between picked unit and all other units. It's 100 real comparisons + 100 functions calls to GetDistanceBetweenUnits(unitA, unitB). Function is very simple so we can think that it another 100 real comparisons. So at this point I need 200 real comparison to find nearby units.
3. Picked unit is archmage. He is in the center of the combat and surrounded by 50 units in 1000 range around him. He's about to cast Blizzard. Best target is surrounded by most enemies and least allies in Blizzard Area of Effect circle. To find best target I need to repeat steps in section 2 for each of these 50 units and make additional comparisons. 50 units X 200 real comparisons = 10.000 real comparisons. Additional comparisons from each iteration: Is Alive Or Not / Ally Or Enemy / Magic immune or not. To make it simple I suggest to convert them to another 10.000 real comparisons. Total: 20.000 Real comparisons.
Archmage needs 20 200 Real comparisons (200 + 20 000) to cast blizzard when there are 50 units nearby and 100 units on the map.
Then I decided to check how much computation power is given by the engine. I wrote an empty loop with 1 comparison in each iteration and execute it every 0.01 second. Then I enbaled FPS meter and started to check performance.
10.000 Iterations ..... 15 FPS
5.000 Iterations ..... 28 FPS
2.000 Iterations ..... 59 FPS
Only 2000 iterations per 0.01 second! Am I doing something wrong? It's impossible to write AI with such poor performance. I can play all modern games on high/ultra. My CPU can handle 115 GFlops.
Any suggestions/ideas/tweaks how to increase number of comparisons per tick? Or how to write it in another way?
Basic AI:
1. Pick 1 unit.
2. Find nearby enemy/ally units.
3. Analyze situation and order to attack/retreat/cast spell/etc.
Let's say we have 4 players. 100 units in total on the map including creeps.
2. To find nearby units I need to iterate over all units on the map and compare distance between picked unit and all other units. It's 100 real comparisons + 100 functions calls to GetDistanceBetweenUnits(unitA, unitB). Function is very simple so we can think that it another 100 real comparisons. So at this point I need 200 real comparison to find nearby units.
3. Picked unit is archmage. He is in the center of the combat and surrounded by 50 units in 1000 range around him. He's about to cast Blizzard. Best target is surrounded by most enemies and least allies in Blizzard Area of Effect circle. To find best target I need to repeat steps in section 2 for each of these 50 units and make additional comparisons. 50 units X 200 real comparisons = 10.000 real comparisons. Additional comparisons from each iteration: Is Alive Or Not / Ally Or Enemy / Magic immune or not. To make it simple I suggest to convert them to another 10.000 real comparisons. Total: 20.000 Real comparisons.
Archmage needs 20 200 Real comparisons (200 + 20 000) to cast blizzard when there are 50 units nearby and 100 units on the map.
Then I decided to check how much computation power is given by the engine. I wrote an empty loop with 1 comparison in each iteration and execute it every 0.01 second. Then I enbaled FPS meter and started to check performance.
-
set index = 1
-
loop
-
exitwhen index > 20000
-
set index= index+ 1
-
-
-
endloop
10.000 Iterations ..... 15 FPS
5.000 Iterations ..... 28 FPS
2.000 Iterations ..... 59 FPS
Only 2000 iterations per 0.01 second! Am I doing something wrong? It's impossible to write AI with such poor performance. I can play all modern games on high/ultra. My CPU can handle 115 GFlops.
Any suggestions/ideas/tweaks how to increase number of comparisons per tick? Or how to write it in another way?