Forum Archive

Go Back   3D Realms Forums > 3D Realms Topics > Duke Nukem > Duke Nukem 3D Modifications
Blogs FAQ Members List Social Groups Calendar Mark Forums Read

Notices

 
 
Thread Tools
Old 05-26-2008, 07:04 PM   #1
Reaper_Man

Reaper_Man's Avatar
EDuke32: Artifical Intelligence 101
I've seen a few threads about writing AI as well as having my own questions, since since I would consider AI to be my strongest point out of all of the programming needs and techniques I have learned over the years, I'd like to go ahead and put some if it down for those new or less experienced to benefit.

What is Artificial Intelligence?
First things first, I'm going to define AI within the scope of this post/tutorial. Artificial Intelligence in EDuke32 is the way in which a computer-controlled actor views the world and decides to make actions based on that view. Looking at the original Duke3D enemies, their decision making process is very simple. Let's look at the Liztroop, one of the more complex enemies.

The Liztroop does a few things: it walks, it runs away, it shoots, it flies, and the Pal 21 ones disappear. For a throwaway enemy that is a lot of things to do! All of these actions are done based on the Liztroop's only goal in view, the player. It decides to shoot at the Player if he is within view, it decides to fly if the Player is above them, it runs away when the Player is too close, and so on.

The basic principal of any AI should be to 1.) decide what it wants, 2.) look for what it wants, and 3.) how to act once it finds it. There can be any number of wants and needs for an AI to make them more complex, but what it comes down to is what the AI is wanting to do at any given point in time.

Setting a Goal
Before you open up any files to start modifying code, the best time saver is to define what you want your AI to do before you even start. Like many things involved in game design, flying by the seat of your pants only serves to burn out your creativity and cause you to waste a lot of time. After more than my fair share of Mod and TC attempts that have both failed and succeeded, time management is key. You also do not want to plan to do something that is outside of your personal skill level. Writing AI is hard but it's not impossible, and having a working knowledge of how the CON language works will go leaps and bounds to keeping you on track.

Once you have decided what you want your AI to do – follow the Player, hunt him down, patrol a given area, look for health or ammo, or any number of such things – the first step is getting the AI to look at the world around him, because you can't make a decision unless you can see!

Viewing the World vs Seeing the World
It goes without saying that AI is only as smart as you make it. Writing AI from scratch is both a great benefit and a ton of work. The benefit is that you do not have to work around any preexisting parameters of the given code, and you can make your AI as smart or as dumb as you would like. The hard work is having to tell the AI about everything in the world, and when it comes to very smart AI, I do mean EVERYTHING.

AI does not know about walls, or water, or jetpacks, or rockets, or pipebombs, or fire, or bottomless cliffs, or anything at all – unless you tell it to know about these things. The most simple AI in the world would be told to face it's target and walk forward. It might hit a wall, it might walk into the path of another enemy, or it might walk off the face of an endless pit. In order for your AI to be smart, it needs to know about the obstacles around it that it may encounter.

Don't want your AI to get stuck on walls? Tell it to perform a check every now and then when it is moving (or should be moving) to see if it is blocked, and either move backwards or jump or duck, or whatever you would prefer.

Don't want your AI to get stuck in the middle of a battle being shot at? Tell it to check for bullets being shot at or near it. This doesn't always work, so you also want to tell your AI how to act when it actually DOES get hit by a bullet.

Don't want your AI to search for something on the other side of the map or behind a wall? Make sure it checks if it can see it's target before trying to get to it. The AI in Duke3D is very omnipotent, it always knows where the player is at at any given point in time. You can easily avoid this with your AI by telling it not to look for it's target if it can't see it, or it hasn't seen it for a small period of time.

AI Concept: Cost
When writing AI, an effective method of decision making it by associating a “cost” with each possible action, and at any given point deciding what action to make based on the “costs” of things we could possibly do. For example, we could make a cost table for a basic AI such as this:

(1) Attack enemy Target
(2) Pickup health/ammo Target
(3) Find new target
(4) Move to new area

This AI would perform a simple “cost search” by looking around and seeing what it could possibly do vs what it wants to do based on the cost. In a room with an Enemy and some Health/Ammo, it would decide to attack the enemy because attacking is “less costly” than picking up Health/Ammo. If there were no enemies around, it would try to pick up Health/Ammo if any existed, and if not it would simply move on.

You might ask why I didn't put the “Find new target” AI routine at the top, and the answer if very simple. If finding a target were the “cheapest” thing it would ever want to do, it would never want to actually DO anything once it has found it. It would move around to find a target such as an Enemy or Health, and once it found it then it would loop again and just try to find it once again.

You can modify this cost on-the-fly to increase the intelligence of your AI. For example of the AI is hurt and has lost health, you could increase the cost of Attacking, or decrease the cost of finding Health so that it's main drive would be to heal itself. Once back to normal you would have to tell it to return to it's “normal mode” and it would start attacking again.

findnearactor: Friend or Foe?
One of the best and worst commands for writing AI is the “findnearactor” command. This command has some great benefits – it can quickly and easily tell us if a given target is within our given distance and we can execute commands right then and there. However this command has some disadvantages, such as a high CPU usage, and the limitation of being able to see through walls. It also can only target a single actor at a time, and can only identify targets by their sprite number.

findnearactor is good for performing simple checks, and is probably best used as a “final check” before making an action. Say our AI is looking for Health/Ammo and it has performed other checks – it has located a Health pickup, can see it, it can actually get to because it is on the same floor and not out of reach. You might then perform a findnearactor to check if it is within distance and of the correct actor type, and then if all of those checks return True you can tell your AI to get it's target.

Personally I think that findnearactor is not needed compared to more thorough checks and can to an extent be rewritten, but I don't expect everyone to share this view. It gets the job done right, but I do advise to double check it's results as it can sometimes give a false positive.

Don't Exceed Your Reach
I said this above and I wanted to restate it – the worst mistake you can do is deciding to write an AI that does everything, only to wind up writing an AI that only does some of them and does it poorly. Given the fluid nature of enemy actors and the Player in the game, writing AI is sometimes difficult since a given scenario may not be able to be reproduced but still gives errors. Do not expect to be able to write a perfect AI the first time, and don't be afraid to go back and enhance existing AI with new or improved code you may have written.

EDIT
I added this to the EDuke wiki though I can't find a category that would be fitting for it, if anyone has an idea please edit and add!
http://wiki.eduke32.com/wiki/Artifical_Intelligence_101
__________________
The Once and Future King
msleeper.com :: Digital Entertainment Design
The AWOL Project :: The Best Damned TC Never
Super AI Project / Duke RTS :: Coming Soon to an Actor near you!
Artificial Intelligence 101 :: Ask AI questions, get AI answers
Last edited by Reaper_Man; 05-26-2008 at 09:07 PM.
Reaper_Man is offline  
Old 05-26-2008, 11:44 PM   #2
DeeperThought

DeeperThought's Avatar
Re: EDuke32: Artifical Intelligence 101
Quote:
Originally Posted by Reaper_Man View Post
if anyone has an idea please edit and add!
What it needs is example code, preferably a step by step tutorial showing how to build an AI. But as you know that's a lot of work to write, and there's a very small audience for it.

AFAIK, no one has ever written a guide to the much simpler task of coding a good old-fashioned enemy that uses the 1.5 commands like seekplayer and ifcanshoottarget. It's disappointing to look at old TCs and see how rarely the scripting system was used effectively. In most cases people just used the existing code for LIZMAN or PIGCOP and slapped on different graphics with maybe a few minor tweaks to the code.
__________________
DUKE PLUS
New map effects and various optional extras for Duke 3D.

DUKE NUKEM: ATTRITION
XP based weapon upgrades, progressive difficulty, and more.
DeeperThought is offline  
Old 05-26-2008, 11:53 PM   #3
Reaper_Man

Reaper_Man's Avatar
Re: EDuke32: Artifical Intelligence 101
Yeah I definitely want to go through and add in some example code, but I just wanted to get the first go out since I sort of had a moment and couldn't stop typing.

There are a lot of TCs that did use modified code at the minimum, but you are right that most of them did just change some art and a few lines and that's that. I did a pretty poor attempt of writing AI info on my old CON site, but even then it was probably too little too late.
__________________
The Once and Future King
msleeper.com :: Digital Entertainment Design
The AWOL Project :: The Best Damned TC Never
Super AI Project / Duke RTS :: Coming Soon to an Actor near you!
Artificial Intelligence 101 :: Ask AI questions, get AI answers
Last edited by Reaper_Man; 05-26-2008 at 11:58 PM.
Reaper_Man is offline  
Old 05-30-2008, 04:59 PM   #4
Reaper_Man

Reaper_Man's Avatar
Re: EDuke32: Artifical Intelligence 101
So hey DT (and really anyone), I am in the mood to write some example code for this but I'm not sure where to start or what examples to provide. Anyone have ideas or requests?
__________________
The Once and Future King
msleeper.com :: Digital Entertainment Design
The AWOL Project :: The Best Damned TC Never
Super AI Project / Duke RTS :: Coming Soon to an Actor near you!
Artificial Intelligence 101 :: Ask AI questions, get AI answers
Reaper_Man is offline  
Old 05-30-2008, 06:58 PM   #5
DeeperThought

DeeperThought's Avatar
Re: EDuke32: Artifical Intelligence 101
Quote:
Originally Posted by Reaper_Man View Post
and really anyone
Yeah, someone else, because there's nothing I'm trying to code that I don't already know how to code, but there are people who have asked for help coding actors and they should be taking advantage of this. In fact, if no one takes advantage of this, then the next time someone asks me to code an actor for them maybe I'll just point them to this thread and tell them to...
__________________
DUKE PLUS
New map effects and various optional extras for Duke 3D.

DUKE NUKEM: ATTRITION
XP based weapon upgrades, progressive difficulty, and more.
DeeperThought is offline  
Old 05-30-2008, 07:05 PM   #6
Reaper_Man

Reaper_Man's Avatar
Re: EDuke32: Artifical Intelligence 101
I can live with that!
__________________
The Once and Future King
msleeper.com :: Digital Entertainment Design
The AWOL Project :: The Best Damned TC Never
Super AI Project / Duke RTS :: Coming Soon to an Actor near you!
Artificial Intelligence 101 :: Ask AI questions, get AI answers
Reaper_Man is offline  
Old 05-30-2008, 07:09 PM   #7
The Commander

The Commander's Avatar
Re: EDuke32: Artifical Intelligence 101
I know something that could be given in an example code that alot of people would find interesting, but it isnt exactly what we are talking about here. Watch the You Tube video in my sig Reaper Man and you will see what im talking about. Will be very familer to you from AWOL.
__________________
I Know Everything There Is To Know About Anything.

Duke Nukem Red Alert SVN

Ask Me Anything!
The Commander is offline  
Old 05-30-2008, 07:23 PM   #8
Reaper_Man

Reaper_Man's Avatar
Re: EDuke32: Artifical Intelligence 101
I still may write a Vehicle Base code, but I'd like to limit the example stuff here to AI. Vehicles are a few steps beyond AI... Unless you are referring to that horrible enemy vehicle AI in your video, in which case you need to learn about waypoints.
__________________
The Once and Future King
msleeper.com :: Digital Entertainment Design
The AWOL Project :: The Best Damned TC Never
Super AI Project / Duke RTS :: Coming Soon to an Actor near you!
Artificial Intelligence 101 :: Ask AI questions, get AI answers
Reaper_Man is offline  
Old 05-30-2008, 10:15 PM   #9
The Commander

The Commander's Avatar
Re: EDuke32: Artifical Intelligence 101
lol, I ment the cop car heh. That fire truck has the worst code ever, see.

ai AIFIRETRUCK_MOVE FIRETRUCK_ANIMATIONS FIRETRUCK_SPEEDS getv geth randomangle
useractor notenemy FIRETRUCK

ifai NO
{
ifspritepal 0
strength FIRETRUCK_NORMAL_STRENGTH
else
strength FIRETRUCK_TOUGHER_STRENGTH
sizeat 55 55
cstator 257
ai AIFIRETRUCK_MOVE
}
ifrnd 8
{
shoot FREEZEBLAST
sound CAT_FIRE
}
ifnotmoving
ai AIFIRETRUCK_MOVE
ifpdistl 1024
ifrnd 16
{
sound DUKE_GRUNT
palfrom 24 24
addphealth FIRETRUCK_DAMAGE_TO_PLAYER
}
ifhitweapon
{
debris SCRAP1 2

ifdead
{
addkills 1
spawn EXPLOSION2
sound RPG_EXPLODE
hitradius 2048
killit
}

sound PISTOL_RICOCHET
}
enda

Ouch, Thats very horrible code... (ill delete this later so it doesnt clog up the thread)
__________________
I Know Everything There Is To Know About Anything.

Duke Nukem Red Alert SVN

Ask Me Anything!
The Commander is offline  
Old 05-30-2008, 11:02 PM   #10
Reaper_Man

Reaper_Man's Avatar
Re: EDuke32: Artifical Intelligence 101
randomangle aye? Yeah that explains it.
__________________
The Once and Future King
msleeper.com :: Digital Entertainment Design
The AWOL Project :: The Best Damned TC Never
Super AI Project / Duke RTS :: Coming Soon to an Actor near you!
Artificial Intelligence 101 :: Ask AI questions, get AI answers
Reaper_Man is offline  
Old 05-30-2008, 11:40 PM   #11
DeeperThought

DeeperThought's Avatar
Re: EDuke32: Artifical Intelligence 101
It's the sample actor code from the top of the original game.con with a few minor differences.
__________________
DUKE PLUS
New map effects and various optional extras for Duke 3D.

DUKE NUKEM: ATTRITION
XP based weapon upgrades, progressive difficulty, and more.
DeeperThought is offline  
Old 05-31-2008, 12:40 AM   #12
The Commander

The Commander's Avatar
Re: EDuke32: Artifical Intelligence 101
Quote:
Originally Posted by DeeperThought View Post
It's the sample actor code from the top of the original game.con with a few minor differences.
Yeah, That is it. Very plain and boring isnt it.
__________________
I Know Everything There Is To Know About Anything.

Duke Nukem Red Alert SVN

Ask Me Anything!
The Commander is offline  
Old 05-31-2008, 02:16 AM   #13
Reaper_Man

Reaper_Man's Avatar
Re: EDuke32: Artifical Intelligence 101
Well since we're giving AI advice...

Don't use randomangle. Whenever you want it to face a new target (assuming that target isn't ALWAYS the Player), use the "make one actor face another" code that is in the Wiki right here: http://wiki.eduke32.com/wiki/Make_on...r_face_another

Since cars don't magically bounce off of walls and most drivers would avoid hitting things, you can add a sort of crude "collision pre-detection" by having your car do a "hitscan" and finding the distance between where it is and where the hitscan was. If the car is within X distance from an object, you probably want to tell it to adjust it's turning.

Whenever the car DOES hit something, you might want to do some checks to see if it is an actor there and not a wall. In which case you can make your cars run things over and do damage to other enemies.

Another idea is to have the car avoid any sector that doesn't have a "street" floor texture, though it's not really necessary and the list of valid floor textures might be a pain if you use a lot of varying detail textures.

Really, what you should do is make a list of things that you think the car AI should do - Avoid obstacles? Avoid walls? Drive only on streets? Drive in straight paths? Once you figure out how you want the car to behave, it is way easier writing some good AI for it.
__________________
The Once and Future King
msleeper.com :: Digital Entertainment Design
The AWOL Project :: The Best Damned TC Never
Super AI Project / Duke RTS :: Coming Soon to an Actor near you!
Artificial Intelligence 101 :: Ask AI questions, get AI answers
Last edited by Reaper_Man; 05-31-2008 at 02:58 AM.
Reaper_Man is offline  
Old 05-31-2008, 02:47 AM   #14
Spiker

Spiker's Avatar
Re: EDuke32: Artifical Intelligence 101
That sounds awesome. I hope that it won't finish only on this dicussion but there really will be this whole project and it will be sucessful.
Spiker is offline  
Old 06-01-2008, 11:18 AM   #15
Mblackwell

Mblackwell's Avatar
Re: EDuke32: Artifical Intelligence 101
AI isn't all that tough in the end.

The enemies in the original The Christmas Project track you, open doors, dodge, take cover, toss grenades, flank you, etc.

They do this all by a few if conditions with some ifrnd commands on top of them.

Honestly I would say DON'T overthink your AI code or you're likely to program in stupidity. It's better to give your actors a small set of options that can be strung together randomly while seeming intelligent than to have things set too specifically. If you have if conditions that are too specific (in sequence) then actions are more likely to NOT be performed when it would be intelligent to do so, such as firing when you are right out in the open.

I believe it was John Carmack that talked about this when talking about current methods of AI coding vs what they used in Doom and how the perceptions of the player play a large part in determining what effect the AI has, vs applying additional "smarts" to the actors and causing them to screw up more often.
__________________
I don't wanna be like other people are
Don't wanna own a key, don't wanna wash my car
Don't wanna have to work like other people do
I want it to be free, I want it to be true

Eduke32.com : The Rejected Applications : The Meadhall of the Comitatus
Mblackwell is offline  
Old 06-01-2008, 01:44 PM   #16
DeeperThought

DeeperThought's Avatar
Re: EDuke32: Artifical Intelligence 101
Quote:
Originally Posted by Mblackwell View Post
It's better to give your actors a small set of options that can be strung together randomly while seeming intelligent than to have things set too specifically.
That works great for the kind of AI you wrote for the Christmas Project, but it's not appropriate in all cases. For example, when I coded the bots for my Duke Nukem Arena mod, it was pretty obvious that in CTF, the flag must take priority over certain other things. When a bot has the flag, his primary concern needs to be getting it back to his base. He will shoot at enemies if they are in sight, but he won't go off of his path to chase them down. The decision to engage/disengage should also be influenced by other factors, such as the availability of pickup items. If a deathmatch bot is weak and/or low on ammo, he should go for some items rather than chasing down a stronger player (or that likelihood could be determined on a sliding scale depending on how aggressive he is). It is really easy to botch things, though, and I had a lot of difficulties with my DNA bots (some of which were never resolved). However, I think that has a lot to do with my inexperience when I was doing that mod.
__________________
DUKE PLUS
New map effects and various optional extras for Duke 3D.

DUKE NUKEM: ATTRITION
XP based weapon upgrades, progressive difficulty, and more.
DeeperThought is offline  
Old 06-02-2008, 08:03 PM   #17
Mblackwell

Mblackwell's Avatar
Re: EDuke32: Artifical Intelligence 101
Reading your post and thinking about the various situations, it wouldn't require that much extra modification to what I said should be your base when considering AI. A few more if conditions to double check things and you're good to go, although in your case you may WANT to program in stupidity in order to having a sliding scale of difficulty.
__________________
I don't wanna be like other people are
Don't wanna own a key, don't wanna wash my car
Don't wanna have to work like other people do
I want it to be free, I want it to be true

Eduke32.com : The Rejected Applications : The Meadhall of the Comitatus
Mblackwell is offline  
Old 06-02-2008, 09:17 PM   #18
DeeperThought

DeeperThought's Avatar
Re: EDuke32: Artifical Intelligence 101
Quote:
Originally Posted by Mblackwell View Post
Reading your post and thinking about the various situations, it wouldn't require that much extra modification to what I said should be your base when considering AI. A few more if conditions to double check things and you're good to go, although in your case you may WANT to program in stupidity in order to having a sliding scale of difficulty.
Yes, you can have an AI like what you described for handling the actual fighting (although it's kind of cool to have a predictable pattern based AI for that old school feel), but those "few more if conditions" are not just a trivial addition, and they do in effect add a prioritization of goals.

Anyway, I don't think there is any real disagreement here, we are just emphasizing different things.

Too bad no one is taking up Reaper_Man on his generous offer to supply code.
__________________
DUKE PLUS
New map effects and various optional extras for Duke 3D.

DUKE NUKEM: ATTRITION
XP based weapon upgrades, progressive difficulty, and more.
DeeperThought is offline  
Old 06-03-2008, 02:18 AM   #19
Jblade

Jblade's Avatar
Re: EDuke32: Artifical Intelligence 101
A 'problem' I've had is getting enemies to jump at times that are appropriate. At the minute I get them to just jump randomly if the player's higher, but that doesn't work all the time. I think the best solution to this problem would be to only jump if it's not moving, but what would be the best way to get them to jump over things like gaps? (hitscan would be involved but I don't really know that much about it)
Jblade is offline  
Old 06-03-2008, 08:09 AM   #20
DeeperThought

DeeperThought's Avatar
Re: EDuke32: Artifical Intelligence 101
Quote:
Originally Posted by Jblade View Post
what would be the best way to get them to jump over things like gaps? (hitscan would be involved but I don't really know that much about it)
The only time I attempted to solve that problem was in my DNA mod, but that was using a botpathing system. I would tag certain nodes on the path so that the bot would know it is supposed to jump when it gets to them. It's very hard to give a bot good information about where it can go in its environment without some kind of pathing system.
__________________
DUKE PLUS
New map effects and various optional extras for Duke 3D.

DUKE NUKEM: ATTRITION
XP based weapon upgrades, progressive difficulty, and more.
DeeperThought is offline  
Old 06-03-2008, 02:03 PM   #21
Reaper_Man

Reaper_Man's Avatar
Re: EDuke32: Artifical Intelligence 101
DT is correct, it is nearly impossible to have a bot examine it's surroundings at any given point without some point of pathfinding or waypoint system. To go off on a tangent here... What you could possibly do is, every few seconds have the bot do a routine where it spawns a few invisible "eye" actors in a radius around it. These would spawn from the actor and move forward a short distance, 4096 units or so, and return data to the bot. This would be useful because you could check if the Bot was about to run into a wall, or where the walls around it were, how high the surrounding area is relative to the Bot, and so on. This is not the best method for examining the environment, but combined with an effective waypoint system it could be very powerful.

To your question though, how do you get an AI to jump effectively? The answer is right there - when DO you want it to jump? Having AI jump when it is stuck on low walls is probably the most common instance of when you would want the AI to jump, and the easiest solution is very simple. Taken from the AWOL Helper AI:

Code:
    ifnotmoving
    {   
        ifrnd 64
            operate
        else ifrnd 8
        {   
            action ABOT_JUMP
            move BOT_JUMPVELS faceplayer
            break
        }
    }
This bit of code is located in the "moving/walking" state and is only checked when the AI should be trying to move forward. It should be self explainatory - If the AI thinks it should be moving, and it is obstructed in some way (using "ifnotmoving") then it will attempt to either use a button/door, or attempt to jump over the obstacle.

One thing you would probably want to add is to add a flag for if the AI has already attempted to jump, so that if it tries to jump again in the same location it knows that it can't or that jumping there does not help it, so it should turn around and try to find a different path.
__________________
The Once and Future King
msleeper.com :: Digital Entertainment Design
The AWOL Project :: The Best Damned TC Never
Super AI Project / Duke RTS :: Coming Soon to an Actor near you!
Artificial Intelligence 101 :: Ask AI questions, get AI answers
Reaper_Man is offline  
Old 06-03-2008, 02:29 PM   #22
Jblade

Jblade's Avatar
Re: EDuke32: Artifical Intelligence 101
I did something similar to that, but I didn't think of adding a flag so that the AI knows not to keep jumping in that same spot - thanks
Jblade is offline  
Old 06-03-2008, 02:31 PM   #23
Reaper_Man

Reaper_Man's Avatar
Re: EDuke32: Artifical Intelligence 101
A quick idea, make a per-actor variable LASTJUMPX and LASTJUMPY, and every time that the AI jumps have it put it's current X/Y location into those variables. The next time that it wants to jump, have it do a distance check between it's current location and the LASTJUMPX/Y, and if it is far away enough from the last location, it should jump again. If not, do whatever - turn around, try crouching, etc.

Example pseudo code:

Code:
state botwalkstate
    (Walking/Running code, etc.)

    ifnotmoving
    {
        getactor[THISACTOR].x tempx
        getactor[THISACTOR].y tempy

        // Get the distance between the actor and our last jump position
        subvarvar tempx LASTJUMPX
        mulvarvar tempx tempx
        subvarvar tempy LASTJUMPY
        mulvarvar tempy tempy
        addvarvar tempx tempy
        sqrt tempx tempx

        ifvarg tempx 8192 // Minimum distance from last jump position before we will jump again
        {
            (Execute jump code here)
        }
        else // The actor is within the last jump position, so let's do something besides jump
        {
            (Execute other AI code here since we don't want to jump)
        }
ends

state botjumpstate
    (Jump action, movement, etc.)

    getactor[THISACTOR].x tempx
    getactor[THISACTOR].y tempy
    setvarvar LASTJUMPX tempx
    setvarvar LASTJUMPY tempy
ends
__________________
The Once and Future King
msleeper.com :: Digital Entertainment Design
The AWOL Project :: The Best Damned TC Never
Super AI Project / Duke RTS :: Coming Soon to an Actor near you!
Artificial Intelligence 101 :: Ask AI questions, get AI answers
Last edited by Reaper_Man; 06-03-2008 at 04:48 PM.
Reaper_Man is offline  
Old 06-03-2008, 03:00 PM   #24
DeeperThought

DeeperThought's Avatar
Re: EDuke32: Artifical Intelligence 101
In practice, doing stuff like never works very well. Sometimes there will be a legitimate jump it can do and it will decide not to because it is within the last jump distance. If you make the distance smaller, then you will get the opposite problem. Also, I see you are only checking the xy distance without regard to z, which will prevent the bot from using a series of jumps to climb structures. Then there is the problem of deciding whether the last jump succeeded. If it did, you don't want to stop it from jumping again (and even if it didn't work, it could have been because of some temporary factor like a sprite above the bots head that is no longer there). The basic problem is you are using the last jump location as a proxy for having detailed information about the environment, but it's not a good substitute.
__________________
DUKE PLUS
New map effects and various optional extras for Duke 3D.

DUKE NUKEM: ATTRITION
XP based weapon upgrades, progressive difficulty, and more.
DeeperThought is offline  
Old 06-03-2008, 03:21 PM   #25
Reaper_Man

Reaper_Man's Avatar
Re: EDuke32: Artifical Intelligence 101
Yeah, it is definitely not the best or the most elegant solution nor was the code I provided a "final draft" that anyone should just copy and paste into their own AI. The idea is the same - "figure out where I was in relation to where I am and see what I should do". An easy fix to the climbing structures example would be to negate the last position check if the actor is higher (or lower) than when it was at the last jump. Adding in a "setactorvar[THISACTOR].LASTJUMPZ" would be simple, but again, not a complete or comprehensive solution to all of the problems.
__________________
The Once and Future King
msleeper.com :: Digital Entertainment Design
The AWOL Project :: The Best Damned TC Never
Super AI Project / Duke RTS :: Coming Soon to an Actor near you!
Artificial Intelligence 101 :: Ask AI questions, get AI answers
Reaper_Man is offline  
Old 06-03-2008, 03:48 PM   #26
Jblade

Jblade's Avatar
Re: EDuke32: Artifical Intelligence 101
Well - it helps in anycase On a unrelated note, I'm confused why you're using 'setactorvar' instead of just setting it normally. I guess there's a good reason why, but I always just used setvar for per-actor variables myself (is it related to sync and multiplayer?)
Jblade is offline  
Old 06-03-2008, 03:54 PM   #27
Reaper_Man

Reaper_Man's Avatar
Re: EDuke32: Artifical Intelligence 101
I am sure DT or TerminX will correct me if I am wrong, but as far as I am aware it does help with sync issues. For me it is also a programming style issue, I think it is cleaner and easier to keep errors omitted if you are as specific as possible when setting vars.
__________________
The Once and Future King
msleeper.com :: Digital Entertainment Design
The AWOL Project :: The Best Damned TC Never
Super AI Project / Duke RTS :: Coming Soon to an Actor near you!
Artificial Intelligence 101 :: Ask AI questions, get AI answers
Reaper_Man is offline  
Old 06-03-2008, 04:04 PM   #28
Hunter_rus

Hunter_rus's Avatar
Re: EDuke32: Artifical Intelligence 101
setactorvar[THISACTOR].VAR1 VAR2
...is equivalent to...
setvarvar VAR1 VAR2.

The only difference is the setactorvar allows you to specify the index which doesn't have to be THISACTOR.
Hunter_rus is offline  
Old 06-03-2008, 04:08 PM   #29
TerminX

TerminX's Avatar
Re: EDuke32: Artifical Intelligence 101
I would not recommend using something like "setactorvar[THISACTOR]" unless you want your compiled code to be a little bit larger, take a little bit longer to compile and run a little bit slower. There is zero effect on sync.
TerminX is offline  
Old 06-03-2008, 04:16 PM   #30
Reaper_Man

Reaper_Man's Avatar
Re: EDuke32: Artifical Intelligence 101
Quote:
Originally Posted by TerminX View Post
. . . compiled code to be a little bit larger, take a little bit longer to compile and run a little bit slower.
Did not know this! Thanks for the info as always TX. Is the same true for "getactorvar[THISACTOR]" in regards to execution speed or is it only the setting of vars that affects it?
__________________
The Once and Future King
msleeper.com :: Digital Entertainment Design
The AWOL Project :: The Best Damned TC Never
Super AI Project / Duke RTS :: Coming Soon to an Actor near you!
Artificial Intelligence 101 :: Ask AI questions, get AI answers
Last edited by Reaper_Man; 06-03-2008 at 04:22 PM.
Reaper_Man is offline  
Old 06-03-2008, 04:38 PM   #31
TerminX

TerminX's Avatar
Re: EDuke32: Artifical Intelligence 101
Did you mean getactorvar instead of getactor? If so, "getactorvar[THISACTOR].LASTJUMPX LASTJUMPX" is a very redundant statement which I would also recommend never using.

Here's why setvarvar is faster than setactorvar[THISACTOR].somevar somevar:

First, we have the code for setactorvar:
Code:
    case CON_SETACTORVAR:
    case CON_GETACTORVAR:
        insptr++;
        {
            // syntax [gs]etactorvar[<var>].<varx> <VAR>
            // gets the value of the per-actor variable varx into VAR
            // <var> <varx> <VAR>
            int lSprite=GetGameVarID(*insptr++, g_i, g_p), lVar1=*insptr++, lVar2=*insptr++;

            if (tw == CON_SETACTORVAR)
            {
                SetGameVarID(lVar1, GetGameVarID(lVar2, g_i, g_p), lSprite, g_p);
                break;
            }
            SetGameVarID(lVar2, GetGameVarID(lVar1, lSprite, g_p), g_i, g_p);
            break;
        }
...and for setvarvar:

Code:
    case CON_SETVARVAR:
        insptr++;
        j=*insptr++;
        SetGameVarID(j, GetGameVarID(*insptr++, g_i, g_p), g_i, g_p);
        break;
As you can see, setactorvar requires 3 extra ints be pushed onto the stack every time its executed, and also requires an extra gamevar lookup to handle which sprite to operate on whereas setvarvar just uses the index of the current sprite.

Storing the reference to the extra gamevar needed for setactorvar also uses 4 bytes of extra space in the compiled code. It looks like setactorvar/getactorvar can be optimized slightly by removing "lVar2" and reusing the existing int "j" however so I suppose I'll make that change now, while I'm still looking at the code.

All things taken into account, setvarvar is probably 50% (or so) faster than the setactorvar stuff you were using. It doesn't seem like much by itself, but it adds up when you're making these calls thousands of times per game tic.
TerminX is offline  
Old 06-03-2008, 05:00 PM   #32
Reaper_Man

Reaper_Man's Avatar
Re: EDuke32: Artifical Intelligence 101
Yeah I meant getactorvar, I made that edit a few minutes after I saw the mistake. Again thanks for the info!

Jblade - I updated my example code with all of this in mind so it should be a bit safer to use.
__________________
The Once and Future King
msleeper.com :: Digital Entertainment Design
The AWOL Project :: The Best Damned TC Never
Super AI Project / Duke RTS :: Coming Soon to an Actor near you!
Artificial Intelligence 101 :: Ask AI questions, get AI answers
Reaper_Man is offline  
Old 06-03-2008, 10:03 PM   #33
The Commander

The Commander's Avatar
Re: EDuke32: Artifical Intelligence 101
I will soon have to start working on a code for these cars to move around the roads and stop at intersections in a some what realistic fashion...
Im thinking of a waypoint system that when it gets to a stop point for it to stop for a few moments then move to the next point.

EDIT: If this is looking very familer to you (the picture) it is what it looks like. lol
Attached Images
File Type: jpg duke0000.jpg (151.3 KB, 32 views)
__________________
I Know Everything There Is To Know About Anything.

Duke Nukem Red Alert SVN

Ask Me Anything!
The Commander is offline  
Old 06-04-2008, 06:56 AM   #34
Jinroh

Jinroh's Avatar
Re: EDuke32: Artifical Intelligence 101
Quote:
EDIT: If this is looking very familer to you (the picture) it is what it looks like. lol
So it is supposed to be like GTA/GTA 2 for the PC/PSX/GBC/GBA Style older GTA Games?

As far as the thread, nice AI thread. Very enlightening, not unlike some of the Quake Bot AI threads I've read.

Kudos.
Jinroh is offline  
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 07:05 AM.

Page generated in 0.25470996 seconds (100.00% PHP - 0% MySQL) with 16 queries

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2020, vBulletin Solutions, Inc.

Website is 1987-2014 Apogee Software, Ltd.
Ideas and messages posted here become property of Apogee Software Ltd.