Game NPC AI ideas

Game development specific discussions.
leopardpm
Posts: 1795
Joined: Feb 28, 2009 20:58

Game NPC AI ideas

Post by leopardpm »

This thread was created as an off-shoot from another thread involving a discussion with Paul Doe. The main reason I am creating it is to get his (and others) feedback on different possible other approaches to achieving my 'end goal' in the creation of a complex Game NPC AI.

Before getting to this end goal, some quick background: I am an avid player of RTS(Warcraft 2/3, Age of Empires, etc), City-Building(Dwarf Fortress, Towns, Goblin Camp, etc) and MMORPG games genres. Besides gaming/programming, I am also a dedicated amatuer economist and enjoy reading articles/lectures/studies regarding economics. RTS games have kinda gone out of style, and MMORPG games have been stuck in a rut for 15 yrs. My thoughts are to combine the 3 genres, add in a dash of complex AI combined with actual economics, and solve the issues.

Problems with MMORPG's: (not necessarily in the order of degree...)
#1 - Content Creation: It takes a huge ($) investment to generate new content for players to explore and solve. It is slow and, in the end, becomes repetitive since it is all created within the same framework/context of the original setting/game.
#2 - Slow Periods: Though MMO's can have 1,000's of total players, at any given moment, in any given area, there can possibly no one around. This is boring for players looking to group up and do things with. Ultimately, if a minimal level of players are not participating, players will quit playing and move on to the 'next thing'...
#3 - Unrealistic Economy: Due to the nature of every MMO, players do not exactly act in the same manner that they would in the real world, which means that the economies of such MMOs will not be very realistic in most things. There is a constant inflation occurring due to the creation of 'money' whenever players obtain items/loot. To combat this, the MMO designers create 'money sinks' which siphon off the money in an effort to balance things. This 'economic' naturally becomes lopsided towards the top-end because all players are progressing in levels and wealth, making the New player isolated - this is a detriment to the New player.

There are other issues that I am sure I have not detailed here, but I will update as I remember them... these are the main ones though (I think)

So, with all that said, here is my basic idea:
By having NPC AI's which exist and interact with the game world in a 'realistic' fashion, all the above issues can be addressed if not solved. NPC's would have goals and desires and be able to progress and upgrade themselves in much the same manner as a player might. They would get tired and need sleep, they would get cold and desire shelter and perhaps a warm fire, as many things as necessary to make them somewhat believable. But, more importantly, as part of their problem-solving ability (basic 'need wood', get axe, chop down tree) also incorporate the ability to trade with each other and to have economic goals. The ability to trade and participate in the economy would automatically open up a variety of interesting 'content' for the players. A forest fire might then make it harder for loggers to obtain wood, raising the price of lumber in the local economy, making it more expensive for a player to build a house.... or.... a player 'blockades' a local iron mine which drives the price of iron weapons up, and the local population then begins to focus on producing and using wooden bows and arrows.... or.... noticing a large price difference between to towns, a player or NPC decides to try to profit from the arbitrage... which means caravans of goods/resources traveling along routes between them, which might be a ripe invitation for other players/NPCs to attempt to ambush/raid these juicy targets, which causes the Trader to hire Bodyguards in an effort to ward off would be highwaymen..... economics is the glue which produces 'content' in the real world and can do so in a game world as well. Note: for the NPC AI to really affect (and mitigate the 'bad' effects that players cause...), there would need to be multitudes of agents, perhaps 1,000s. There are a myriad of other aspects of gameplay I would like to incorporate for the player to do, but, this thread's focus is on the AI....

NPC AI:
Having a ball bounce randomly around 4 walls is AI. Not very 'smart' or 'intelligent' or even interesting, but it is AI. Since the AI I am envisioning is something that will induce the player to believing that the AI is human-like, it must be quite more fleshed out than random movements. There are a variety of different approaches to AI: FSMs, HFSMs, Planners, and I guess even NNs. My opinion is that through a combination of FSMs and a Robust Planner, my goal can be reached without delving into Neural Nets et al.

I will use the term 'Agent' instead of 'NPC' from here on...

AI OUTLINE:
(1) The 'Brain' - This part of the AI determines what Goals the Agent has, both long term and immediate. it is formatted within a rough variation of Maslow's Hierarchy of Needs. Mostly, this portion of the AI is comprised of FSMs/HFSMs and will be the most extensive portion of the total AI.

(2) Memory - Sometimes referred to as 'the Blackboard' where the Agent can store information about the world from past experiences

(3) Agent Sensors - These are things that the brain might incorporate to choose which Goals it desires - Is there an Enemy Nearby? Is it Cold outside? Am I hungry? Am I tired? etc

(4) World Sensors - These are things that are dynamic in the world: weather, resources, etc - basically all things that do not have an 'intelligence' to them, they just operate on basic physics and such. These will also be referenced by the Brain in its processing.

(5) GOAP - Goal Oriented Action Planner: This is the portion of the AI that I am focusing on now. It takes a given Goal and with a set of atomistic actions ('Move to', 'Pickup Axe', 'Chop Tree', 'Make Axe', 'Pick Berries', 'Eat Berries', etc, etc, etc) and figures out an optimal plan to achieve that Goal from the current state of the Agent. A GOAP routine is very similiar to pathfinding and most even use A* in order to generate plans - I don't think that is a very good method because of the strange heuristics used. In theory, GOAP is pretty simple & understandable, but making it robust enough to handle a variety of variations in the Actions is the hard part. Once the GOAP portion is developed, the format allows for easy creation of great amounts of additional Actions in order to provide the AI with many options to achieve their Goals.

(6) ACTION/ACTING - this part of the AI basically follows the current Plan, one step at a time, and acts it out in the world. If the current action is to Chop Down a Tree, then this routine sets the appropriate animation/sound/etc and makes the resulting changes to the world once the action is completed(Tree disappears and is replaced by a pile of wood, the agent moves one unit, etc)

This is all just pie-in-the-sky theory, and my own programming skills are vastly insufficient to achieve the 'grand dream', but I enjoy working on rudimentary aspects and possibly getting some form of limited 'proof of concept' demo working - a 2D world instead of 3D, very limited graphics, mostly focus on the behind-the-scenes AI development. As I mentioned, I am (along with BasicCoder2) fleshing out the fundamental GOAP routines which could be useful in a variety of different game types (RTS, City-Building, etc) and will post things as they become interesting enough for others....
badidea
Posts: 2591
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Game NPC AI ideas

Post by badidea »

I like the idea of a more realistic economy, but to get that right is not easy I think. Another thing is that an (experience) human player will still be a million times more intelligent then an AI-player. So a human player will find tricks to 'abuse' the AI-player. Some AI-learning might be needed to counter this.

One advantage of the AI-player is that it could use all the trading information (value of stuff) in the game. However for more rare items this might not help much.

The real world economy also depends of the number of humans. This amount in 10 years can be estimated with a low error bar, unless world war 3 happens or something. The number of players in a game in 1 year further in time is much more difficult to predict.
BTW, The real economy is also a quite strange thing, if you ask me.

Content creation is also this awesome new place with different buildings, scenery, enemies, etc. Not clear how you plan to provide this. Something like minecraft where players can build there own world maybe. But how to prevent destruction by others in a nice way? The real world has all kinds of rules and enforcers that try to prevent this.

If I quickly browse through the wikipedia article on 'Maslow's hierarchy of needs' I also wonder how to implement certain things at the top of the piramid. E.g. 'Seeking Happiness', 'Pursuing a goal' or even 'Transcendence'. At that level, 'Pursuing a goal' if different then 'how do I get wood'.
leopardpm
Posts: 1795
Joined: Feb 28, 2009 20:58

Re: Game NPC AI ideas

Post by leopardpm »

I really didn't want to make this thread because in all this 'dreaming' of the perfect game, something most gamer/programmers do, thinking about it
is a form of mental masturbation which might be fun, but it ain't the real thing. Also, is such a time suck and distraction from actual programming...

That said, here i go...
badidea wrote:I like the idea of a more realistic economy, but to get that right is not easy I think. Another thing is that an (experience) human player will still be a million times more intelligent then an AI-player. So a human player will find tricks to 'abuse' the AI-player. Some AI-learning might be needed to counter this.
quite true
The real world economy also depends of the number of humans. This amount in 10 years can be estimated with a low error bar, unless world war 3 happens or something. The number of players in a game in 1 year further in time is much more difficult to predict.
BTW, The real economy is also a quite strange thing, if you ask me.
The larger the population, the better the Division of Labor, and so the productivity is better, which means a better Standard of Living. But, that doesn't mean a population of 1,000 could not have an economy.
Content creation is also this awesome new place with different buildings, scenery, enemies, etc. Not clear how you plan to provide this.
Yes. There are different types of content, and the type where a well-planned story with different actors in it combined with interesting and related places (dungeons, etc) is hard & expansive to produce - it also is hard to do procedurally. But I notice alot of folks don't even follow the 'story' of the main quest lines - just doing quests to level up and get to the so-called 'end game' which ends up being raids raids raids... not too exciting after awhile. I also notice alot of people who play decidedly different: there are explorer-types, trader-types, and even folks that enjoy just Farming (remember the Farmville craze a few years back? never understood these folks... In the same vein, there are folks who like hardcore RPG, others who like the command/control of RTS games, and those that like creating metropolises in city-builders/sims. So, my thinking is that having a realistic economy will provide things to do that are interesting for the Farmville-types, the traders, & the crafters. By having a large AI population which realistically responds to incentives and such, this could facilitate almost a different level of playing for those who would rather spend time building up a town to a city, maybe as far as a city-state or nation. This would also provide ability to develop or take real territory with real effects on other players and NPCs. This provides the 'raid' content for those type of gamers, BUT it is rooted in the actual world so the battles and raids and rape/pillage actually matters in how it affects others. There is TONS of balancing issues with doing any of this stuff... so its rather pointless to discus it except as a thought exercise. I have yet to figure out how to provide traditional content that makes sense in such a dynamic type world without it being expensive.
Something like minecraft where players can build there own world maybe. But how to prevent destruction by others in a nice way? The real world has all kinds of rules and enforcers that try to prevent this.
I don't want to prevent destruction by others, but just as there are consequences in the real-world and so it is naturally curtailed, so to in-game.
If I quickly browse through the wikipedia article on 'Maslow's hierarchy of needs' I also wonder how to implement certain things at the top of the piramid. E.g. 'Seeking Happiness', 'Pursuing a goal' or even 'Transcendence'. At that level, 'Pursuing a goal' if different then 'how do I get wood'.
yes, the higher values are much more abstract and harder to visualize in the context of actions, and that is one of my goals once I get a robust GOAP system working is to figure out ways to use it or change it do be able to achieve these 'meta-goals'. BTW, I am not totally against scripting or hardcoded FSMs in any way - the whole point is some sort of perception of realism on the part of the player that would be interesting... so I wouldn\t want to force any bias into choose which AI tools might work best for a situation. But I really like the atomistic nature of GOAP - it just makes sense to me as being pretty realistic.
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Re: Game NPC AI ideas

Post by BasicCoder2 »

leopardpm wrote:NPC AI:
Having a ball bounce randomly around 4 walls is AI. Not very 'smart' or 'intelligent' or even interesting, but it is AI.
Well maybe. That is a the "wandering" behavior I have used for agents. However I would suggest that intelligent behavior requires an end goal (a purpose for the behavior). If the characters do things like wander about, "bounce" off world objects, in order to satisfy a goal (find desired item) then you might call it intelligent behavior (goal seeking behaviour) at least more intelligent than not moving about and waiting for an item to happen along. Intelligent behavior also means recognizing the goal by some action even a simple action like stop moving. Think of the light following robots. Move the light and the robot follows. Or if a cockroach it may move away from light. The key mechanism here is feedback. An air conditioner might seem to have a purpose in turning itself on/off in order to maintain a particular temperature. Without feedback to inform the mechanism of the consequences of its actions it cannot behave "intelligently".
leopardpm
Posts: 1795
Joined: Feb 28, 2009 20:58

Re: Game NPC AI ideas

Post by leopardpm »

BasicCoder2 wrote:
leopardpm wrote:NPC AI:
Having a ball bounce randomly around 4 walls is AI. Not very 'smart' or 'intelligent' or even interesting, but it is AI.
Well maybe.
I was just pointing out that having something 'do' anything and 'react' somehow is a form of AI - it ain't HAL from 2001:Space Odyssey, but it is AI in a basic, technical sense. In the case of a ball bouncing, it is 'sensing' and 'reacting' to the objects it bounces off of, perhaps according to real-world physics (or not).

In any case, that is not what anyone reading this thread is really interested about: they want to know about game agents behaving in a more human-like manner.
Tourist Trap
Posts: 2958
Joined: Jun 02, 2015 16:24

Re: Game NPC AI ideas

Post by Tourist Trap »

leopardpm wrote: In any case, that is not what anyone reading this thread is really interested about: they want to know about game agents behaving in a more human-like manner.
I m' not qualified in AI. I'm still interested by the discussion however and would have liked you to tell us if you definitely want to keep it in the domain of games, or if you are talking more of science and simulation of human intelligence?
About games, from my experience, the human touch of a not-human-player did never come from its real or supposed intelligence, but rather of its well imitating of human mood.
Such a mood could be agressivity, patience, an erratic mood, or a quiet attitude. For a bot, not being absolutly predictible is better.

In few words, if we talk about games here, the bot will look more human to my eyes if he seems to behave according to some emotional state close to something real. Being really intelligent and therefore being almost unchallengeable, this won't be very funny I think.

There is a tool provided for free by Blizzard to set-up and run bots to challenge the AI of Starcraft2. If I get some link, I'll bring it here, it may well interest you if you really like this topic.

link --> starcraft API
http://us.battle.net/sc2/en/blog/20944009
Scripted AI API
Image-based AI API (feature layers)
Documentation, sample code, and sample bots
Support for offline AI vs. AI play
A replay pack of anonymized 1v1 ladder games*
Windows and Mac support
Fully-featured Linux package of the API
leopardpm
Posts: 1795
Joined: Feb 28, 2009 20:58

Re: Game NPC AI ideas

Post by leopardpm »

Tourist Trap wrote:I m' not qualified in AI.
Don't know what 'qualified' means in this context, but I think everyone in this forum is 'qualified' to voice their opinion or give whatever input based on all of our limited knowledge....
I'm still interested by the discussion however and would have liked you to tell us if you definitely want to keep it in the domain of games, or if you are talking more of science and simulation of human intelligence?
more so in games... but the closer to simulate human intelligence/behavior, the better
Such a mood could be agressivity, patience, an erratic mood, or a quiet attitude. For a bot, not being absolutly predictible is better.
I completely agree, these are all 'Character Traits' that will be implemented later on - Each Agent having an Emotional state that can be affected by game events as well as the State effecting their own action choices would be important. But, it is all in the implementation... as well as how the emotional state affects the agent - perhaps being in a 'patient' state does not increase the Players enjoyment of the game or it hardly impacts choices made by the agent. Part n parcel of this topic is to be able to convey TO THE PLAYER what emotional state a particular agent is in, and what and why they are doing actions... else it might appear that the agent is randomly doing stuff and that ain't fun either! Notice, us humans will sometimes anthropomorphize agents or actions EVEN if they are actually random... so the goal is to trick the brain into thinking "Hey! That AI is really acting like a human would!"
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Game NPC AI ideas

Post by dodicat »

leopardpm wrote:
NPC AI:
Having a ball bounce randomly around 4 walls is AI. Not very 'smart' or 'intelligent' or even interesting, but it is AI.

How can a ball bounce around four walls?
It would bounce clean out.
You need 6 walls (unless it is inside a tetrahedron thing).

6 walls could be 5 walls and a glass end wall for viewing.

Code: Select all

 
Screen 20,32,,64
Dim Shared As Integer xres,yres
Screeninfo xres,yres
Dim Shared As Any Pointer im

Type vector
    As Single x,y,z
    #define vct Type<vector>
    #define dot *
    #define cross ^
End Type

Type line3d
    As vector v1,v2
End Type
Type plane
    As vector v1,v2,v3
End Type
Type _object
    As vector position,velocity
    As Single mass,radius
End Type

Operator + (v1 As vector,v2 As vector) As vector
Return vct(v1.x+v2.x,v1.y+v2.y,v1.z+v2.z)
End Operator
Operator -(v1 As vector,v2 As vector) As vector
Return vct(v1.x-v2.x,v1.y-v2.y,v1.z-v2.z)
End Operator
Operator * (f As Single,v1 As vector) As vector 'scalar*vector
Return vct(f*v1.x,f*v1.y,f*v1.z)
End Operator
Operator * (v1 As vector,v2 As vector) As Single 'dot product
Return v1.x*v2.x+v1.y*v2.y+v1.z*v2.z
End Operator
Operator ^ (v1 As vector,v2 As vector) As vector 'cross product
Return vct(v1.y*v2.z-v2.y*v1.z,-(v1.x*v2.z-v2.x*v1.z),v1.x*v2.y-v2.x*v1.y)
End Operator
'subs
Function length(v As vector) As Single
    Return Sqr(v.x*v.x+v.y*v.y+v.z*v.z)
End Function

Function normalize(v As vector) As vector
    Dim n As Single=length(v)
    If n=0 Then n=1e-20
    Return vct(v.x/n,v.y/n,v.z/n)
End Function

Function Rotate3D(c As vector,p As vector,byval angle as vector,scale As vector=Type<vector>(1,1,1)) As vector
    angle= (0.0174532925199433)*angle
     Dim As Single sx=Sin(angle.x),sy=Sin(angle.y),sz=Sin(angle.z)
    Dim As Single cx=Cos(angle.x),cy=Cos(angle.y),cz=Cos(angle.z)
    Dim As Single dx=p.x-c.x,dy=p.y-c.y,dz=p.z-c.z
    Return Type<vector>((scale.x)*((cy*cz)*dx+(-cx*sz+sx*sy*cz)*dy+(sx*sz+cx*sy*cz)*dz)+c.x,_
    (scale.y)*((cy*sz)*dx+(cx*cz+sx*sy*sz)*dy+(-sx*cz+cx*sy*sz)*dz)+c.y,_
    (scale.z)*((-sy)*dx+(sx*cy)*dy+(cx*cy)*dz)+c.z)
End Function 


Function apply_perspective(p As vector,eyepoint As vector) As vector
    Dim As Single   w=1+(p.z/eyepoint.z)
    If w=0 Then w=1e-20
    Return vct((p.x-eyepoint.x)/w+eyepoint.x,(p.y-eyepoint.y)/w+eyepoint.y,(p.z-eyepoint.z)/w+eyepoint.z)
End Function

Sub blow(a() As vector,m As Double)
    For z As Integer=1 To Ubound(a)
        a(z)=m*a(z)
    Next z
End Sub
Sub translate(a() As vector,shift As vector)
    For z As Integer=1 To Ubound(a)
        a(z)=a(z)+shift
    Next z
End Sub

Sub drawpolygon(p() As vector,i As Integer,col As ulong,flag As String="",im As Any Pointer=0) 
    Dim k As Integer=Ubound(p,1)+1
    Dim As Integer index,nextindex
    Dim As Double xc,yc
    For n As Integer=1 To Ubound(p,1)
        xc=xc+p(n,i).x:yc=yc+p(n,i).y
        index=n Mod k:nextindex=(n+1) Mod k
        If nextindex=0 Then nextindex=1
        Line im,(p(index,i).x,p(index,i).y)-(p(nextindex,i).x,p(nextindex,i).y),col
    Next
    xc=xc/Ubound(p,1):yc=yc/Ubound(p,1)
    If flag="fill" Then Paint (xc,yc),col,col
End Sub

Function planedistance(S As PLANE,p As vector,Byref ip As vector=vct(0,0,0)) As Single
    Dim As vector unitcross=normalize((s.v1-s.v2) cross (S.v2-S.v3))
    Dim As Single dist=unitcross dot (p-s.v1)'pv
    Dim As vector ip1=p+dist*unitcross
    Dim As Single d1=length(s.v1-ip1)
    unitcross=-1*unitcross
    Dim As vector ip2=p+dist*unitcross
    Dim As Single d2=length(s.v1-ip2)
    If d1 <= d2 Then ip=ip1 Else ip=ip2
    Return dist
End Function

Sub PAINTBALL(cx As Double,_ 
    cy As Double,_
    radius As Double,_
    col() As long,_  
    offsetX As Double=0,_ 
    offsetY As Double=0,_
    e As Double=0,_       
    resolution As Double=16,_ '32
    im As Any Pointer=0)
    Dim As Integer red,green,blue,r,g,b
    Dim As Double ox,oy,nx,ny 
    ox=cx+offsetX*radius
    oy=cy+offsetY*radius
    red=col(1): green=col(2):blue=col(3)
    For d As Double = radius To 0 Step -radius/resolution
        nx=(cx-ox)*(d-radius)/radius + cx 
        ny=(cy-oy)*(d-radius)/radius + cy
        r=-red*(d/radius-1)
        g=-green*(d/radius-1)
        b=-blue*(d/radius-1)
        Circle im,(nx,ny),d,Rgb(r,g,b),,,e,F
    Next d
End Sub

Function vradius(b As _object) As Single
    Dim As Single d=xres/5
    Return ((1-1.5)*(b.position.z+d)/(2*d)+1.485)*b.radius
End Function

Function Regulate(Byval MyFps As long,Byref fps As long) As long
    Static As Double timervalue,_lastsleeptime,t3,frames
    Var t=Timer
    frames+=1
    If (t-t3)>=1 Then t3=t:fps=frames:frames=0
    Var sleeptime=_lastsleeptime+((1/myfps)-T+timervalue)*1000
    If sleeptime<1 Then sleeptime=1
    _lastsleeptime=sleeptime
    timervalue=T
    Return sleeptime
End Function
'variables
Dim As vector e(1 To 24),ve(1 To 24),pivot=vct(xres/2,yres/2,0)
Dim As vector angle,scale=vct(1,1,1),temp
Dim As ulong fcolour(1 To 10)
Dim As plane side(1 To 6)
Dim As vector face(1 To 4,6)
Dim As Single t,pi=4*Atn(1)
Dim  As vector impulse,impact,closepoint
Dim As long col(1 To 3)
Redim   As Single _dt(0,0) 'register of impact dot impulse
Dim As Single ma,mb,seperation
Redim As _object ball()
Dim As Integer count
Redim As vector ballcol()
dim as single eyepointz=900
#macro start()
#define rr(f,l) (Rnd*(l-f)+f)
For z As Integer=1 To 10:fcolour(z)=Rgb(Rnd*200,Rnd*200,Rnd*200):Next z'floorboards
    e(1) =vct( 1, 1,-1)
    e(2) =vct(-1, 1,-1)
    e(3) =vct(-1, 1, 1)
    e(4) =vct( 1, 1, 1)
    side(1)=Type<plane>(e(1),e(2),e(3))
    
    e(5) =vct( 1,-1, 1)
    e(6) =vct(-1,-1, 1)
    e(7) =vct(-1,-1,-1) 
    e(8) =vct( 1,-1,-1)
    side(2)=Type<plane>(e(5),e(6),e(7))
    
    e(9) =vct( 1, 1, 1)
    e(10)=vct(-1, 1, 1)
    e(11)=vct(-1,-1, 1) 
    e(12)=vct( 1,-1, 1) 
    side(3)=Type<plane>(e(9),e(10),e(11))
    
    e(13)=vct( 1,-1,-1)
    e(14)=vct(-1,-1,-1)
    e(15)=vct(-1, 1,-1)  
    e(16)=vct( 1, 1,-1)  
    side(4)=Type<plane>(e(13),e(14),e(15))
    
    e(17)=vct(-1, 1, 1)  
    e(18)=vct(-1, 1,-1)   
    e(19)=vct(-1,-1,-1) 
    e(20)=vct(-1,-1, 1)   
    side(5)=Type<plane>(e(17),e(18),e(19))
    
    e(21)=vct( 1, 1,-1)  
    e(22)=vct( 1, 1, 1)   
    e(23)=vct( 1,-1, 1)   
    e(24)=vct( 1,-1,-1)   
    side(6)=Type<plane>(e(21),e(22),e(23))
   
    blow(e(),xres/4)            'magnify
    translate(e(),vct(xres/2,yres/2,0)) 'centralize
    side(1)=Type<plane>(e(1),e(2),e(3))
    side(2)=Type<plane>(e(5),e(6),e(7))
    side(3)=Type<plane>(e(9),e(10),e(11))
    side(4)=Type<plane>(e(13),e(14),e(15))
    side(5)=Type<plane>(e(17),e(18),e(19))
    side(6)=Type<plane>(e(21),e(22),e(23))

    For x As Integer=.3*xres To .7*xres Step 1.3*xres/10
        For y As Integer=.3*yres To .7*yres Step 1.3*yres/10
            For z As Integer=1 To Ubound(side)'-1
                If Abs(planedistance(side(z),vct(x,y,z*20)))<30 Then   Goto skip
            Next z
            count=count+1
            Redim Preserve ball(count)
            ball(count).position=vct(x,y,0)
            ball(count).radius=25
            ball(count).mass=4.18*ball(count).radius^3 
            ball(count).velocity=vct(rr(-1,1),rr(-1,1),rr(-1,-5))
            ball(count).velocity=4*normalize((ball(count).velocity))
            if count=15 then exit for,for
            skip:
        Next y
    Next x
    Redim _dt(1 To count,1 To count)
    Redim ballcol(count)
    For z As Integer=1 To Ubound(ballcol)
        ballcol(z)=vct(Rnd*200,Rnd*155,Rnd*255)
    Next z
    #endmacro
    
    #macro rotatebox()
    For a As Integer=1 To Ubound(e)
        temp=rotate3d(pivot,e(a),angle,scale)
        ve(a)=apply_perspective(temp,vct(xres/2,yres/2,eyepointz))
    Next a
    #endmacro
    
    #macro setfaces()
    Scope
        Dim As Integer s,c
        Do
            c=c+1
            For n As Integer=1 To 4: face(n,c)=ve(n+s):Next n
                s=s+4
            Loop Until c=6
        End Scope
        #endmacro
        
        #macro drawfaces()
        Scope
            Dim As ulong col
            For a As Integer=1 To Ubound(face,2)
                Select Case As Const a
                Case 2:col=Rgb(200,240,255)'2
                Case 3:col=Rgb(50,50,100)
                Case 5,6:col=Rgb(100,100,150)
                End Select
                if a<>4 then drawpolygon(face(),a,col,"fill")
            Next a
            
            Dim As vector back,front 
            Dim As vector pts(1 To 2)
            Dim As Integer count
            back=face(2,1)-face(1,1)
            front=face(3,1)-face(4,1)
            drawpolygon(face(),1,Rgb(100,100,150))
            For a As Single=0 To 1 Step .1
                count=count+1
                pts(1)=face(1,1)+a*back
                pts(2)=face(4,1)+a*front
                Line(pts(1).x,pts(1).y)-(pts(2).x,pts(2).y),Rgb(100,100,150)
                Paint(.5*(pts(2).x+pts(1).x)-25,2+.5*(pts(2).y+pts(1).y)),fcolour(count),Rgb(100,100,150)
            Next a
            drawpolygon(face(),4,Rgb(200,0,0))
        End Scope
        #endmacro
        
        #macro zsort(n) 
        For p1 As Integer = 1 To n - 1
            For p2 As Integer  = p1 + 1 To n          
                If vradius(ball(p1))>vradius(ball(p2)) Then 
               Swap ball(p1),ball(p2):Swap ballcol(p1),ballcol(p2) 
                end if
            Next p2
        Next p1
        #endmacro
        
        #macro check_ball_to_plane_collisions()
        Scope
            Dim As vector temp
            Dim As Single s
            s=.5+(angle.x)/60
            For z As Integer=1 To Ubound(ball)
                For z2 As Integer=1 To Ubound(side)
                    seperation=Abs(planedistance(side(z2),ball(z).position,closepoint))
                    temp=closepoint
                    temp=rotate3d(pivot,temp,angle,scale)
                    temp=apply_perspective(temp,vct(xres/2,yres/2,eyepointz))
                    If z2=1 Then Circle(temp.x,temp.y),vradius(ball(z)),Rgba(0,0,0,50),,,s,f
                    If seperation>ball(z).radius Then _dt(z,z)=0
                    If seperation<=ball(z).radius Then
                        If _dt(z,z)=0 Then
                            impact=-1*ball(z).velocity
                            impulse=normalize(closepoint-ball(z).position)
                            _dt(z,z)=(impact dot impulse)
                            ball(z).velocity=ball(z).velocity +2*_dt(z,z)*impulse 
                        End If
                    End If
                Next z2
            Next z
        End Scope
        #endmacro
        #macro check_ball_to_ball_collisions()
        For x As Integer=1 To Ubound(ball)-1
            For y As Integer=x+1 To Ubound(ball)
                seperation=length((ball(x).position-ball(y).position))
                If seperation>(ball(x).radius+ball(y).radius) Then _dt(x,y)=0
                If seperation<=ball(x).radius+ball(y).radius Then
                    If _dt(x,y)=0 Then
                        impulse=normalize((ball(x).position-ball(y).position))
                        impact=ball(x).velocity-ball(y).velocity
                        _dt(x,y)=(impact dot impulse)
                        ma=ball(x).mass:mb=ball(y).mass
                        ball(x).velocity=ball(x).velocity-_dt(x,y)*((2*mb/(ma+mb)))*impulse
                        ball(y).velocity=ball(y).velocity+_dt(x,y)*((2*ma/(mb+ma)))*impulse
                    End If
                End If
            Next y
        Next x
        #endmacro
        
        #macro drawballs()
        Scope
            Dim As vector temp
            For z As Integer=1 To Ubound(ball)
                col(1)=ballcol(z).x:col(2)=ballcol(z).y:col(3)=ballcol(z).z
                ball(z).position=ball(z).position+ball(z).velocity
                temp=rotate3d(pivot,ball(z).position,angle,scale)
                temp=apply_perspective(temp,vct(xres/2,yres/2,eyepointz))
                paintball(temp.x,temp.y,vradius(ball(z)),col(),0,-.5)
            Next z
            
        End Scope
        #endmacro
        
        start()
        dim as long fps
        Do
            t=t+.25:If t>=360 Then t=0
            angle.z=5*sin(2*t*pi/180)'roll
            angle.x=10*sin(3*t*pi/180)'yaw
            angle.y=12*sin(2*t*pi/180)'screw
            
            rotatebox()
            setfaces() 
            Screenlock
            Cls
            draw string(5,5), "Framerate " &fps
            drawfaces()
            check_ball_to_ball_collisions()
            check_ball_to_plane_collisions()
            zsort(Ubound(ball)) 
            drawballs()
            Screenunlock
            Sleep regulate(30,fps),1
        Loop Until Inkey=Chr(27)
        
        Sleep
        
          
leopardpm
Posts: 1795
Joined: Feb 28, 2009 20:58

Re: Game NPC AI ideas

Post by leopardpm »

@dodicat
You are an ANIMAL!

please tell me you already had that code basically done and, at most, you made some changes to post it, right? right???!!!! You didn't just whip that out of the ether in your brain in 5 mins... right?

obviously, I am thinking 2D, like pong, with 4 walls enclosing the ball....

smartass!

PS: changing the regulate to 100fps, my system can manage between 73 -89 fps
leopardpm
Posts: 1795
Joined: Feb 28, 2009 20:58

Re: Game NPC AI ideas

Post by leopardpm »

Tourist Trap wrote:
leopardpm wrote: In any case, that is not what anyone reading this thread is really interested about: they want to know about game agents behaving in a more human-like manner.
... from my experience, the human touch of a not-human-player did never come from its real or supposed intelligence, but rather of its well imitating of human mood.
Such a mood could be agressivity, patience, an erratic mood, or a quiet attitude. For a bot, not being absolutly predictible is better.

In few words, if we talk about games here, the bot will look more human to my eyes if he seems to behave according to some emotional state close to something real. Being really intelligent and therefore being almost unchallengeable, this won't be very funny I think.
Was surfing around and came across this VERY interesting and indepth (out of my depth right now...) paper. Thought you might be interested.

I skimmed through, and I think it provides some very good insights that I will incorporate down the road... I have always veered away from trying to figure out how to realistically model emotional behaviors for NPCs, but I think it could add alot to gameplay as long as it wasn't too expensive.

Link to paper:
https://perso.limsi.fr/sabouret/ps/TCIAIG.pdf

and also this:
https://pdfs.semanticscholar.org/3c68/7 ... 9adb28.pdf

and...
https://www.aaai.org/ocs/index.php/AIID ... 1530/11371
Tourist Trap
Posts: 2958
Joined: Jun 02, 2015 16:24

Re: Game NPC AI ideas

Post by Tourist Trap »

leopardpm wrote:. Thought you might be interested.

I skimmed through, and I think it provides some very good insights that I will incorporate down the road... I have always veered away from trying to figure out how to realistically model emotional behaviors for NPCs, but I think it could add alot to gameplay as long as it wasn't too expensive.

Link to paper:
https://perso.limsi.fr/sabouret/ps/TCIAIG.pdf

and also this:
https://pdfs.semanticscholar.org/3c68/7 ... 9adb28.pdf

and...
https://www.aaai.org/ocs/index.php/AIID ... 1530/11371
Yes I'm interested, thanks a lot. The pdf at semantic scholars doesn't download but it's quite involved stuff I guess.
I wouldn't worry too much about Npc's AI anyway. Not before some advanced stage of the design where you can test the game enough. Why I tell you that is I read the interview of the creator of Paradroid. I lost the link unfortunately, probably in a c64 game website.... What I understood from what he said if I'm not too wrong, is that the appearance of a clever behaviour of the robots in the game was unexpected and spawned alone from the complexity. C64 was a very tiny machine. I find it believable that no AI was especially researched at those times, but it came for free from the overall game behaviour and even bugs maybe :)
What I mean is that I would code everything then test it before I go with the AI. However if you are at this stage then of course you can't postpone anymore.
leopardpm
Posts: 1795
Joined: Feb 28, 2009 20:58

Re: Game NPC AI ideas

Post by leopardpm »

I wouldn't worry too much about Npc's AI anyway.
...but, it is exactly the NPC AI that is at the foundation of my 'theory': That a world filled with complex, unique, and individual AI with the ability to interact between themselves and with the environment would create 'content' (in a variety of different ways) for the player to enjoy WITHOUT much additional involvement of the game designers. EverQuest Next had a VERY reduced version of this vision and it seemed like there was plenty of support from their prospective player base (online forums, etc).
What I understood from what he said if I'm not too wrong, is that the appearance of a clever behaviour of the robots in the game was unexpected and spawned alone from the complexity. C64 was a very tiny machine. I find it believable that no AI was especially researched at those times, but it came for free from the overall game behaviour and even bugs maybe :)
yes, i agree. The problem is that the purpose of the AI in what I am proposing is different than in normal games. It is not the actual AI which will give the players the challenge directly (like how games are currently making better and much more involved Combat AI), but instead, it is from how the complexity allows entirely different gameplay to emerge.

For instance: My focus on GOAP and on Agents carrying out atomistic actions is NOT so that players can come across Farmer John and say "Wow! Look at that, he was plowing his field, then his plow broke and he went and chopped some wood, took it to his carpentry shack and made a new handle then repaired his plow! - That might be interesting to see ONCE, but it is basically just background dressing which could easily be done with pure scripting mostly. What I am getting at is when Farmer John breaks his plow and needs either a new handle, he might do it himself, or, possibly purchase on 'on the market' from other AI's OR from players. This economic bond will give automatic rise to the following things: the prices of things in the world will reflect actual supply/demand which means that changes to the situation will change behaviors: a forest fire will reduce the ability to gather wood locally, rising the price of wood in a particular area, which might induce a merchant from another town to load up a wagon of wood and cart it into the area.... his new trade route might then induce a band of Orcs to start ambushing that trade route. this is automatic 'new' content for players to interact with, as merchants, as bandits, as bodyguards, as adventurers... and even as wood choppers!

This type of depth in NPC behavior will not 'come for free' - and it may very well be way too expensive, or not even possible, which is why I am trying to create a smaller-scale test simulation..... but I still need to focus on the AI mechanics...
Tourist Trap
Posts: 2958
Joined: Jun 02, 2015 16:24

Re: Game NPC AI ideas

Post by Tourist Trap »

leopardpm wrote:
I read carefully what you wrote above, and it's making it clearer I find. I think humbly that what you are looking for is not in the AI category of the computers games. It reminds me of what some Japanese did with robots that were able to learn a language of their own from scratch. They just put a bunch of the robots in a box and after a while of interacting each other and with the environment to find energy and stuff like that - they basically needed, they were able to communicate in their own way.
The topic maybe is of the kind of Chomsky's generative grammar and this kind of stuff.
I can be wrong again, but this is the only general purpose AI that I know. The computers AI are all tasks oriented (pathfinding etc...). The grammarian AI, when taken with the angle of language discovery is far more general.
Now that I say this, I know too less in this domain. My best guess is that among the many patterns we find in agent programming, there is probably things like that. Those domains are truly hard to dig out, due to the technical symbols cluttering the papers.
I hope I'm not telling too much fool things :D
leopardpm
Posts: 1795
Joined: Feb 28, 2009 20:58

Re: Game NPC AI ideas

Post by leopardpm »

Tourist Trap wrote:
leopardpm wrote:
I read carefully what you wrote above, and it's making it clearer I find.
it is my fault for not being able to communicate clearly the concept I am thinking of.... not your fault.
I think humbly that what you are looking for is not in the AI category of the computers games.
it is not in the category of what the AI of current computer games do.... but it is in the AI category. I would call it possibly "Interactive Economic AI'.
It reminds me of what some Japanese did with robots that were able to learn a language of their own from scratch. They just put a bunch of the robots in a box and after a while of interacting each other and with the environment to find energy and stuff like that - they basically needed, they were able to communicate in their own way.
yes, I also read about that... but that is totally different from what I propose. My AI is actually 'simple' in that it is deterministic... where it is complex is in its ability to interact. It won't create its own language or anything strange like that because it is not specifically a 'learning' AI.
The computers AI are all tasks oriented (pathfinding etc...).
yup.... and with GOAP, the paths can be through a graph of possible Actions, which creates dynamic scripts. But currently, the AI in games is limited by how the Agent can interact with players...mostly combat now. I propose to include OTHER methods of interaction, namely economic (ie: being able to Trade, to express their 'demand' on the market, etc)
I hope I'm not telling too much fool things :D
I don't exactly understand your sentence here, but, you are no fool!
Tourist Trap
Posts: 2958
Joined: Jun 02, 2015 16:24

Re: Game NPC AI ideas

Post by Tourist Trap »

leopardpm wrote:
Tourist Trap wrote:
leopardpm wrote:
I read carefully what you wrote above, and it's making it clearer I find.
it is my fault for not being able to communicate clearly the concept I am thinking of.... not your fault.
Ahah, thanks then. But as a non English-tongued person I probably miss a lot of points that you explained quite well in the first place.

Anyway, what you added right now is a confirmation to my eyes that you will have to struggle with communication and in general something like a performative language. For instance, I stay in the domain of the communication, you have:

Code: Select all

send request at (address)
in return handshake
ask for a xml document 
see if there is an item section of interest in the code
if yes send bitcoins to download the item, it is moved accordingly in the general database
or the same thing in reverse order
Now of course, I miss some time to simulate this, but it looks like economy with trade implemented. My point here is to show that it already exists as language (xml) and protocol (handshaking...). The prices of course are left to the agents (by price I mean what you need to pay to get the item downloaded).

Ok, I made a first jet here below. I will add agent with schematics when I find time. For now only the world spawns. It's flat , as we know :)

Code: Select all

 'economicus agent proof of concept in freebasic

#include "fbgfx.bi"

type GENERALAGENT extends OBJECT
    as string               _typeName
    as any ptr              _subornedAgentArrayOfPtr(any)
    as string               _subornedAgentArrayOfTypename(any)
end type

type MONNEY extends GENERALAGENT
    as integer              _value
end type

type SCHEMATICS extends GENERALAGENT
    as any ptr              _usageConventionArray(any)
    as string               _usageConventionTypeName(any)
    as string               _document(any)
end type

type PHYSICALPOSITION
    as integer              _x
    as integer              _y
end type

type PHYSICALSCORE
    as string               _typeName
    as integer              _value
end type

type PHYSICALLIFESCORE
    as PHYSICALSCORE ptr    _scoringPtrArray(any)
    as string               _scoringTypenameArray(any)
end type

type PHYSICALGEOMETRYSCHEMATICS
    as sub(as any ptr)                              _draw
    as function(as any ptr) as boolean              _testcollision
end type

type PHYSICS extends GENERALAGENT
    as PHYSICALPOSITION             _position
    as PHYSICALLIFESCORE            _lifescore
    as PHYSICALGEOMETRYSCHEMATICS   _geometry    
end type

type MOB extends PHYSICS
    as GENERALAGENT             _rootedSelf
    as SCHEMATICS               _rootedSchematics
end type

type WORLD extends MOB
    as MOB ptr                  _everyMobOfTheWorldArrayOfPtr(any)
    declare constructor()
    declare sub AddAgentReference(as MOB ptr)
    declare sub KillAgentReference(as MOB ptr)
    declare static sub DrawWorld(as any ptr)
    declare static function TestWorldForCollision(as any ptr) as boolean
end type
constructor WORLD()
    dim as integer  dskW, dskH
    screencontrol   fb. GET_DESKTOP_SIZE , dskW, dskH
    screenRes .7*dskW, .6*dskH, 32, 2, , 0
    '
    'GENERALAGENT
        THIS._typeName      = "world"
    'PHYSICS
        THIS._position      = type<PHYSICALPOSITION>(0,0)
        THIS._lifescore     = PHYSICALLIFESCORE()
        'assign geometry callbacks
        THIS._geometry      = type<PHYSICALGEOMETRYSCHEMATICS>(@WORLD.DrawWorld,@WORLD.TestWorldForCollision)
    'MOB
end constructor
sub WORLD.AddAgentReference(MobPtr as MOB ptr)
    if MobPtr=0 then exit sub
    '
    dim as boolean mobFound => FALSE
    for index as integer = lBound(THIS._everyMobOfTheWorldArrayOfPtr) to ubound(THIS._everyMobOfTheWorldArrayOfPtr)
        if THIS._everyMobOfTheWorldArrayOfPtr(index)=MobPtr then
            mobFound = TRUE
            exit sub
        end if
    next index
    '
    redim preserve THIS._everyMobOfTheWorldArrayOfPtr(ubound(THIS._everyMobOfTheWorldArrayOfPtr) + 1)
    THIS._everyMobOfTheWorldArrayOfPtr(ubound(THIS._everyMobOfTheWorldArrayOfPtr)) = MobPtr
    '
    'update the suborned GENERALAGENT - 
    'the suborned AGENTS of the world are all the rooted selves of the mobs around
    'their agent typname is the mob's agent rootedself typename
    redim THIS._subornedAgentArrayOfPtr(lBound(THIS._everyMobOfTheWorldArrayOfPtr) to ubound(THIS._everyMobOfTheWorldArrayOfPtr))
    redim THIS._subornedAgentArrayOfTypename(lBound(THIS._everyMobOfTheWorldArrayOfPtr) to ubound(THIS._everyMobOfTheWorldArrayOfPtr))
    for index as integer = lBound(THIS._everyMobOfTheWorldArrayOfPtr) to ubound(THIS._everyMobOfTheWorldArrayOfPtr)
        THIS._subornedAgentArrayOfPtr(index) = @(THIS._everyMobOfTheWorldArrayOfPtr(index)->_rootedSelf)
        THIS._subornedAgentArrayOfTypename(index) = THIS._everyMobOfTheWorldArrayOfPtr(index)->_rootedSelf._typeName
    next index
end sub
sub WORLD.KillAgentReference(MobPtr as MOB ptr)
    dim as boolean mobFound     => FALSE
    dim as integer searchindex  => any
    for searchindex = lBound(THIS._everyMobOfTheWorldArrayOfPtr) to ubound(THIS._everyMobOfTheWorldArrayOfPtr)
        if THIS._everyMobOfTheWorldArrayOfPtr(searchindex)=MobPtr then
            mobFound = TRUE
            THIS._lifescore._scoringPtrArray(0)->_value -= MobPtr->_lifescore._scoringPtrArray(0)->_value
            exit for
        end if
    next searchindex
    if not mobFound then exit sub
    '
    for moveindex as integer = searchindex to ubound(THIS._everyMobOfTheWorldArrayOfPtr) - 1
        THIS._everyMobOfTheWorldArrayOfPtr(moveindex) = THIS._everyMobOfTheWorldArrayOfPtr(moveindex + 1)
    next moveindex
    redim preserve THIS._everyMobOfTheWorldArrayOfPtr(ubound(THIS._everyMobOfTheWorldArrayOfPtr) - 1)
    'update the suborned GENERALAGENT - 
    'the suborned AGENTS of the world are all the rooted selves of the mobs around
    'their agent typname is the mob's agent rootedself typename
    redim THIS._subornedAgentArrayOfPtr(lBound(THIS._everyMobOfTheWorldArrayOfPtr) to ubound(THIS._everyMobOfTheWorldArrayOfPtr))
    redim THIS._subornedAgentArrayOfTypename(lBound(THIS._everyMobOfTheWorldArrayOfPtr) to ubound(THIS._everyMobOfTheWorldArrayOfPtr))
    for index as integer = lBound(THIS._everyMobOfTheWorldArrayOfPtr) to ubound(THIS._everyMobOfTheWorldArrayOfPtr)
        THIS._subornedAgentArrayOfPtr(index) = @(THIS._everyMobOfTheWorldArrayOfPtr(index)->_rootedSelf)
        THIS._subornedAgentArrayOfTypename(index) = THIS._everyMobOfTheWorldArrayOfPtr(index)->_rootedSelf._typeName
    next index
end sub
sub WORLD.DrawWorld(THISptr as any ptr)
    dim as integer scrW, scrH
    screenInfo scrW, scrH
    locate 2, 1 : ? "   this is the world"
    line (20, 20)-(scrW - 20, scrH - 20), rgb(255,0,0), b
    '
    'draw every mobs
    dim as WORLD thisWorld => *cast(WORLD ptr, THISptr)
    for index as integer = lBound(thisWorld._everyMobOfTheWorldArrayOfPtr) to ubound(thisWorld._everyMobOfTheWorldArrayOfPtr)
        if thisWorld._everyMobOfTheWorldArrayOfPtr(index)<>0 then
            thisWorld._everyMobOfTheWorldArrayOfPtr(index)->_geometry._draw(@thisWorld._everyMobOfTheWorldArrayOfPtr(index))
        end if
    next index
end sub
function WORLD.TestWorldForCollision(THISptr as any ptr) as boolean
    return FALSE
end function


'
dim as WORLD    theworld
do
    theworld._geometry._draw(@theworld)
    '
    sleep 15
loop until inkey()=chr(27)

'(eof)
Edit,
I'm adding a few word of explanation. I don't try to set sensors or emotions. I just set physical world laws and life scoring in one hand, and schematics in the other hand. Schematics adds something in the fact that they serve to communicate between agents that can access and also parse the schematics of someone. If you find a car you can get it by killing the owner, but if you still don't get the schematics you may well not drive very far.
I don't want to be too long with a so tiny draft, but at least this will let you know where we differ in our approach to get towards a more automotive world of agents. They don't need only to do things physically constrained, but also do things in a more elaborated plane of schematics, that defines everything else but mere physics.
Of course I can still be wrong, but for this second part, besides the physical world, this is a question of communication devices first. Even if the ability to decrypt schematics may be treated as a kind of shortest path finding problem as usual.
Post Reply