Game Development Community

AI Genetic algorithm implementation

by Chris Beals · in Torque 2D Beginner · 11/20/2013 (5:21 pm) · 7 replies

Hello, I am a fairly new user of Torque2D. I am trying to make AI the focus of the game I am making, but I am unsure of the method of implementation. Is there any way to define your own AI routines and algorithms?

I wish to use a variant of a genetic algorithm since it is often very flexible and adaptive evolutionary algorithm. However, I do not see mention of implementing any of these methodologies. I have seen talk of implementing and utilizing personal c++ files but I am unsure if it viable, currently available, and able to express more complex AI algorithms.

Any help is appreciated. Thank you.

-Chris

About the author

Recent CS graduate trying to get a foothold into the videogame industry. I currently am trying to implement interesting applications for a novel AI.


#1
11/21/2013 (1:36 am)
This seems to explain it all quite well.
And this one gives a good example of a genetic Tetris AI.
#2
11/21/2013 (7:00 am)
You have the source code; it's written in C/C++ so you can modify it to your heart's content.

There are several methods for implementing AI, most of them discussed in AI trade journals or books on the subject. See Matt Buckland's Programming Game AI by Example for a fairly easy-to-digest "primer."

I recommend using TorqueScript to prototype and test, then moving the "heavier" parts into the engine itself once you get things functioning.

I have absolutely no idea what you're getting at here:
Quote: I have seen talk of implementing and utilizing personal c++ files but I am unsure if it viable, currently available, and able to express more complex AI algorithms.
C++ has been used for a number of things, including "more complex AI algorithms." I'm not sure what you would suggest as an alternative. Assembly perhaps? I would recommend against that - code complexity is at least an order of magnitude higher than C++ and today's optimizing compilers make this a huge waste of effort in all but a very few cases.
#3
11/21/2013 (7:14 am)
I may have been too vague. I do know how to implement an AI in a generic sense. I have already wrote many C++ AI applications with many of them using a genetic algorithm approach. The part I am questioning about is applying these to the Torque 2D engine.

I have seen this thread: (http://www.garagegames.com/community/forums/viewthread/133395)

In that, there is talk about creating C++ objects to be used in Torque2D. I am wondering if that ability still exists. Also if it is even viable to implement an AI algorithm this way.

I am trying to not over think the problem, so if actually modifying the engine is avoidable, then I think I would prefer not to go that deep.

Thanks for the quick replies also. I am having to do fast prototyping so the speed is very appreciated.
#4
11/21/2013 (8:47 am)
@Chris ah let me see if I can help you.
Take a look at this directory, there is 3 files for the class GuiSpriteCtrl
  • guiSpriteCtrl.h
  • guiSpriteCtrl.cc
  • guiSpriteCtrl_ScriptBindings.h
The header file contains the header of the class as usual, as well with the .cc file. The second header(_ScriptBindings.h) file contains the methods that are exposed to TorqueScript.
You can look at that to see how it's done.

For the header of the class there is some things you should notice.
This line is necessary, it's pretty straightforward what it does.
This line declares to the console that this class should be exposed to script.
In the code file there is the corresponding line.

The class you create should derive from SimObject.

(If anyone clear this up a little bit more feel free, I'm a T3D developer not a T2D developer, just thought I would help to get you started quickly)

Apart from that if the stuff you do doesn't require that it is exposed to script, then you don't have to do all of the above and you can simply do it as you would with any other C++ program. It's the exposing to script that is tricky.
#5
11/21/2013 (9:49 am)
One of the many half finished projects sitting on my hard drive is a conversion of this tutorial:

tdn.garagegames.com/wiki/TGB/Tutorials/Fill_Battle

Even though the TorqueScript-side of things is outdated since so much has changed with the MIT version, the C++ part is still pretty relevant and shows how to add a class to the game and implement A.I.
#6
11/21/2013 (4:47 pm)
@Lukas
So the key parts are the IMPLEMENT_CONOBJECT() and DECLARE_CONOBJECT()? What do those do exactly? I've tried to look into it, but I can't find information.

@Mike
This could help a great deal. They might be outdated which will add confusion but it might serve as an example. The AI was mostly in C++ then?
#7
11/21/2013 (4:59 pm)
IMPLEMENT_CONOBJECT() and DECLARE_CONOBJECT() and any similar "macros" define things needed for the object to properly inter-operate with the engine through the console. This means they can be instantiated via script.