AI

Blitz3D Forums/Blitz3D Programming/AI

patisawesome(Posted 2003) [#1]
How do I create an AI that interact with eachother?
-me


Zo Zo Zee Zar(Posted 2003) [#2]
erm...code it?


Rob(Posted 2003) [#3]
Function AI_follow(enemy,player)
pointentity enemy,player
moveentity enemy,0,0,1
end function

now you can do AI_follow(ball,camera)
and the ball will follow and chase the camera.

It should get you started.


ckob(Posted 2003) [#4]
what rob said is the best and easiest way :) or you can do

function make_really_awesome_super_realistic_AI_now()

end function


MadJack(Posted 2003) [#5]
Have a look at this identically named thread from a little while ago:
http://www.blitzbasic.co.nz/Community/posts.php?topic=27676


patisawesome(Posted 2003) [#6]
Hmmm... that should help me for now.
Thanks!
-me


ChrML(Posted 2003) [#7]
Lol, patisawesome: You obviously don't know what programming is. You can't do: StartANewMissionWhereYouStartBehindAWindow(player,enemy), and then you suddenly start in a grand mission. In programming each little detail has to be programmed. If you've seen Matrix, then you hear them explain that all AI in computers are based on rules. Like the agents in Matrix are :P.


(tu) sinu(Posted 2003) [#8]
"function make_really_awesome_super_realistic_AI_now()

end function "

i'll be coding a.i for my 3d platformer soon, hopefully will be good enough to release the source.


poopla(Posted 2003) [#9]
AI is one of the most confusing subjects you can look into as far as programming goes(it just contains so many fields of logic). May I advise you sit down and decide what you want this A.I. to be capable of, then think of what it takes to perform said tasks in the real world. Break the actions down into the smallest possible systems within reason, then code those indevidual systems. Just try and keep each of the AI's subroutines simple.


ChrML(Posted 2003) [#10]
AI is a simple thing to code. Just find the logic, which should be easy in almost any cases, and then write it in code. Confusing stuff in programming is physics, not AI.


MadJack(Posted 2003) [#11]
Well of course, ChrML has hit the nail on the head! Just 'find the logic' and then 'write it in code'! Simple!

And if you want AI that's any more advanced than Pacman, just 'find the logic' and then 'write it in code'! Brilliant!

Everyone repeat after me now, 'find the logic' and then 'write it in code'! Hurrah!


poopla(Posted 2003) [#12]
Hahaha. ChrMl, I recall you saying (to patisawesome?) That he has no idea what programming is. Physics is hard, but replicating a neural circuit system like the human(or alien may it be) brain uses to INTELLIGENTLY make decisions is something NO ONE has done (were getting close however). However, I see lots of physics engines poping up with near real world accuracy.

Where did you 'find the logic' that AI is easy? If your talking about coding finite state machines(pac man crap AI) then all good and well, that is easy enough. However, I spent a month writting 5000 lines of test code to simulate an insect doing insect things. People are a little more complex then that, so I doubt making one act realistically in game is not "simple".


puki(Posted 2003) [#13]
"ChrML" is right in a way, I know what he means - Anyway "patisawesome" needs to be more specific with asking about how to make the AI do what he wants. "Rob" took an obvious fast route to the question as there is not a lot else you can do. I note "patisawesome" has now removed the door he put in his "game", maybe he wanted to know how to make it open (by the player walking up to it, or by pressing an open button) - maybe he wants the character he added to be able to "see" the player and shoot back, run away, come after the player, lock the door? Who knows?


ChrML(Posted 2003) [#14]
Real Intelligence, which is the opposite of Artificial Intelligence is impossible to make on computers, because computers are built on math, which means logic. And, logic explaination can never be intelligent. Stuff you explain logically, which means step for step, can NEVER think by itself, so because of that, AI can never think only by itself.

AI means that we have programmed in lots of cases, and several rulez it moves by. Like this: If near both hiding place 1 and hiding place 2 (which is set by nodes), then it's 30% chance that I will move to place 1, and 60% chance for that I will move to place 2, and 10% chance that I will go somewhere else. Maybe not the best example, but you get what I mean.


Bot Builder(Posted 2003) [#15]
I desagree. I believe that humans are no different from other matter, and that our brains may one day be accuately simulated to the point that they believe they are intelligent and can make intelligent dicisions. AI doesn't mean that we have programmed in several rules that it moves by. there have been many cases where people have applied artificial neural networks, when the network knows nothing about what it's doing except for a good/bad response from an enviornment. JUST LIKE A HUMAN. We are programmed by evolution to interpret good and bad. for instance physical damage. Our brain, a massive neural network learns to avoide these cases.

ChrML is talking about the standerd FSM approach to AI, which looks ok, but isn't intelligent. An Infinite State machine (described on blitzcoder) however, could become intelligent by having rules that create and manipulte other rules. Another system that possibly allows for intelligent AI is a GA, or genetic algorithm. This is basically a sped up simulation of computer evolution, continuealy testing the AI's code against a fitness test, and allowing the most fit ones to mutate or crossover.

Who says our brains aren't step by step? A neuron fires, causing another neuron to fire, causing a whole series of neurons to fire in different ways, combining with other input data, and eventually triggering a message that travels along the spinal cord. It is nearly impossible that these events would start at the same time. instead the impulses 'slowly' (okay, so insanely fastly) travel around the brain and back down the spinal cord. What makes it impossible to run the brain through an extremly acurate physics sim? Sure we don't have the technology now, but I don't see any problem with it.

Also, there are more AI examples than physics example. almost every single complete game relesed with blitz has AI somewhere. Whether it's random motion or neural networks, it still classifies as an artificial attempt at reprouducing intelligence.


patisawesome(Posted 2003) [#16]
Okay, this is getting a little out of hand. I think that bot builder is correct. I heard of a program in which a little guy moves around in a maze and makes decisions based on his surroundings. What I'm trying to get is an AI with a virtual brain, and attacks other AI.
-me


MadJack(Posted 2003) [#17]
patisawesome

Go to

http://www.blitzcoder.com/cgi-bin/showcase/showcase_frontpage.pl

and browse the 'action' category entries (if you haven't already). There's a number of small projects similar to what you've mentioned that include source code.

But the first question would be, have you decided on your pathfinding method?


Bot Builder(Posted 2003) [#18]
The easiest convincing method I know of, as mentioned in my last post is to employ a Finite State Machine. Your code would basically look like this:

const STATE_FULLHEALTH
const STATE_MODERATE
const STATE_WOUNDED
const STATE_NEARDEAD

type enemy
 field entity
 field action
 field state
 field health
 field ammo[9]
 field weapon_flags
 field team
 field alive
 field enemynear
end type

function UpdateEnemies()
 for e.enemy=each enemy
  if e\alive then
   scan_area()
   select e\state
   case STATE_FULL
    if e\enemynear then
     fight
    else 
     patrol
    endif
   case STATE_MODERATE
    if e\enemynear then
     fight_protectivly
    else 
     patrol
    endif
   case STATE_WOUNDED
    findhealth
   case STATE_NEARDEAD
    if e\enemynear then
     kamakazee
    else
     findhealth
    endif
   end select
  endif
 next
end function


this obviously isn't full AI code. You still need to write the functions. I'm not even sure if I had any syntax errors, since this was written directly into the post.


puki(Posted 2003) [#19]
I admit in advance that the following is somewhat crude - but it is meant as a guide:

"patisawesome" - So you want AI with a virtual brain, which also attacks the player. There are pathfinding routines and AI links in the "Algorithms" section of the code archives.

"patisawesome" - This is no easy subject - a lot of commercial games have naff AI - some have smart AI - Look at it from a simple point of view (without doing too much at once) - You need your enemy to spot you. A crude (because it isn't 100% and you could use "LinePick") way of doing this is with "EntityVisible" to check between the enemy and you (the camera/or whatever you are referencing to) - it will be true or false. You could then set a flag ("EnemySeesMe=1" for example to kick in the "AI" - now that the enemy sees you it can now come after/shoot you/run away, etc. Baring in mind that if "EntityVisible" becomes false (you can't see each other, albeit in a crude way) you can decide to either make the enemy stop/search for you/carry on firing where you where when it last saw you/heal itself (if it was injured)/re-load its gun, etc.

When the enemey "sees" you, you can point it to you with "PointEntity" (see "Rob's" reply) and effectively make it come after you. Or you can just point it to you and allow it to start shooting or both shoot and come after you. If you are playing in an open area then making it come after you is simple enough (this is why I was asking about your environment previously). If you want it to chase you down/wander corridors, etc. then you need "Pathfinding too" - In simple terms this can be done with nodes/waypoints. So, for example, if your enemy is going down a corridor that leads to a junction (with options of straight on, left or right), you will want to make the AI "decide" where to go - if it can see you then the decision is made (providing you want it start shooting/chasing you) - if it cannot see you then maybe it can "hear" you - maybe it can see footprints, etc. - or it can just "decide" to pick a route (If the AI has "memory" then it can search areas it hasn't been in).
| |
|* |
-------------- -----------------|
* * * *|
--------------| *|--------------- |
| | | *|
| --------------- |
| * *|
----------------------

This is somewhate crude, but imagine the "*"'s as your waypoints/nodes - these help the enemy from one place to another. I previously suggested you look at "Samples\Blitz 3D Samples\si\fps\fps.bb" - there are nodes/waypoints in this code - this is how the enemy is moving around the level. Take another look. You could apply the old Pacman AI here as a FPS can be a bit like Pacman but in a first person view point - it can help to look at/imagine your level/environment from a "plan view" perspective at times.

Hopefully, you can now see how complex the AI can start becoming even with doing one thing - who's to say the enemy couldn't also call for help/press the alarm button/turn the lights off/on, etc. This is why giving you a answer for AI with a "virtual brain" is a big answer - ID Software want it too! Nobody is going to hand it over to you.

Why not forget about head-bobbing and bullets for the time being and play around with AI - head-bobbing is cosmetic, and you can still shoot things without creating bullets and making them collide with a target. Ideally concentrate on one thing at a time - you'll probably get better help in the forums.


puki(Posted 2003) [#20]
"patisawesome" sorry my little ASCII diagram went screwy when I posted


patisawesome(Posted 2003) [#21]
I tried to make my enemy turn out lights, and I (tried) to make them turn back on, but they won't!
-me


Ross C(Posted 2003) [#22]
if you do an ascII diagram in a [ code ] box, it should work :)

| | 
|* | 
-------------- -----------------| 
* * * *| 
--------------| *|--------------- | 
| | | *| 
| --------------- | 
| * *| 
----------------------



Ross C(Posted 2003) [#23]
mmmm....maybe not then :p


GitTech(Posted 2003) [#24]
Maybe use dots instead of spaces?

---------------
|..*..........|
|.............|
|.........*...|
---------------


EDIT: Yep, it works :)


patisawesome(Posted 2003) [#25]
How do you do the code box?
-me


GitTech(Posted 2003) [#26]
{code}
...
{/code}

Replace {} with []


patisawesome(Posted 2003) [#27]
thanks!

AAAHHHHHHHHHHHHH!!!!!!!!!!!!!!!!!!!!!!!WEEEEEEEEEEEEEEEEE!!!!!!!!!!!!!!!!!!!!!!!

-me


puki(Posted 2003) [#28]
"patisawesome" - your back - I've been off doing other things. How is the "AI" going? I'm currently messing with/adding (probably loads) to Simon Harrison's FPS demo code (the one I refered you to). How are you getting on with it?

Sorry my ASCII thing didn't work - for a real-time example, add (before main loop):

visible_node=CreateSphere()
For a=1 To 10
CopyEntity visible_node
PositionEntity visible_node, node_x(a), node_y(a), node_z(a)
Next

Then you'll see little "domes" on the walkways - beats looking at an Ascii diagram. - try playing with the positions of them - they're plotted in 3D space. This isn't AI though.

I'm working on a demo (like a FPS game level) of it to include AI with "memory" and AI that can "learn"/"adapt" (the "Alien" films gave me some ideas) - I won't start properly doing it until after Christmas, when I have some holiday, as I need to add more "areas" to it - but you may be interested in the end result.


puki(Posted 2003) [#29]
"patisawesome" PS. I'll be doing lighting too

In the meantime:

A good on/off toggle is:

If KeyHit( whatever key you use )
"lighton"=Not "lighton"
If "lighton" Then ShowEntity "light" Else HideEntity "light"
EndIf

I think I've written it right - try it - see ya!