If you need help with NPC or game AI ask me here

Game development specific discussions.
Post Reply
TESLACOIL
Posts: 1769
Joined: Jun 20, 2010 16:04
Location: UK
Contact:

If you need help with NPC or game AI ask me here

Post by TESLACOIL »

If you need help with NPC or game AI ask me here

I cant help you out with specific coding issues But i can tell you why,how & what to code for

I just need to know

A what you want your AI to be capable of

&

B what information it has access too


pathfinding is trivial

amassing arms or armies in a complex world and hunting you down like a dog is my specialty
leopardpm
Posts: 1795
Joined: Feb 28, 2009 20:58

Post by leopardpm »

Hi!
I have been researching AI for the past year and have started doing some FSM based AI. I haven't yet grasped the 'genetic learning' AI and/or neural net approaches as they seem very involved. There is a game I came across called Dwarf Fortress which has alot of interesting features and some good variations of AI (the dwarves have personalities, and a hierarchy of needs and react to situations accordingly, plus some randomness thrown in like they can 'go crazy' and other things) but the game's interface and graphics are horrible and all but make it impossible to learn and play for most folks.
Well, this game got me thinking about MMO's and the NPC's within and how interesting it would be to have NPC's that have a much more involved AI and not only react to situations, but kind of 'live' in their environment kind of like a SIM game on steriods. For instance, an NPC farmer would get up in the morning, eat, do some household chores, then go work his fields all day, stopping by the pub on his way home, and, at night, sit in his chair and read (or knit, whittle, paint, etc whatever his 'hobby' was), then go to bed. This much is pretty straightforward AI, BUT to make him actually 'live' he would need to: go to the grocery store when running low on food, buy/make farming implements as he needed, build his cottage, or improve his existing one, etc, etc.

So, my desire is to program an AI which lives, interacts, and even changes his environment (game world). The best way I can currently see to do this simply is by having a Hierarchy of Needs (maslov) and extensive FSM routines which are triggered by various inputs from his 'personality', his current status in the Hierachy of Needs, and his environment. The AI would be generic in that there would not be different AI's for different 'types' of NPC's: woodcutters, farmers, hunters, shoemakers, etc... but rather one AI routine which would produce such 'types' based on the Agent's personality and the local environment. I realize this is all but an impossible goal, but my idea to to work in a sandbox world and continually add FSM routines and see how they affect his actions. It has been great fun so far.... BUT...

Do you have any advice on other ways to implement what I am trying to accomplish? One of the obstacles that I am having trouble incorporating is social interaction/trade and economics. For instance, if this Agent decided it was time to get a better house, he would have to weigh the cost of building it himself vs possibly renting or buying one on the market. This goes back down through many levels, ie: building it himself would require him to have a saw (which he might not own) and he would have to make the same calculation (make it or buy it) on that tool and every other tool required in the process. One method I have been mulling around with is to price everything in estimated 'time units', for instance to make an axe might take him 1/2 hr to chop a branch, 2 hrs to mine the ore and process it, and 1 hr to forge/smelt and build the final axe.... giving the decision to make an axe a 'cost' of 3.5 hrs. Now to compare that to the possibility of 'buying' the axe, he would have to figure out his current income per hour and divide the market price for an axe to get work hours needed to purchase it, then he could choose the 'easiest' way.

My problem here is how to have a group of agents interact through trade and come up with a relatively stable market economy which would reflect supply and demand, and all the effects of various personalities of agents within the market. I am having trouble arriving at agent driven 'prices' is I guess my problem here.

Sorry, a bit overly ambitious, I know. But perhaps in your knowledge of AI, you might see how some other types of AI would be much better suited in my attempts to achieve my goals here. My ideal (an impossibility perhaps) is to have a virtual world, drop a few of these AI agents into it, and see them 'evolve' - first searching out food sources, then building basic structures (tents, etc) then advancing depending on their own personalities and desires, and modified by the environmental situation (ie: if no forests are around, then no agent in the area is going to become a 'woodcutter', no matter how much they might 'like' the job.

well, anyways, what are your thoughts?
agamemnus
Posts: 1842
Joined: Jun 02, 2005 4:48

Post by agamemnus »

Ok, very interesting work leopardpm.

The major problem with AI is that you always have to frame things to artificially limit choices to a computationally and programatically feasible amount.

I'd like to point out two things, here.

Firstly, one thing you can do that makes a farmer a "farmer" and a woodcutter a "woodcutter" is to give them various advantages.. a farmer might be able to get a better yield from his crops (because he "knows" more) and a woodcutter could cut wood faster. (because he can find the best trees to cut, faster)

-----------------------------------------------------------

That brings me to my second point:

The decision to be a farmer or a woodcutter, or to go to the market versus making your own wood, is programatically difficult, and computationally expensive, and thus requires a lot of decision-making streamlining to make it work.

One way you can approach this is to create certain points in a farmer or woodcutter's life (say, every 1000 ticks) where they calculate whether they should continue being a farmer or change their profession. That reduces the computational requirements and is more realistic (because, people don't make these decisions every tick in the real world).

The same could be said for an agent deciding to buy an axe. In the real world, he will not calculate the cost every time his axe breaks (and don't forget, he also needs to find the market price of the ore and wood, etcetc, not just find the market price of the axe itself.)

-----------------------------------------------------------

One thing you could simplify is to assume that each agent automatically knows the market price of something even if it is far away, but you could also add a cost for the agent to go to the market and back to make the decision more realistic.

There's also the problem of the agent not getting something when he finally arrives at the market. There are various solutions to that problem too-- maybe you make the market item appear right away, instead of making the agent go to the market. You can also make the agent wait for the item to appear in the market a set amount of ticks.)

To model the price of something on the market again depends a lot on your world rules and constraints. In the real world, the woodcutter would balance the price of the axe versus the cost of making it himself based on the price he would get on the market of wood that he would have cut in the period of time it takes him to make the axe.

It's the same idea for selling something, just in reverse. Suppose the axe maker needs food. How much money would the axe maker get for making an axe (in terms of food) versus making it himself?

You'd also need some initial stock or prices, or maybe even an agent who just has some facility in trading. Perhaps it might be easier to model a barter economy first, and then when you have that down try to model a gold-based or fiat-based economy.
leopardpm
Posts: 1795
Joined: Feb 28, 2009 20:58

Post by leopardpm »

Very Good! I see that you have some economics background as well!

OK, your first point: an agent who is better at woodcutting would tend to gravitate towards that 'job' versus others because of his competitive advantage... or, better stated, because in his opportunity cost comparison he is more efficient at such a task. Instead of giving out random 'talents' for the agents, I would rather let the talents/skills 'build' from experience. For instance, given 10 agents, each starts out and builds a list of 'goals' based on the environment as they see it, their personality (I like growing things, I like wood, I like fish, etc), and their current HON (Hierarchy of Needs) as in: I have no shelter so I need one, BUT I have no food stored and that is more important so get food first (prioritize). So each determines which methods of food generation (berry picking, fishing, farming, hunting, etc) is most advantageous to them (closer to a fishing lake than to any berry bushes, etc). So, the agent who chooses fishing will gain Fishing skill which in turn makes them 'slightly' more efficient doing that particular task. This is where the market comes into play to help spread out the specializations: if everyone is fishing then the price of fish will drop so much that other food gathering methods become attractive enough to 'change professions'. Eventually I figure there will be some sort of rough equilibrium where most agents are kind of set in their ways unless a shock to the system occurs (all the trees are cut down, the ore runs out, no more fish in the lake, etc) at which point the group/economy will rearrange until a new equilibrium is reached which takes into account the changed environment.

#2 - I totally agree that these agents would not/could not re-evaluate their entire life each cycle - a horrendous overhead! I was thinking much as you that either a pre-set time period (1000 ticks) or just a simple random chance which might be checked only when certain conditions are met (when something 'happens' like a farmers tool breaks, or the fisherman's pole is lost, or something)... but this part doesn't need to be so involved or complicated, so the simpler the better.

#3 - as far as incorporating distance into the opportunity cost equation is spot on to the way I have been thinking, but you came up with it immediately whereas I have been mentally wrestling with these things for months (and enjoying every bit of time lost to my contemplations!).

#4 - it is exactly in modeling a barter economy that I run into problems. I understand that I can come up with algo's which figure out mins and maxs (like the minimum price an agent might sell an axe for, or the maximum another agent might purchase an axe for), but these seems very calculationally intensive, and, even more important, determining a 'market' price involves a way to incorporate ALL the agents (in an area) mins and maxes) as a way of evaluation 'total potential demand' and 'total potential supply'.... but this has me currently overwhelmed! I love economics and especially micro-econ, but modeling an AI agent to behave anything like a semi-rational economic actor is insanely hard! But I love the challenge!

So, in your estimation, do you think that having a personality filtered through a Hierarchy of Needs, to create a goal table, which is acted on by an insanely large number of FSM's which can be recursively called (via a stack), will get me anywhere close to satisfactory outcomes? Or will I end up generating lines of code for 2 years that end up with a $%#@ agent that sits there, does nothing, and contemplates the meaning of life for eternity?

thanks again for your response!
M
leopardpm
Posts: 1795
Joined: Feb 28, 2009 20:58

Post by leopardpm »

Things really get complicated/confusing when transcending from a single agent to multiple agents.... with a single agent, it is relatively easy to determine their goals and how to achieve them... but adding even 1 additional agent makes my eyes glaze over as there are so many interrelations between them. For instance, I understand comparative advantage calculations where agent A is good at woodcutting(8) and berry picking(5) and fishing(3), and agent B is good at berry picking (4) and woodcutting (5) and determining that the most efficient division of labor is to have Agent A do woodcutting and Agent B do berry picking which produces the most amount of goods during a given amount of time/effort. BUT Agent B only knows HIS talents and an AI routine that does not somehow take into account external Agents would naturally pick woodcutting for both Agents! How do I overcome such problems?

My thought right now is just to keep working and expanding on getting the single agent acting relatively 'human' and once that AI is somewhat sophisticated (He tries to continually improve his 'life', ie: better shelter, more efficient resource gathering (making a cart to haul loads of wood back to camp instead of many trips carrying small bundles!), and 'enjoyment' of leisure time, etc) then introduce a second agent and, by watching them - trial and error method, start adding inter-related algo's as I can best decipher to achieve the desired results.... I really have no other idea as to how to tackle the problem.
leopardpm
Posts: 1795
Joined: Feb 28, 2009 20:58

Post by leopardpm »

ok, here I go again... hope this is at least interesting reading for anyone...

Obviously, it would be ideal to have things 'spring up' natural, for instance a town, or a marketplace. I could 'tend' things towards such results by incorporating advantages to building a shelter nearer to other shelters for instance, modified by perhaps some sort of 'social' personality trait where a 'hermit' might NOT be inclined to build close, whereas a social agent would. Then, a market could be caused to 'spring up' by incorporating distance into the cost calculations then weighting the desire to trade with nearness to one's stockpiles/house/storage/etc and a 'trade map' which would perhaps keep track of the locations of all previous trades and so weights any other trades towards the most frequented locations. So, agents would tend to group up in clusters (towns) then most trade would start occurring somewhere in that town which would be the de facto 'marketplace' and then. In turn, this marketplace would be the point used for distance calculations which try to determine relative costs (should I make an axe from resources I have with me, or, walk to the marketplace and pay the current market price?).

ALSO, how to determine 'demand' for a good which has yet to be created? For instance, a carpenter might gain enough skill to produce a hand cart, but how would I determine the demand for hand carts before any trades were executed? I guess I could use sort sort of default formula like "beginning price of any item starts out at 2 times its time value" and have a way for the agent to reduce the price until it sells. Once that first selling point is determined, another Cart could be made and see how quickly it sells for the same price and now you have data on time and price which can be used to determine if the price needs to be further reduced (time to sell being used as an ad hoc way to determine relative demand) until such time that enough of the item is supplied to meet demand for maximum 'profit'..... this stuff is just crazy.
leopardpm
Posts: 1795
Joined: Feb 28, 2009 20:58

Post by leopardpm »

My fear is that every single usable object and every single possibility of different combinations for use would have to be pre-determined before an agent could calculate. Again, with the hand cart example: There is no way to have a woodcutter evaluate using a handcart unless that 'recipe' (ie: Recipe #1: chop wood until have full load(backpack) then walk X distance to stockpile, vs, Recipe #2: chop wood until have full load(cart) then drag cart to stockpile) was already pre-thoughtout by the programmer and coded. Given the possibility of perhaps multiple ways of accomplishing same task (plowing a field by hand (no tool), plowing it with a Hoe, or plowing it with a ox drawn plow, etc) this makes it virtually impossible to code all variations in any sort of reasonable time (say, within my lifetime?!) though I don't think that memory requirements would necessarily start to be a problem - even 1 mb can hold ALOT of FSM code!

I guess some sort of intelligence built into the items themselves could help to automate the process: the definition of an 'axe' would include all its possible uses (Use for Tree Chopping - chop a tree with rate of chopping variable, Use for Battle - do battle damage with associated variables, etc) and for a cart (Use for Transport - carry an amount(20) of goods at speed X) and a backpack (Use for transport - carry amount(2) of goods at walking speed) and then a routine which parses a goal:

Build House(Goal):
--- Resources needed at location
- Need 10 wood logs
- Need Door
- Need 2 Windows

like this:
10 wood logs: takes X time to chop leaving piles of wood X distance away from desired location. Needs transport to location... so routine would traverse the entire array of objects possible, noting the ones which can 'transport' and comparing the various methods. This would save the programming time of individually coding every possibility, BUT, it greatly increases the memory requirements of the world Objects.... craziness.

The more I think about this, the more I think my best bet is to vastly pull back on possibilities and keep things oh-so-simple (maybe only 1 method of accomplishing any particular goal like gathering food). Else I will never get any kind of code completed... don't try and eat the apple all at once, take small bites at a time.
j_milton
Posts: 458
Joined: Feb 11, 2010 17:35

Post by j_milton »

I sort of like the idea of figuring out what the problem to be solved is before getting too deep into how to solve it ;-)

By this I mean what is the purpose of the program? Entertainment (like watching fish in an aquarium), testing of some economics hypothesis? etc.

Then some thought to interface: Does the person running the program provide any inputs to it, or do they just sit back and watch it run?

What,in general terms do you see thew output looking like? Is it a bunch of animated super mario woodcutters bouncing around a forest, or a bar graph describing the peasants to lords ratio of a country over time?
Or will I end up generating lines of code for 2 years that end up with a $%#@ agent that sits there, does nothing, and contemplates the meaning of life for eternity?
Just have them write a book evey 5 years and you can call them tenured professors :->
leopardpm
Posts: 1795
Joined: Feb 28, 2009 20:58

Post by leopardpm »

LOL!

ok, fair enough...

Purpose:
the programming part (a challenge to solve = fun)
the end result being entertainment (fun to play/watch)

Interface:
This depends upon the level and sophistication that the AI can perform. For instance, an RTS game has pretty rudimentary AI (select peon, tell him to chop wood at this location, he continues until dead or you direct him otherwise... same with any military units, with additional options like patrolling, etc) . An RPG game also has pretty rudimentary AI for all NPCs (including the beings to attack).

So, abstracting the AI into levels from rudimentary actions to complicated recursive scripts (chopping wood to trying to survive through making furniture to sell on the market, which might of course involve going out and chopping some wood each morning, etc), and seeing how far up the chain I can get... this will help determine where or how the player interacts with the world.

for instance, the AI of Dwarf Fortress is a bit more sophisticated than an RTS in that the player designates 'jobs' to be done, and the agents(dwarves) figure out what to do, when to do it, they take breaks, eat, sleep, fight off nasties all the way, and go crazy every so often just for spice. You do set up each dwarf as to what their 'job' title is and so you pretty much can control which dwarf does which job, but it is a level removed from an RTS-select-command style.

OK, I can imagine a few pretty nifty uses for the AI depending upon its ability. Imagine an RPG (or an MMORPG) in an ever-changing dynamic world in which various groups/races expand their territory, conquering cities, building new ones, being exterminated, etc... its a world that 'creates' its own story and will have an infinite amount of 'quests' generated by the circumstances and changing environment. Quite a tall order, but, I do see Independent Agent AI as the direction which the game industry must eventually go, be it for MMORPGs, RTS's, RPG, etc.

As far as output... initially my sandbox is basic 2d top-down with lots of screen space dedicated to watching the ongoing changes in variables. Clicking on a particular agent gives you detailed info on what they are trying to currently accomplish and how. This is how I am testing the AI.

I would gather they 'game' would have the player as either some sort of diety which can 'nudge' his agents in certain directions (if the AI was very sophisticated), or being alot more hands on if the agent AI ends up pretty stupid. And, again if the AI was smart enough, have the player act as an agent and attempt to garner NPC agents to 'follow' him as he builds something like reputation, etc. Ultimately, I think having it multiplayer would be most sweet.

BUT, it really depends upon the level of AI sophistication that I can figure out. Everything else is just dreaming.

NOTICE: the AI is really independent of the game... the game could be a 3D game, a 2D game, an RTS, or an RPG.... but the AI engine could be basically the same. I personally think the RTS genre is about finished and the next step is a fusion of RPG with RTS elements at higher 'levels' - for instance your character advances to be town Mayor and now has abilities to issue commands to the citizens and build a militia, attack neighboring towns, repel orcish hordes, go seek out new mining areas, conquer the world.... standard fare.

But, yes, for now animated mario bros chopping wood, fishing, picking berries, farming, using a carpentry shop, building walls, baking bread, etc....
agamemnus
Posts: 1842
Joined: Jun 02, 2005 4:48

Post by agamemnus »

Dude, I do like to talk about these things... however, my head just exploded. :-(
So, in your estimation, do you think that having a personality filtered through a Hierarchy of Needs, to create a goal table, which is acted on by an insanely large number of FSM's which can be recursively called (via a stack), will get me anywhere close to satisfactory outcomes? Or will I end up generating lines of code for 2 years that end up with a $%#@ agent that sits there, does nothing, and contemplates the meaning of life for eternity?
A hierarchy of needs might work very well. It works very well in The Sims.

The more I think about this, the more I think my best bet is to vastly pull back on possibilities and keep things oh-so-simple (maybe only 1 method of accomplishing any particular goal like gathering food). Else I will never get any kind of code completed... don't try and eat the apple all at once, take small bites at a time.
:-)


We should talk. Come on over to #freebasic on the freenode.net IRC network sometime!
leopardpm
Posts: 1795
Joined: Feb 28, 2009 20:58

Post by leopardpm »

its been over 20 years since I have been on an IRC channel, don't even remember or know how to do it! My email is leopardpm@yahoo.com and I guess I could get some sort of chat program if ya wanted to talk more fluidly.

Actually, from what I have read, the Sims also does a 'broadcast' thing where different objects tell the agents what they do - a toaster says "I turn bread into toast", the refrigerator says "I have food", etc. So when an agent decides that it is hungry, it searches nearby objects which have 'food'.... just relaying 2nd hand info from an article I recently read, so I don't really know.

Sorry about the 'head explosion' - I understand there is a distinct difference between 'dreams' and 'possibilities' and can settle for anything in between... someone was just asking about the entire concept which kinda evokes a 'wish list'.

Has anyone played either Dwarf Fortress, or the easier to use but having much less depth, 'Goblin Camp'? These pretty much represent a new genre but are so horribly implemented that I figure there is room for me, hobbyist programmer at large, to contribute to it.
kiyotewolf
Posts: 1009
Joined: Oct 11, 2008 7:42
Location: ABQ, NM
Contact:

Post by kiyotewolf »

@Telsacoil

Dear Telsacoil,

I might've posted a reply on here, that might've sounded a bit harsh, but I did NOT intend it to sound as such.

Please.

I would love to collaborate with you, on KikiAI, in private, and would love to hear about the older flavors of BASIC you know.

Although B2B does not want older flavors of BASIC listed in there, after a certain point, it does not mean that I personally, do not want to hear about your adventures in BASIC from days gone by.

I THRIVE on old BASIC language, and have a DOS laptop, which I'm using as a cute PDA.

~~~

KikiAI is going to feature 3 voices, hers, and two lil kid voices, cause her ultimate goal is a learning tool for my kids & two other godchildren.

If I offended you, I am VERY TRUELY SORRY, and wish to make amends.

I am not pandering or talking down to you, you are very well versed in AI, and I am not.

Please please, accept my wish to be your friend again, and I would LOVE to work with you on AI now, and in the far off future.

~~~

I have an internet surfing project, which would start out compressing 1 minute into 59 seconds, which after much training, could be directly tied into an AI neural net, to aid in teaching a web-enabled AI much quicker, than conventional means.

The future of the internet and AI, is acceleration, aka, time travel.

~~~

If we can teach ourselves to surf the internet at 98.3% higher speeds, we can train ourselves to surf even faster.

If we let an AI watch and follow our patterns, if we surf faster, we can train the AI neural networks faster as well.

~~~

If we train our AI's enough, we can remove the human component, and the remaining empty space, will fill itself in, and create a wholey unique AI, as the computer attempts to recreate what it saw in the learning process.



~Kiyote!

I have so MANY ideas to give you as well as bounce off you.

I am very sorry for sounding like a pompus jerk, I did NOT intend to.

http://www.tgwv.webs.com
TESLACOIL
Posts: 1769
Joined: Jun 20, 2010 16:04
Location: UK
Contact:

sorry ive been away kiyote

Post by TESLACOIL »

sorry ive been away, kiyotewolf , been very busy no time to think


asimovone at yahoo dot com is my email address for all things A.I. & Computery stuff

http://www.youtube.com/user/2TESLACOIL



AIKO
http://www.youtube.com/user/aibot21

Tim Machine gun Tyler , very very good video series on AI
http://www.youtube.com/watch?v=ikg848h1 ... re=related
Last edited by TESLACOIL on Jan 26, 2011 14:19, edited 1 time in total.
Prime Productions
Posts: 147
Joined: May 24, 2009 23:13
Location: Texas, United States, Planet Earth
Contact:

Post by Prime Productions »

Hello there TESLACOIL good to see you again.

Cool ASIMOV YouTube Video. I understand that you are coding it, correct?

Impressive for saying that in real-time.

All the best to you, hope to see you around.

David
Post Reply