Author Topic: Calling all coders - please help me test Infected AI v2!  (Read 4528 times)

0 Members and 1 Guest are viewing this topic.

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Calling all coders - please help me test Infected AI v2!
« on: December 22, 2010, 12:35:19 AM »
Infected AI v2
Beta Version 2.3



Beta closed.  :>
New templates online soon..


Version 2.3 notes

  • Fixed a bug that occasionally caused the AI to colonise 2 asteroids then stop completely until attacked.
  • Various minor code tweaks (I don't remember what) to improve efficiency and overall effectiveness

Version 2.2 notes:

  • The AI now automatically detects flowers that grow on its trees, and plants them on Dyson Trees.  No mines just yet, sorry!
  • The AI will now continue to send seedlings to reinforce an attack it is winning.
  • The AI is now a lot smarter about choosing the size of the initial force of seedlings it sends to colonise an asteroid inhabited by greys.
  • Fixed a bug (hopefully) with AI seedlings all flying back to the gather point as soon as they had successfully captured an asteroid.
  • Orphans surrounded by lots of enemies will now try to launch an attack - at the latest - when they reach their spawn cap.
  • When a gather point that has a very large number of seeds launches an attack, it will now split them between all available neighbouring enemy asteroids, drastically improving the virulence of large AI swarms.
  • Removed some unnecessary parts of code that were not doing anything except slowing the engine down.




The Infected AI should then take control of empires 2, 3, 4, 5, 6, etc.
It will not control Player 0 or Player 1.
The AI should perform well in any situation provided you closely follow the implementation instructions.  If your level gives the AI problems, please let me know!!
You need to make sure that the AI has at least 1 asteroid to control.  If he isn't the owner of at least 1 asteroid with either 10+ seeds or 1+ tree, he won't do anything.
« Last Edit: January 05, 2011, 07:05:34 AM by annikk.exe »

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: Calling all coders - please help me test Infected AI v2!
« Reply #1 on: December 22, 2010, 12:36:41 AM »
Notes for putting this in your level

1.  This COMPLETELY REPLACES the first version of Infected AI.  It's definitely not recommended to use them both in the same level.

2.  This AI will control as many factions as you want it to.  You don't need to paste multiple copies of the code or anything like that - the ability to control multiple empires and have them fight the player and each other is a key feature of the new version.  All you need to do to have multiple AIv2 factions in your level, is to create asteroids for players 2, 3, 4, 5, etc (whichever ones you want), and give their asteroids some seeds and/or dyson trees.  If an asteroid belongs to one of these empires and has at least 10 seeds or 1 dyson tree on it, the AI will start controlling it.  See the discussion near the bottom of the first page of this thread for more details.

3.  The AI should notice if under attack from a player mine.  (untested)  However, mines for all other factions are currently ignored.  AIv2 does not currently handle its own flowers or mines in any way.

4.  Currently the AI engine constantly renames all of the asteroids on the map to whatever the metric number of that asteroid is.  The metric number is what is used to determine the path seedlings should take to get where they are needed.  Being able to see at a glance what metric a particular asteroid has is a huge help with troubleshooting the AI engine, so I decided to leave this in for the beta version.



Bugs:

- Partitions with only fully-built friendly neighbours but no enemy neighbours or blank neighbours, keep all their asteroids on metric 500, rather than grouping their seeds up or shuffling them around somehow.  This is somewhat of an issue on maps with moving asteroids.

- EFFICIENCY: Regarding the code for sending the seeds to the next lowest metric.  Currently, the check to see if this is a player asteroid is nested deep inside the For loops.  This is inefficient; a better way would be to carry out the check right at the start of the "Send Seeds To Next Lowest Metric" code, and simply not bother running any of the code if checkedroid.owner == 1 or 0.

- EFFICIENCY: As above, but for the "launch attack" code.  It might be easiest to simply include a giant If Statement that rules out any actions being carried out if checkedroid is a player asteroid.  This is conceptually the easiest way to understand it as well, and would remove some detail from the complicated For loops inside the actions section.

- EFFICIENCY: Found some erroneous code that doesn't need to be there.  It talks about "gatherpointsallowed" and carries out some checks to set a variable of the same name.  However, the variable is never used, so this just represents precious clock cycles going to waste.

- Treeless asteroids belonging to player 0 are eroneously considered "friendly" asteroids even when there are actually greys present at the asteroid.  The naive AI sends his 10 colonising seeds there, and they get slaughtered.  :P

- Adjacent single-asteroid partitions belonging to different empires both become gather points, and can reach a situation where one reaches the spawncap, but does not attack because the other orphan asteroid has almost as many seedlings.  I need a special trap for this situation to get the orphans to attack when they reach their spawn cap.

- After capturing an asteroid, its gather metric is reset to 500.  I have seen some cases where this causes seedlings on the newly captured planet to instantly fly back to the gather point (which has metric 200).  A better solution would be to set newly captured asteroids to a metric of 200.  This would cause them to become gather points, meaning the seed army would stick around.  If they aren't valid as gather points they will be changed anyway on the next cycle. By removing the OnAsteroidTaken, set metric to 500 code, now when asteroids are taken they start with a metric of 0.  Nearby seeds will flood in to reinforce.  0 will be re-evaluated shortly thereafter and reset.

- In very action-packed games, the AI will wander about responding to attacks of 50 seedlings with a swarm of 2000.  This is excessive - the AI should make better use of these.



Wish List

- Ability to detect seedlings in flight
- When sending seeds to a neighbour, ability to tell if another (enemy) asteroid is in the way, whose seeds might snipe the travellers on the flyby.
- Ability to detect flowers, and plant them to make super seedlings and/or mines.
- Detect enemy AI mines as well as player mines
- It would be nice if the AI could recognise when he is already attacking, and send the reinforcements as they arrive at the gather point.
« Last Edit: December 29, 2010, 11:22:35 PM by annikk.exe »

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: Calling all coders - please help me test Infected AI v2!
« Reply #2 on: December 22, 2010, 03:41:20 PM »
Anyone tried it?
I tried on my Infected Empire map, and also on a new gravity map that I'm making.  It avails itself quite well in either scenario, save for the bug (at the time of writing there is only one) listed above.

AWS

  • Achiever
  • Arboreal Being
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 274
Re: Calling all coders - please help me test Infected AI v2!
« Reply #3 on: December 22, 2010, 09:46:47 PM »
annikk, im really excited about this...i will try it asap and in my newest, unreleased map..(which currently has your AI.v1 code, tweaked for 2 enemy factions)

..i dread to think whats going to happen..
 ??? ;D

anticipating a swift death AWS

EDIT - will this control just 1 enemy's AI? do i need to do what i did before and change the values for a 2nd, 3rd, etc enemy?
« Last Edit: December 22, 2010, 09:56:29 PM by AWS »

AWS

  • Achiever
  • Arboreal Being
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 274
Re: Calling all coders - please help me test Infected AI v2!
« Reply #4 on: December 22, 2010, 09:51:50 PM »
ok, one thing...
do i need to completely remove all previous AI coding, and paste this in afresh??
or add it in addition to whats there already?

im assuming it will require pasting over ALL the old code...

aws

EDIT - its working with 1 AI right now... ;D

EDIT 2 - well, its now decided to crash on me! but i cant be sure it has anything to do with your code.
one error message im getting is the line in your code right at the start-

GetAsteroid(0): ChangeOwner(2)

- saying when loading the game 'attempt to index a nil value'

firstly, i dont know what that specifically refers to, or how to change it.
second, it may have nothing to do with your code as i have also added the rallypoint v.2 code at the same time.
intially it loaded fine, got to my second welcome text explaining how to use the rallypoints, and then it froze. 3 times at the same point.
but now it wont load at all..so, im a little lost with this one.

however, ill keep tweaking and see if i can rescue it before i lose the whole thing :(
lol.
« Last Edit: December 22, 2010, 11:26:16 PM by AWS »

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: Calling all coders - please help me test Infected AI v2!
« Reply #5 on: December 22, 2010, 11:53:52 PM »
Quote
GetAsteroid(0): ChangeOwner(2)

Uh, that line isn't in my code...  Are you sure that's not leftover from something else?
And maybe the reason it is causing a crash is because of the erroneous space after the colon.  :>



For the avoidance of doubt, ALL the AIv1 code should be stripped out.


Also,

Quote
EDIT - will this control just 1 enemy's AI? do i need to do what i did before and change the values for a 2nd, 3rd, etc enemy?

Nope, it will control as many factions as you like.  You don't need to do anything special to the code at all.  Just make a level which has some asteroids belong to AI empires (like 2, 3, 4, 5, etc) and give some trees and/or seeds.  The AI will take control of it.  :>
« Last Edit: December 22, 2010, 11:57:54 PM by annikk.exe »

AWS

  • Achiever
  • Arboreal Being
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 274
Re: Calling all coders - please help me test Infected AI v2!
« Reply #6 on: December 22, 2010, 11:59:39 PM »
ok annikk. thanks.
for clarity - this is what it currently looks like (i havent tested this exact state yet as i wanted to post here before i forgot my question!)


GetAsteroid(0):ChangeOwner(2)

purgetimer = GetGameTime()  

   
   while GameRunning() do
   
      
      -- *** INFECTED AI V2 ***
      -- BETA VERSION 0.1


- the red text was there before, from previous code, and the black is your new AI copied into it just now.
do i need both red and black bits. or JUST from the while GameRunning loop...?

again , for clarity -
- before, i had 2 sets of your AI v1 code, one for enemy 2 and for enemy 3. ( i went through each line of your code to change the particular '2' values to '3' !! )
With this new v2 code, you're saying i can make do with just one code set for both/ all enemy AI's i want?
 ;D
« Last Edit: December 23, 2010, 12:03:20 AM by AWS »

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: Calling all coders - please help me test Infected AI v2!
« Reply #7 on: December 23, 2010, 12:00:40 AM »
You don't need either of them.

Quote
or JUST from the while GameRunning loop...?

this.



PM me your code if you want, and I'll help you clear out the remnants of AIv1 :>

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: Calling all coders - please help me test Infected AI v2!
« Reply #8 on: December 23, 2010, 12:04:52 AM »
Quote
however, ill keep tweaking and see if i can rescue it before i lose the whole thing :(

Go download Notepad++ !  It has basically unlimited undo levels.  It saves me all the freaking time.  If I totally mess something up, I can CTRL-Z my way back through hours and hours of work, looking at what I all changed.... and then just as easily CTRL-Y to fast forward through those changes.

Plus you can skin it, and it has tabs, and it colours all the different lua-specific things so that you can see typos and such.  It keeps nice tramlines for all your tabs and you can even minimize individual sections of code.

It's also totally free to download and takes seconds to install.  :>

AWS

  • Achiever
  • Arboreal Being
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 274
Re: Calling all coders - please help me test Infected AI v2!
« Reply #9 on: December 23, 2010, 12:11:11 AM »
oooh... nice program!! it looks just like dreamweaver / css now.

ok. ive added your v2 code and it works.
i have kept the old v1 for the other enemy and theres no issue as yet running both in the same script.
by what you say i can erase completely the 'copy' of the code so ill try that now and see what happens.

it seems to me now that it is a problem with the rallypoint V2 coding and not your fresh AI v2! :) which is good.. for you anyway!

will keep you posted.
thx as always.

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: Calling all coders - please help me test Infected AI v2!
« Reply #10 on: December 23, 2010, 12:18:40 AM »
You really should remove Infected AI v1.

The reason why I think this is that AIv2 is going to try to control AIv1's asteroids.  So whichever one of them thinks it's a good idea that the asteroid sends some seeds somewhere, will make the call - and the other AI will be unable to prevent it.
Apart from anything else, AIv1 has a HUGE processing overhead and it will probably slow down the computers of a lot of people that try to play it if you run 2 AI's at once.. :P


AIv1 was never really intended to be used by anyone else to be honest.  I'm surprised and intrigued that you managed to implement it into another level despite its shortcomings.  :>  Did you manage to figure out how it does what it does?  The code isn't exactly pretty.. :P

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: Calling all coders - please help me test Infected AI v2!
« Reply #11 on: December 23, 2010, 12:26:10 AM »
Quote
again , for clarity -
- before, i had 2 sets of your AI v1 code, one for enemy 2 and for enemy 3. ( i went through each line of your code to change the particular '2' values to '3' !! )
With this new v2 code, you're saying i can make do with just one code set for both/ all enemy AI's i want?


Yes - this is correct.  :>  Honestly!
I'm trying to think how I can make this any more clear...  you just... you know when you create asteroids, like this:


a = AddAsteroidWithAttribs(x,y,e,s,s)
a.owner = 1


Well, just make AI asteroids like this:


a = AddAsteroidWithAttribs(x,y,e,s,s)
a.owner = 2
s = a:AddDysonTree()
a:AddSeedlings(50)

a = AddAsteroidWithAttribs(x,y,e,s,s)
a.owner = 3
s = a:AddDysonTree()
a:AddSeedlings(50)

a = AddAsteroidWithAttribs(x,y,e,s,s)
a.owner = 4
s = a:AddDysonTree()
a:AddSeedlings(50)




Now, as long as you have copied and pasted my AI code (ONCE only!) like I specified in the original post, the AI will now control factions 2, 3 and 4 for you.
Each of those factions will attempt to colonise the galaxy, capture each others planets, and so on.

You don't need to do anything else.  Just make roids, trees and seeds for the factions you want.  :>


Hopefully this is good and clear now.  ^_^

AWS

  • Achiever
  • Arboreal Being
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 274
Re: Calling all coders - please help me test Infected AI v2!
« Reply #12 on: December 23, 2010, 12:32:56 AM »
You really should remove Infected AI v1.
AIv1 was never really intended to be used by anyone else to be honest.  I'm surprised and intrigued that you managed to implement it into another level despite its shortcomings.  :>  Did you manage to figure out how it does what it does?  The code isn't exactly pretty.. :P
hehe.... lol.
well, all i can really tell you is that i wanted to have the AI for 2 enemies. so i did the logical thing and copied it!
i then went through and where i thought it was referring to the enemy 2, i changed it to 3.
how much effect it had i really couldnt say.
in addition, and ive only now, after all this time just realised it, i had the Global's for enemy3 active as well.
- so i dont really know what the code did what in game, but it worked. and i did notice the game step up a notch :)

anyway, i have now removed the erroneous copied code and have just the new v2 in place.
needless to say, its all totally beyond me. but i trust in the process so im expecting good things.
also, i havent played my level for a few months now. ive been so busy with various home things that i just havent been able to get into it. not to mentionm having no regular internet access for a long time either.

so, where i am now is that i have 1 copy of your new v2 code and it works. which is good.
next is to try and get Pilchard's rallypoint v2 code to work as well. i like his new grey slider bar. but i dont like its positioning on-screen. but first i need it to work.

EDIT - lol. sorry for reiterating my concern. i couldnt figure out how one code can control multiple factions at once! but i see your explanation now and its a little clearer. sorry, it takes some time for me to get my head round all this mathematical stuff. it always has, it probably always will..
:D

AWS

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: Calling all coders - please help me test Infected AI v2!
« Reply #13 on: December 23, 2010, 12:45:06 AM »
I can imagine that having 2 copies of Infected AIv1 would mean that the two different empires would read each other's metrics.
This is quite interesting because it means, for example, if one AI attacks the other, then they BOTH think they are the one that is under attack.  :P  So they would both spam reinforcements from their entire empire and it would become an all-consuming war, when a much more viable strategy might be to continue peacefully colonising the galaxy, and swarming up...

It's interesting thinking about it, but to be honest the complexity of AIv1 is so great that it's hard to figure out exactly what the results would be.  If you hadn't already told me that it worked, I would have expected it to crash.. :P


Quote
EDIT - lol. sorry for reiterating my concern. i couldnt figure out how one code can control multiple factions at once! but i see your explanation now and its a little clearer. sorry, it takes some time for me to get my head round all this mathematical stuff. it always has, it probably always will..

It's ok.  :>
The dev blog I wrote/spammed recently about the development of AIv2 probably goes some way to explaining it.

The simplest explanation I can think of is that when an asteroid is selected for checking, it only exchanges metric information with neighbouring asteroids that are owned by the same empire.  Those are also the only asteroids it considers as "friendly".  If a neighbouring asteroid is owned by an empire other than checkedroid.owner then it must clearly be an enemy.

The key is that it's possible to check who owns checkedroid, and also who owns a given neighbouring asteroid.  Because if this, it's possible to figure out if the neighbours are friends or not.

This approach works whether you are checking an empire 3 asteroid, or an empire 5 asteroid, or whatever.  :>

AWS

  • Achiever
  • Arboreal Being
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 274
Re: Calling all coders - please help me test Infected AI v2!
« Reply #14 on: December 23, 2010, 12:57:04 AM »
I can imagine that having 2 copies of Infected AIv1 would mean that the two different empires would read each other's metrics.
This is quite interesting because it means, for example, if one AI attacks the other, then they BOTH think they are the one that is under attack.  :P  So they would both spam reinforcements from their entire empire and it would become an all-consuming war, when a much more viable strategy might be to continue peacefully colonising the galaxy, and swarming up...

It's interesting thinking about it, but to be honest the complexity of AIv1 is so great that it's hard to figure out exactly what the results would be.  If you hadn't already told me that it worked, I would have expected it to crash.. :P

 - this is a most intriguing scenario. perhaps there will be a way to consider both potentialities of spamming each other head-on for gratuitous warring, but only above a certain seed count, and/or then grouping elsewhere nearby to act as counter attacking forces or even pincer movements?! then it really would be hard  :P ;D