Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (degenerate_762), 1,098 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Advice on building AI #466200
05/31/17 03:06
05/31/17 03:06
Joined: Apr 2002
Posts: 1,246
ny
jumpman Offline OP
Serious User
jumpman  Offline OP
Serious User

Joined: Apr 2002
Posts: 1,246
ny
Hi everyone

Im looking for any advice, pseudo code, theory, macro-micro ideas when it comes to building an AI. I've made AI before in my game Swordlord, but the AI I am working on now is much more complex. In swordlord, the AI really was in only 2 states, randomly moving around and attacking. But in my new game, the AI will be doing this, as well as pathfinding/attacking/making decisions/animating etc.

Im building an AI that can pathfind around the level using A*, and when it gets into it's attack range, it will attack its target. This sounds easy, but it really isnt, especially because I have so many things going on in an AI. If the AI sees an enemy/player, it can pathfind to the player. But what if the player is not there at the end of the path? So the AI will do something else, a search or whatever. What if the AI sees a player thats not close to any nodes? Then the AI must go of into a manual movement outside of the pathfinding. I can already see the branching of the AI being very big in scope.

When you make your AI, do you do everything in one loop/while? Currently I have a separate pathing bot that just handles pathfinding. Do I integrate decision making into this bot? Or do I attach a secondary entity to this bot that handles decision making, and let the pathfind bot just handle movement?

Where should I fit in animation, animation blending and attacking? Should I have pathfinding/animation/decisions/state machines in one entity?

I like the idea of having two entities, one handling pathfinding, while the other handles animation and AI. But this also means they have to constantly communicate with each other. Ive done this on a smaller scale, but I can see if I want to expand the AI, I will be doing alot of hacks. On the other hand, doing everything in one loop/or working in state machines is easy, but that may require alot of duplicate code, ie state_1=pathfinding while attacking, state_2=pathfinding to retreat etc etc.

Re: Advice on building AI [Re: jumpman] #466202
05/31/17 06:59
05/31/17 06:59
Joined: Nov 2008
Posts: 946
T
the_clown Offline
User
the_clown  Offline
User
T

Joined: Nov 2008
Posts: 946
Originally Posted By: jumpman
Hi everyone

Im looking for any advice, pseudo code, theory, macro-micro ideas when it comes to building an AI. I've made AI before in my game Swordlord, but the AI I am working on now is much more complex. In swordlord, the AI really was in only 2 states, randomly moving around and attacking. But in my new game, the AI will be doing this, as well as pathfinding/attacking/making decisions/animating etc.

Im building an AI that can pathfind around the level using A*, and when it gets into it's attack range, it will attack its target. This sounds easy, but it really isnt, especially because I have so many things going on in an AI. If the AI sees an enemy/player, it can pathfind to the player. But what if the player is not there at the end of the path? So the AI will do something else, a search or whatever. What if the AI sees a player thats not close to any nodes? Then the AI must go of into a manual movement outside of the pathfinding. I can already see the branching of the AI being very big in scope.

When you make your AI, do you do everything in one loop/while? Currently I have a separate pathing bot that just handles pathfinding. Do I integrate decision making into this bot? Or do I attach a secondary entity to this bot that handles decision making, and let the pathfind bot just handle movement?

Where should I fit in animation, animation blending and attacking? Should I have pathfinding/animation/decisions/state machines in one entity?

I like the idea of having two entities, one handling pathfinding, while the other handles animation and AI. But this also means they have to constantly communicate with each other. Ive done this on a smaller scale, but I can see if I want to expand the AI, I will be doing alot of hacks. On the other hand, doing everything in one loop/or working in state machines is easy, but that may require alot of duplicate code, ie state_1=pathfinding while attacking, state_2=pathfinding to retreat etc etc.



First of all, you'll want to split animation off the AI.
Animation should either react to movement or, in cases where animation drives movement via root motion or something, be driven by AI but not intermangled with it.
So your animation systems should be completely separated and accept inputs that control the animation states and blending etc of your entities. You can then drive those systems with movement controlled by AI, or directly drive them with AI.

For the AI itself, state machines get messy fast with more complex AIs, so you wanna look into alternatives. Behaviour trees are popular in AAA atm:

http://www.gamasutra.com/blogs/ChrisSimpson/20140717/221339/Behavior_trees_for_AI_How_they_work.php

Before behaviour trees, goal oriented planners were the thing:

http://alumni.media.mit.edu/~jorkin/gdc2006_orkin_jeff_fear.pdf

Now these are abstract concepts but there's numerous ways you could implement them in lite-c. Behaviour trees are often done in a very OOP-like fashion, with nodes corresponding to virtual functions being called on the AI agents and what not. You could implement that in lite-c using dispatch tables I thing (not actually sure if function pointers were a thing that worked in lite-c).

In general though for AI, you want to separate the concerns as much as possible. So splitting pathfinding, animation and decision making is a good line of thinking.

Re: Advice on building AI [Re: the_clown] #466203
05/31/17 08:08
05/31/17 08:08
Joined: Mar 2011
Posts: 3,150
Budapest
sivan Offline
Expert
sivan  Offline
Expert

Joined: Mar 2011
Posts: 3,150
Budapest
behavior tree is a nice and extendable solution. you can imitate a behavior tree by a couple of if-else branches in lite-c, to avoid writing a node based flexible but complex system. (selectors and sequences are just for branching, decorators are just for enabling or interrupting node running, and the final job is always executed in tasks)

you can check how behavior tree works in unreal engine 4, there are a couple of examples for shooter or zombie AI (you can see it through fast thanks to the visual editor). it was quite motivating for me when replaced my earlier state machine with a behavior tree, and it was my best decision.

you can make tasks which can take several frames, e.g. in case of a Move To task you can do first the pathfinding, then in a loop handle movement and check for arrival, or enemy moves to do repathing. you just need a few bools to check which branch is running in your behavior tree.

and yes, animation should be separated, should watch actual movement speed, and switch to or blend in animations when fighting.

for my RTS units and groups I used a struct in lite-c that included the entities managed, so you can easily have a separated pathfinding and a rendered/moving/colliding entity.


Free world editor for 3D Gamestudio: MapBuilder Editor
Re: Advice on building AI [Re: sivan] #466204
05/31/17 13:00
05/31/17 13:00
Joined: Dec 2011
Posts: 1,823
Netherlands
Reconnoiter Offline
Serious User
Reconnoiter  Offline
Serious User

Joined: Dec 2011
Posts: 1,823
Netherlands
In my current I use a state machine + conditions & AI properties (e.g. stuck, alerted or aggressiveness to name a few, stored in local variables or in entity skills if needed) + if/else branches which calls the necessarily functions.

I also find Half Life 1's way to be interesting, which is goal oriented (I guess), interesting part of it:

Quote:
Tasks
Tasks are short atomic behaviors that are defined for a specific purpose. For instance, most actors in Half-Life support the following: TASK_WALK_PATH, TASK_CROUCH, TASK_STAND, TASK_GUARD, TASK_STEP_FORWARD, TASK_DODGE_RIGHT, TASK_FIND_COVER_FROM_ENEMY, TASK_EAT, TASK_STOP_MOVING, TASK_TURN_LEFT, TASK_REMEMBER. These are defined as enumerations in the header file, and implemented as C++ methods.

Conditions
Conditions are used to express the situation of an actor in the world. Since everything is hard-coded, conditions can be expressed very compactly as a bitfield, but in this case it limits the different conditions to 32. For example, conditions are COND_NO_AMMO_LOADED, COND_SEE_HATE, COND_SEE_FEAR, COND_SEE_DISLIKE, COND_ENEMY_OCCLUDED, COND_ENEMY_TOOFAR, COND_HEAVY_DAMAGE, COND_CAN_MELEE_ATTACK2, COND_ENEMY_FACING_ME.

Schedules
A schedule is composed out of a series of tasks (with arbitrary parameters), and given a bitfield of conditions to help specify when this schedule invalid. The basic schedule object also has a name to help with debugging.

Goals
On a higher level, goals are made up of multiple schedules. The logic in the goal can select a schedule as necessary based on which task failed, and what the current context is. The goals in Half-Life include GOAL_ATTACK_ENEMY, GOAL_MOVE, GOAL_TAKE_COVER, GOAL_MOVE_TARGET and GOAL_EAT.

source -> http://aigamedev.com/open/article/halflife-sdk/

Re: Advice on building AI [Re: Reconnoiter] #466211
06/01/17 07:01
06/01/17 07:01
Joined: May 2005
Posts: 868
Chicago, IL
Dooley Offline
User
Dooley  Offline
User

Joined: May 2005
Posts: 868
Chicago, IL
This is a high level approach that I take to AI. I am not an expert, but I've managed to get some things to work okay in my games. AI is all about States.

I have been using a skill to store a number. Depending on the number, the AI will behave in a certain way, this is it's "state." Now depending on what happens to the AI, i.e. getting shot, losing sight of the player, etc... the state may change. The number in that skill changes, and therefore the behavior changes.

So I will set up a while loop like this:

Quote:

while(1)
{
if(my.skill10 == 1)
{
Do_something();
}
else if(my.skill10 == 2)
{
Do_something_else();
}

if(something_happens)
{
my.skill10 = 1;
}
else if(something_else_happens)
{
my.skill10 = 2;
}
wait(1);
}

Re: Advice on building AI [Re: Dooley] #466220
06/01/17 17:50
06/01/17 17:50
Joined: Apr 2002
Posts: 1,246
ny
jumpman Offline OP
Serious User
jumpman  Offline OP
Serious User

Joined: Apr 2002
Posts: 1,246
ny
Thank you for your input and links everyone!

Composition wise, I will be continuing with splitting an AI into different entities working together like you guys said.

Currently, Im working on the pathfinding entity. Its only task is to get to a position in the world, however it can. It can go in a straight line or A*, or it could do A* then a straight line immediately after. The reason why is because I want the decision making entity to only need to give a target position to the pathfinding entity, and not worry about actually doing the path loop.


Im intrigued by the goal/behavior tree option! How would you guys handle the sequence of tasks in Lite-C? Fill an array with a series of tasks, and if one task is successful, move onto the next array position and execute it's task?

Re: Advice on building AI [Re: jumpman] #466222
06/01/17 20:32
06/01/17 20:32
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
@jumpman - you are over your Private Topic limit. Wanted to ask you few advices laugh

I'm sorry for offtopic here.


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: Advice on building AI [Re: 3run] #466223
06/01/17 20:57
06/01/17 20:57
Joined: Apr 2002
Posts: 1,246
ny
jumpman Offline OP
Serious User
jumpman  Offline OP
Serious User

Joined: Apr 2002
Posts: 1,246
ny
(I deleted some PMs to make space, I cant send you a PM you are over your private limit as well it seems)

Re: Advice on building AI [Re: jumpman] #466224
06/01/17 21:00
06/01/17 21:00
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
That is strange... I also deleted some dialogs from my PMs, but yet I can't PM you. Try to PM me once again, please.
Edit: I deleted lots of dialogs, you should be able to get in touch with me now. Sorry for make offtopics here, but I need your advices badly blush


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1