how to start the AI

how to start the AI

Here is where ideas can be collected for the skirmish AI in development

Moderators: hoijui, Moderators

User avatar
krogothe
AI Developer
Posts: 1050
Joined: 14 Nov 2005, 17:07

how to start the AI

Post by krogothe »

Okay Im new to this forum so hi all :-)
so of you might have seen my Advanced AI Mod for C&C Generals ZH (i was called Lion then). Im planning to start an AI for spring since it can be actually coded instead of being just a bunch of conditional scripts. However i havent got a clue how to start an AI for spring.
Do i just tell the AI to run as a dummy client (emulating the key presses and so on) or do i use some sort of handles?
Any pointers to the right direction (preferably a tutorial or help file explaining it in detail) would be appreciated.
I have a lot of great ideas but not being able to put them into action can really suck.


By the way heres my plan for the AI:
-Try to make it smart by simple well-thought out checks instead of writing huge piles of code to improve it marginally.
-Put all relevant constants (such as amount of eachbuilding/unit to build, likelihood of certain events, multipliers etc) in a text file for easy changing by users so i can focus on coding while users focus on balance issues.
-Have the AI teamwork by using the same principles listed above, simple things like synching attacks, defense and nukes by considering ally's bases as their own under certain circumstances etc.
-Have a scoring system for a lot of units and actions, per map, per setting, which can be stored and can affect certain decisions.
-Have a slow update system where most things are only checked every second or more so it will be able to multitask better with the same CPU usage.

thanks.
submarine
AI Developer
Posts: 834
Joined: 31 Jan 2005, 20:04

Post by submarine »

you'll compile your ai as a multithreaded dll that the engine loads..

there's very few documentation in the IAICallback.h

i recommend you to have a look at the empyai (to learn how to set up a proper ai dll) and than have a look at the source code of other ai's

or post questions here in the forum, the other ai devs will surely try to help you...
User avatar
krogothe
AI Developer
Posts: 1050
Joined: 14 Nov 2005, 17:07

Post by krogothe »

Thanks, i had a look at the source code of JCAI but where do i find the source of the emptyAI.dll?
submarine
AI Developer
Posts: 834
Joined: 31 Jan 2005, 20:04

Post by submarine »

oh sorry, i had a look at the 0.66source and it seems emptyai is not included in it anymore...

it used to be there some versions ago... jcai probably looks a bit confusing at the beginning as there are a lot of classes and other stuff...
User avatar
krogothe
AI Developer
Posts: 1050
Joined: 14 Nov 2005, 17:07

Post by krogothe »

yeah it is a bit overwhelming but im starting to get grips with it, the IAIcallback is also helping!
Do i have to program the AI in C++ or can i do it in other languages (since im more familiar with C# and VB)?
User avatar
jcnossen
Former Engine Dev
Posts: 2440
Joined: 05 Jun 2005, 19:13

Post by jcnossen »

C++ is your best shot here, there are no interfaces for anything else.
User avatar
krogothe
AI Developer
Posts: 1050
Joined: 14 Nov 2005, 17:07

Post by krogothe »

Guess ill have to read up on a book or two on C++ then!
I was planning to start by just testing out some callback functions and printing them on a log, but when i went to try JCAI and NTAI i had a problem:
they simply wouldnt spawn!
and when they did the comm would stand there doing nothing!
and when i joined the same team as an AI it built 2 mexes and the game crashed!

any ideas on whats wrong?
User avatar
jcnossen
Former Engine Dev
Posts: 2440
Joined: 05 Jun 2005, 19:13

Post by jcnossen »

both ntai and jcai work... run small divide (a nice standard map) and be sure to have the AI in a different team... otherwise I don't know
User avatar
krogothe
AI Developer
Posts: 1050
Joined: 14 Nov 2005, 17:07

Post by krogothe »

Well this sucks monkey butt!
i ran some tests in small divide and other similarly small and simple maps. here are the results:

As ARM

NTAI: doesnt do anything at all, just a comm standing there
JCAI: doesnt seem to do anything, when any of my units comes withing radar range i get the BSoD (Blue Screen of Death) and my pc resets making a scary noise.

As CORE

NTAI: crashes instantly with BSoD
JCAI: seems to build and make progress but as soon as i get into their radar range BSoD again!

So the only way for me to watch the AI develop is to play against a core JCAI, stay away from it as much as possible (comm underwater?) and then watch the replay after the inevitable crash!

Can any of the devs let me have the EmptyAI source please??
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

It wasnt an NTAI crash ti was an engine crash.

NTAI starts up immediatly and as soon as ti starts ti starts fof the commanders build queue. This involves calling the engine itnerface ClosestBuildSite().

But that itnerface function has a bug in it that crashes the engine on a handful of maps, e.g. small divide.

Brazillian battlefields, or valley of death/war would be a better map to test with.
User avatar
jcnossen
Former Engine Dev
Posts: 2440
Joined: 05 Jun 2005, 19:13

Post by jcnossen »

User avatar
krogothe
AI Developer
Posts: 1050
Joined: 14 Nov 2005, 17:07

Post by krogothe »

Awesome. You know your shizzle Alantai!
the AI worked flawlessy (for a WIP AI).
Might I add the crash bug seems to happen on maps where buildings deform the terrain. You can see flat squares of land on small divide where the AI is placing buildings right at the start, but not in brazilian battlefield!
Thanks a bunch guys!
(dont miss me too much, ill be asking LOADS of help very soon :P)
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

Not at all, I played on anglo saxon redux, where a com explosion leaves a smallish pool, and I can see where the AI palces building son brazillian battlefields too soemtimes.

I'm thinking if this error isnt fixed soon or I dont fix ti myself, I'll write a piece of code that looks at the maps name and checks it against a blacklist then disables the AI if it finds a match so no crashes occur.

Maybe I can sue ym planned map GUI code to display a funky error message with flashign colours and rotating 3D models on the terrain
User avatar
krogothe
AI Developer
Posts: 1050
Joined: 14 Nov 2005, 17:07

Post by krogothe »

Lol...
Right now trying to compile my emptyAI is giving me hell, once i got over the #include "stdafx.h" problem, now it keeps giving me this:

i:\documents and settings\admin\my documents\visual studio 2005\projects\chaosai\chaosai\GlobalAI.h(12) : fatal error C1083: Cannot open include file: 'IGlobalAI.h': No such file or directory
ChaosAI.cpp
.\ChaosAI.cpp(9) : fatal error C1083: Cannot open include file: 'windows.h': No such file or directory

I could probably add the 'IGlobalAI.h' header to my project folder but i have no idea about the 'windows.h'.
Is there a way to compile the program ignoring the errors? The source files for both JCAI and EmptyAI do not have those two missing headers so I'm a bit lost!
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

Do it the way I did it. Your project isnt compiling because ti needs to be set to have the rts folder of the spring source as an include directory.

Goto TestAI folder ro somethign similair and use that, just rename the fodlername to ChasAI is it? Then work on that. I did that for TAI and NTAI and I had ti all configured for me, with a basic itnerface all writen out for me like a pretty skeleton, correctly configured project files too.
User avatar
krogothe
AI Developer
Posts: 1050
Joined: 14 Nov 2005, 17:07

Post by krogothe »

Finally, after a few hours of struggling with Visual studio (it wouldnt make me a DLL file) and sorting a load of errors, i got to try it, but when the game starts i get the message saying "Incorrect Global AI Dll". does this have anything to do with trying the versions of the downloaded emptyAI and the current spring or what?
At least the commander spawns and the game doesnt crash but i need to fix this error!

I did delete the "testAI.h" and "testAI.cpp" since just about every line in it was giving compile errors, but i figured that JCAI didnt have them.
I also used MyWindows.h instead of windows.h, since i couldnt find a windows.h anywhere in the spring source code. I thought it was just the right file with the wrong name but who knows?
Any ideas on what went wrong?
submarine
AI Developer
Posts: 834
Joined: 31 Jan 2005, 20:04

Post by submarine »

its probably because your dll doesnt export the right functions; make sure it uses a def file (e.g. take jcais .def file and set this as the export definitions file in your project's properties)

next make sure you use the same calling convention spring does (at the moment __cdecl (this can also be set in the project's properties)


which compiler are you using? afaik it works only with the microsoft c++ compiler (that comes for example with vs.net)
User avatar
krogothe
AI Developer
Posts: 1050
Joined: 14 Nov 2005, 17:07

Post by krogothe »

I have tested both the JCAI and TestAI .def files as the module definition files (there doesnt seem to be any "export definitions file" option under properties).
The convention is __cdecl and i am using visual studio.

It keeps on nagging me about the windows.h file, which is nowhere to be found (yes its probably inside some obvious DLL in my system but the program just wont find it!)

Once again heres the compile error i get:

i:\documents and settings\admin\my documents\visual studio 2005\projects\testglobalai\testai.cpp(9) : fatal error C1083: Cannot open include file: 'windows.h': No such file or directory

thats with the vanilla TestAI source!
submarine
AI Developer
Posts: 834
Joined: 31 Jan 2005, 20:04

Post by submarine »

is it possible that there's anything wrong with your vs net installation because the compiler is not not able to find windows.h?

did you deactivate the use of precompiled headers (in he projects properties->c/c++

you can set a .def file in properties->linker->input ->module definition file
User avatar
krogothe
AI Developer
Posts: 1050
Joined: 14 Nov 2005, 17:07

Post by krogothe »

Yep i done both of them, still no windows.h!
Ive tried changing the include line to:
"windows.h"
"windows"
<windows.h>
<windows>

but no success either!
can anyone just send me that file? my first attempts at googling for it failed too!

EDIT:
Okay im downloading the SDKs, toolboxes etc from MS, one of them is bound to have that file...
Last edited by krogothe on 16 Nov 2005, 23:48, edited 1 time in total.
Post Reply

Return to “AI”