Modding the AI

Modding the AI

Moderator: Content Developer

Post Reply
discodowney
Posts: 47
Joined: 19 Apr 2010, 15:31

Modding the AI

Post by discodowney »

Hi,

Im doing a Masters in Computer Games Technology. My MAsters dissertation is to create a Support Vector Machine AI to control the enemy AI in a RTS.

Kernel Panic seems less complicated than others on the site, at least in terms of unit numbers. Its also built more on strategy and tactics which is very useful for me. If people would let me know of their experiences developing AI for the game thatd be great.

One more thing actually, could someone point me to some technical info about the AI in the game. If there is none then could you leave a few lines describing it - if its a FSM, theres loads of states, how the strategy is handled, something along those lines.

Cheers.
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7049
Joined: 16 Nov 2004, 13:08

Re: Modding the AI

Post by zwzsg »

Nom nom, copy-pasta!

The AI that can currently play Kernel Panic are:
  • Kernel Panic AI
    Often shortened to "KPAI", often lengthned to "Kernel Panic Lua AI". This AI is built-in the mod, as a Lua gadget. Use 7-zip to open up /mods/Kernel_Panic_4.0.sd7 then extract \LuaRules\Gadgets\KPAI.lua for the source code. All the source is in a single file, about 1300 lines long. I like to think it's a good exemple of AI since it's short yet complete, and you don't need any compiler to edit it. Then I might think that because it's the only AI I know the inners of. It was orginally written by KDR_11k. Then I expanded it to handle more factions and special commands, so now I mostly known how it works, except that the formula KDR_11k uses to assign weight to position still eludes me. I tried replacing it with formula that were easier for me to understand, but KDR_11k magic recipe always gave best results. I don't know much about Finite State Machine, but I don't think KPAI use one. In fact I don't see how finite state machines would be of any use for a RTS AI: There's lots going on at once, yet only one strategy to apply during the whole game. KPAI works by detecting units belonging to it that are new or that run out of orders, and then trying to find occupations for them. For instance, it sees that is has a new construction unit, or that a construction unit is doing nothing, then it looks for a nearby datavent that is free and tells the construction unit to build a minifac there. Then it is informed that a new minifac has been created, so it tells the minifac to build an endless queue of spam units. Then it gets noticed of having new spam units, and it assign them to a "position". That's the other part of KPAI logic. Since the only important terrain feature of KP are datavents, the KPAI first make a list of every datavent. Then during the game it keep track of the state of each datavent: Owned by ally, free, owned by enemy. Every attack unit are assigned a datavent to station around. Attacking is done by telling attack units to go station at an enemy datavent. KDR_11k magic formula give a weight to each datavent, depending on stuff like who owns it, how many enemy units around, etc.., I think it makes the one on the border of the controlled territory more attractive. Periodically the AI recalculate the weight of all positions, pick the best one, then assess how many units it would need to occupy it, then go grab all the units it think it needs and tell them to go there. I think. Not really sure. Like I said, the core logic was done by KDR_11k, I debugged it and expanded it, but some of it eludes me. The part I updated was the one giving orders to builders, and managing special abilities. Which I've done with simple stimulus-response, without any strategic view. For instance any Bug flip into Exploit if there are enemy within exploit cannon range but no enemy very close. Any Exploit switch back to Bug when there are no enemy in range, or when enemy is getting close. Or, the AI check firewalls regularly, when it find one that is charged, it looks for an area with a cluster of allies near a cluster of enemies, and if one is found, cast firewall there. Oh, and Kernel Panic AI is a cheating AI, since, as a gadget, it knows the position of enemy units it should not be able to see. But extra info is not a too severe form of cheating, so I don't mind.
  • Fair KPAI
    It's a copypasta of KPAI, except I changed it to count how many units of each type the enemy has, and stop the production when the AI outproduce the enemy. Also handle playing in place of the player when the player is playing HOMF. But just forget about that, I only mention it in case you stumble upon the part of the code mentionning "homf" or "megas".
  • NTai
    It worked then broke then worked again then broke again. So currently broken. NTai was an external C++ AI developped by AF. It used a profile per mod, that profile could be filled to give it indication about how to play a mod, which made it possible to make it play KP fairly competently (would usually beat KPAI). You can probably find NTai source next to Spring source, unless it's been culled when it stopped compiling. You could read the NTAI thread, but iirc AF doesn't support NTai anymore.
  • BaczekKPAI
    imbaczek wanted to try making an AI, so made a simple one geared to playing KP. Plays pretty good, and still works. I think the source is available, not sure where. No idea how it works internally, ask imbaczek. See the thread [ANN] Baczek's KP AI 1.2.
  • Shard
    I'll trust AF who told me yesterday Shard plays as well as the two other AI. Source not yet but soon available. Shard is an AI relying on lua files for configuation and to handle mod specificities. See Shard Thread for details.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Modding the AI

Post by AF »

Here are the winning results of a round of 100 games of Shard vs Kernel Panic AI vs BaczekKPAI:

Winner, time to win
BaczekKPAI 1.2 216.89999389648
Shard dev 390.4333190918
Shard dev 264.73333740234
Shard dev 353.39999389648
Kernel Panic AI <not versioned> 404.83334350586
Shard dev 412.16665649414
Shard dev 393.29998779297
Kernel Panic AI <not versioned> 397.10000610352
BaczekKPAI 1.2 353.86666870117
BaczekKPAI 1.2 325.26666259766
Kernel Panic AI <not versioned> 390.46667480469
Kernel Panic AI <not versioned> 581.70001220703
BaczekKPAI 1.2 336.66665649414
Shard dev 319.4333190918
Kernel Panic AI <not versioned> 553.5
BaczekKPAI 1.2 338.36666870117
Shard dev 294.76666259766
Kernel Panic AI <not versioned> 454.46667480469
Shard dev 358.23333740234
Kernel Panic AI <not versioned> 556.86663818359
Kernel Panic AI <not versioned> 450.20001220703
BaczekKPAI 1.2 268.23333740234
BaczekKPAI 1.2 333.0666809082
Shard dev 493.10000610352
Kernel Panic AI <not versioned> 347.39999389648
Kernel Panic AI <not versioned> 426.13333129883
BaczekKPAI 1.2 243.26666259766
Shard dev 180.06666564941
Kernel Panic AI <not versioned> 655
Kernel Panic AI <not versioned> 411.96667480469
Kernel Panic AI <not versioned> 416.0666809082
Shard dev 316.83334350586
BaczekKPAI 1.2 347.26666259766
Kernel Panic AI <not versioned> 468
Kernel Panic AI <not versioned> 367.26666259766
Shard dev 254.33332824707
Kernel Panic AI <not versioned> 441.76666259766
Kernel Panic AI <not versioned> 507.86666870117
Kernel Panic AI <not versioned> 332.79998779297
Shard dev 425.70001220703
Kernel Panic AI <not versioned> 364.86666870117
Shard dev 492.33334350586
Kernel Panic AI <not versioned> 467.26666259766
Shard dev 350.53332519531
Kernel Panic AI <not versioned> 480.0666809082
Kernel Panic AI <not versioned> 364.86666870117
BaczekKPAI 1.2 289
BaczekKPAI 1.2 322.23333740234
BaczekKPAI 1.2 223.26666259766
Shard dev 609.43334960938
Kernel Panic AI <not versioned> 323.10000610352
Kernel Panic AI <not versioned> 352.0666809082
Kernel Panic AI <not versioned> 258.20001220703
Shard dev 333.36666870117
Shard dev 503.4333190918
BaczekKPAI 1.2 340.36666870117
BaczekKPAI 1.2 362.9333190918
BaczekKPAI 1.2 341.63333129883
Shard dev 285.10000610352
Kernel Panic AI <not versioned> 420.33334350586
BaczekKPAI 1.2 273.73333740234
Shard dev 295.60000610352
Kernel Panic AI <not versioned> 450.20001220703
BaczekKPAI 1.2 399.29998779297
Shard dev 478.76666259766
BaczekKPAI 1.2 395.13333129883
BaczekKPAI 1.2 219.06666564941
Shard dev 343.73333740234
Kernel Panic AI <not versioned> 457.53332519531
Kernel Panic AI <not versioned> 381.9333190918
Shard dev 216.66667175293
Shard dev 338.66665649414
Kernel Panic AI <not versioned> 521.90002441406
BaczekKPAI 1.2 394.83334350586
Kernel Panic AI <not versioned> 332.70001220703
Kernel Panic AI <not versioned> 474
Kernel Panic AI <not versioned> 491.5666809082
Kernel Panic AI <not versioned> 350.16665649414
Kernel Panic AI <not versioned> 343.53332519531
Shard dev 258.33334350586
Shard dev 291.83334350586
Shard dev 196.93333435059
Shard dev 345.16665649414
Kernel Panic AI <not versioned> 289.23333740234
BaczekKPAI 1.2 231.36666870117
Kernel Panic AI <not versioned> 419.66665649414
BaczekKPAI 1.2 220.23333740234
BaczekKPAI 1.2 467.10000610352
Kernel Panic AI <not versioned> 460.46667480469
Shard dev 532.70001220703
BaczekKPAI 1.2 375.53332519531
Shard dev 371.63333129883
Shard dev 228.73333740234
Shard dev 301.73333740234
Shard dev 379.83334350586
BaczekKPAI 1.2 345.23333740234
BaczekKPAI 1.2 324.46667480469
BaczekKPAI 1.2 308.23333740234
BaczekKPAI 1.2 340.76666259766
BaczekKPAI 1.2 312.5666809082
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7049
Joined: 16 Nov 2004, 13:08

Re: Modding the AI

Post by zwzsg »

So, the proportion of victory are:
  • BaczekKPAI: 29%
  • Shard: 33%
  • KPAI: 38%
That's incredibly balanced!


What map(s) and what faction(s)? I assume time is in seconds? Was it always a 3FFA? I'd rather see 1v1 results.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Modding the AI

Post by AF »

Now if you could teach me how to make excel/google docs figure out a pie chart from that, I'd be quite happy ^_^
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Re: Modding the AI

Post by KDR_11k »

At first I intended for the spots in the KPAI to be FSEs but there wasn't enough to put into them for a simple behaviour so all they have is three states. A proper AI will of course need global states like the strategy it is going for, KPAI is pretty much just designed to give players something to shoot at.
discodowney
Posts: 47
Joined: 19 Apr 2010, 15:31

Re: Modding the AI

Post by discodowney »

Lua is getting an awful lot of love on here. But there is one in C++ so ill have a look through that.

If all it has it 3 states maybe i can add a bit more myself. Ill download the source prob tomorrow and ill have a look through it. Cheers for the help lads.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Modding the AI

Post by AF »

Here is the script used to do the 100 games:

http://pastebin.com/bsd1HChM
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7049
Joined: 16 Nov 2004, 13:08

Re: Modding the AI

Post by zwzsg »

startpostype=3;// Hey, BaczekKPAI always get the worst spot, not fair! Use random pos next time. Also, last KP is 4.0 not 3.6 (though that wouldn't change much).
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Modding the AI

Post by AF »

I'm happy, I got results I liked, hehehehe I could run another batch and change the folders round for KP 4 but Id rather type the write up instead right now!
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7049
Joined: 16 Nov 2004, 13:08

Re: Modding the AI

Post by zwzsg »

AF wrote:I'm happy, I got results I liked, hehehehe I could run another batch and change the folders round for KP 4 but Id rather type the write up instead right now!
I could run another batch myself, randomising maps and start pos and AI through my skirmish generator widget. But I would need a fresh Shard AI. I can only find the old Shard 0.21 on your website. Did you find a way to issue DISPATCH commands btw?
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Modding the AI

Post by knorke »

instead of 1v1v1 on marble madness (guy in middle=bad start) you should do 1v1 or if you do 1v1v1 use the speedballx18 map or something.
how to make excel/google docs figure out a pie chart from that
copy in texteditor (ie Notepad++), crtl-f "BaczekKPAI" -> click count -> "29 matches found"
repeat, make excel stuff with the numbers

also for the lols if you do this again:
http://springrts.com/phpbb/viewtopic.php?f=1&t=22571
(must add an allseeing spec)
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Modding the AI

Post by AF »

I haven't tried yet, my dissertation was due in yesterday so I had to focus on my write up
User avatar
JohannesH
Posts: 1793
Joined: 07 Apr 2009, 12:43

Re: Modding the AI

Post by JohannesH »

1v1 results would be more interesting than 1v1v1, coolest find would be if they all ended up beating 1 AI but losing to another most of their games (like rps)
discodowney
Posts: 47
Joined: 19 Apr 2010, 15:31

Re: Modding the AI

Post by discodowney »

Hey,

I know its been a while. Was wrapping up projects and reports. mental times, im sure i dont need to explain. Then took a week or two off. But im still interested in this. Im downloading the game and the AI now. This is just to let whoever may care know im still doing this.

Cheers.
Post Reply

Return to “Kernel Panic”