AI

Blitz3D Forums/Blitz3D Programming/AI

Jerome Squalor(Posted 2008) [#1]
Hi, i'm pretty new at Ai programming so i was wondering if anyone could give me some nice tutorials or instructions on some basics

thnx


mtnhome3d(Posted 2008) [#2]
It depends on what the object thats is "AI-ed" is supposed to do. if its a baddie it needs to move in such a way as the type of baddie would move and so and so forth
without knowing what the object is its hard to help

for starters get to know entitydistance real well and linepick.


Jasu(Posted 2008) [#3]
I've written a very competent AI for my game without ever seeking any information or reading a tutorial about creating one. It took a few days to come up with the idea and a lot days more to make it work, but it's not impossible.

The basic good idea is thinking in states. 'Finite state machine' as the academics call it. First think of values the AI should be gathering about it's surroundings and itself.
- My health is low
- Enemy present
- Multiple enemies present
- Enemy outnumbered
- I am outnumbered
- Route to enemy is blocked

Then according to these values, your AI should decide a state it is in.
- Agressive attack
- Defensive attack
- Flee
- Move to X
- Wait

Then according to the state, AI should prioritize whether to shoot or move or anything it could be doing.

Please keep in mind that although it makes AI coding easier to do 'AI cheating', it drives people crazy. So if possible, make your AI so that it doesn't have capabilities the human player doesn't have.


Ross C(Posted 2008) [#4]
Also, you may want to look into path finding, to help your cpu characters find their way round the enviroment.


Jasu(Posted 2008) [#5]
Yes, path finding is basically a chapter of its own. There are also lots of other issues, like AI teamwork. There are always ways to improve your AI, but there's rarely a need for best of the best solution. Just think what you need for your game.

There's also another approach to AI. An action score system. Define all the possibilities AI can do and give points to those actions with some predefined system. The action with most score is chosen. It requires some heavy testing in balancing the scoring system, but when it works, AI can be suprisingly human-like.


Sokurah(Posted 2008) [#6]
A couple of good posts there.

The best I can offer is, if you tell us what kind of game you're looking to make an AI for - it would be easier, to more correctly, guide you to the best solution, if we know what kind of game it's needed for.


Jerome Squalor(Posted 2008) [#7]
wow, i go to bed and when i get up there are six posts!

anyway, Thnx for all the advice.the game i am trying to write is a FPS paintball game. The AI will be for the other members of the player's team and the members of the opposite team. The members of the player's team will need to be able to locate each of the other team members and then start shooting at them. The opposite team will have to do pretty much the same thing, only, against the player's team. all the AI controlled characters will need to find their way from bunker to bunker.

thnx in advance


jhocking(Posted 2008) [#8]
Abstract overview:
Make a function called ProcessAI() or something and have it loop through each of the AI characters. For each character, evaluate what things are like currently (eg. use LinePick to "see" what is ahead of the character) and then have the character choose a reaction to the situation (eg. if they don't see anything, continue walking; if they see the player, shoot.)


mtnhome3d(Posted 2008) [#9]
i'm working on the ai in my game also.
here it is use it if yu want. its based on the "AIscore" idea.
Function getenemystate()
For e.enemy=Each enemy
 For c.char=Each char
  EntityPick (e\e,150)
  ;check disance
  e\score=100
  If EntityDistance(e\e,c\e)>50 
   e\score=e\score-50
  Else If EntityDistance(e\e,c\e)>30 
   e\score=e\score-30
  Else If EntityDistance(e\e,c\e)>20 
   e\score=e\score-20
  Else If EntityDistance(e\e,c\e)>10 
   e\score=e\score-10
  End If
  ;check health
  If e\hp<80 
   e\score=e\score-10
  Else If e\hp<60 
   e\score=e\score-20
  Else If e\hp<40 
   e\score=e\score-30
  Else If e\hp<20 
   e\score=e\score-40
  Else If e\hp<10 
   e\score=e\score-60
  End If
  ;check whats infront of it
  If PickedEntity=c\e 
   e\score=e\score+20
  Else If Not PickedEntity=c\e 
   e\score=e\score-10
  End If
  DebugLog "hp "+e\hp
  DebugLog "AIscore "+e\score
  ;"normalize" the score
  If e\score>100 
   e\score=100
  Else If e\score<0 
   e\score=0
 
  End If
 Next
Next
End Function




jhocking(Posted 2008) [#10]
What is the point of the score?


mtnhome3d(Posted 2008) [#11]
to determin an action later on. in the updateenemy command i check the score and if it is <> a cetain value it will do something. the posted code was a example of sorts for a method posted ealier by jasu.


Stevie G(Posted 2008) [#12]
For a major speed boost, should this ..

For e.enemy=Each enemy
For c.char=Each char
EntityPick (e\e,150)

Not be this?

For e.enemy=Each enemy
EntityPick (e\e,150)
For c.char=Each char

Otherwise you are repeating the same pick for every instance of char unecessarily.

Stevie


mtnhome3d(Posted 2008) [#13]
yeah probably. :)


chwaga(Posted 2008) [#14]
I don't know much of anything about AI programming, but I know the basic logic of it...I just need pathfinding GAH!!!

The purpose of using a score system is so you can evaluate the best possible decision, so you loop through all surrounding conditions, and score each condition. For example, If playerhealth > (npcHealth * 2) then choicescore = choicescore-50. This way, you can evaluate your choicescore at the end of processing the conditions, so you can say: if choicescore < 20 then runaway(). Using a system like this, you can make an AI usually choose the best action for the current decisions, and you could even make "personalities" using the score system, for example, for a cowardly npc this would be more realistic: if choicescore < 40 then runaway. Basically, higher choicescore would mean the conditions are leaning further toward the npc, and it stands a better chance if it were to fight than if it ran away. A choicescore system would work best when integrated with a finite logic system, so you can further enhance the personalities of different npc's, so as to extend the logic from numbers to numbers and if statements, for example:

if choicescore < 20 and surroundingallies < 1 then
runaway()
elseif choicescore < 20 and surroundingallies > 1 then
standandfight()
endif
;this would do something to the effect of, if conditions are bad and there are no allies around, run away, 
;if conditions are bad and there are allies around, stand and fight

hope that helped.


Jerome Squalor(Posted 2008) [#15]
hi,

i've been trying some basics with AI but i ran into a problem which i am guessing is very simple, i just can't figure it out

here is my code:



my problem is at CollisionEntity(b\shape,countcollisions(b\shape))

i get a MAV saying 'collision index out of range'

any suggestions?


mtnhome3d(Posted 2008) [#16]
change collisionentity to entitycollided(b\shape,3) this will work. if you stop this piece of code and look at the veriables it says the enemy and goodguy types are null but i can't find out why.


mtnhome3d(Posted 2008) [#17]
hi again i was trying to use jerome's code for the ai in my game cause my verson wasn't working very well in this context. i got everything setup and tryed running it and the ai won't update its self. it stays at a constant state and won't move to another one. also it won't delete the badie when its health gets to low even though it was working when i had my sytem in place.



Stevie G(Posted 2008) [#18]
If (dist < 200 And dist > 500)
   e\State = chase
ElseIf (dist < 100 And dist > 200)		
  e\state = attack
ElseIf (dist > 1000)
 e\state = roam
EndIf


Unless the dist > 1000 no state change will happen. How can dist be < 200 and > 500 or < 100 and > 200 !!?

if dist > 1000
   e\State = roam
elseif dist < 100
   e\State = attack
elseif dist < 200
   e\State = chase
endif



Only problem with this is that if dist >=200 or <= 1000 nothing will happen. You may want to set the state to roam if dist >= 200.

Stevie


mtnhome3d(Posted 2008) [#19]
thank you very much it works great now just a little more and i'll release a demo.