Advertisement

AI Advice needed

Started by October 23, 2007 10:24 AM
5 comments, last by conkerjoe 17 years, 1 month ago
iv started work on a A-Life simulator as a learning excersise for AI. iv started to implement a set of rules and based on the value of the rule respond with an action.. for example im hungry now eat. no food so hunt.. hunting produces food once i have food eat it im no longer hungry. but i can see straight away that my AI code is going to get ridiculously out of control with if statements. What i need is guidance on what AI methods to implement for this style of game.. i have started researching Neural networks and fuzzy logic but struggling to interpret the theory into game functionality.
Sounds like what you need are some software patterns to help make your code more manageable, not any academic technology.

Try looking into the State Pattern in particular. Once you implement all the functionality into very small functions (e.g. actions and conditions), it becomes much more manageable.

Join us in Vienna for the nucl.ai Conference 2015, on July 20-22... Don't miss it!

Advertisement
Quote: Original post by conkerjoe
i have started researching Neural networks and fuzzy logic but struggling to interpret the theory into game functionality.

Don't.

Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC
Professional consultant on game AI, mathematical modeling, simulation modeling
Co-founder and 10 year advisor of the GDC AI Summit
Author of the book, Behavioral Mathematics for Game AI
Blogs I write:
IA News - What's happening at IA | IA on AI - AI news and notes | Post-Play'em - Observations on AI of games I play

"Reducing the world to mathematical equations!"

I'd suggest that each cycle you put all the possible actions onto a list together with a priority, and then pick the one with the highest priority to carry out. This lets the logic for each possible action be quire small and self contained.

example.
I'm a bit hungry, so add an eat action with priority 10
I'm pretty thirsty so add a "go to the river" action priority 50
Need to get away from that crocodile, so add "run away" action priority 95

Result, run away from the crocodile.

If you're dying of thirst however, then the priority for getting a drink would be 100, resulting in going down to the river, and taking your chances with the croc.
I think personally I would go with a AI based on individuals having a small about of intelligence. I did a disertation on Ant Colony algorithms once apon a time and that was all based on each individual having a simple set of rules but you put a load of them out and they would find the quickest path towards food.

I like longjohns idea, but to develop it I would say break each individuals behaviour emotions for instance:

Fear
Love
Likes
Hates

also have a set of fitness functions (stuff that gives u an indication of how well the creature is doing) i.e.

Happiness
Health
Hunger

and basically for each class of creature put in a set of rules

I fear crocodile
I like flowers
I hate badgers
etc.

And a set of actions

Eat
Fight
Run
'Snuggle'

And how it affects your fitness function

When im afraid happiness goes down.
When im close to something I like happiness up.

Now here comes hopefully the clever bit

Each time this creature feels an emotion have it do something random from the list of actions. Depending on how this affects the fitness function associate that value to the action and emotion pair i.e.

Fear -> randomly comes up with Fight -> creature fights crocdile -> -20 Health -> -20 to Fear, Fight.
Flower -> randomly comes up with Eat -> creature eats flower -> + 5 to Hunger -> +5 to Like, Eat

Now all you have to do is instead of that being completely random you weight the choice based on what happened last, so:

Fear -> randomly picks but less likely to Fight -> picks run -> + 5 happiness -> +5 to Fear, Run (therefore more likely to do that next time)

Do that for a few generations (10-10,000) and your system will have learn to work by itself. Lock the values when your happy and the system will hopefull manage itself. Its a case of balancing the attributes of your creatures after this point.

If this sound complicated, it kind of is. BUT it comes up with some interesting results and can give some cool 'realistic' if not sometimes suprising behaviours.

Made me want to program something up now :D
First, make separate items in the creature object: what the creature is actually doing, and what is going on inside its brain.
If your programming language supports 'sets', use them to the max.

for example:

creature.brain
--can have these states (brain_think_food, brain_think_hunt) etc.

creature.action
--can have these states (action_hunt, action_wander_around, action_jump) etc.

give also the creature object a series of 'desire' vars like:
creature.desire_food

if the desire_food var gets over a certain treshold, the creature.action state switches to (action_hunt). Make a separate routine where the code comes what happens when this happens. If the desire_food is very low, the creature.action state switches to (action_wander_around). etc.

In this way you can use case..of statements, in stead of if..then. And the code gets very transparent.
Advertisement
Cool thank for the comments so far.
Here is what i have so far


The items on the screen are as follows
The Hut in the top left
The Forest near by and an apple tree near by also... near the center is the "Town center"
the two characters are a male and female.
They wander around the town center until they are hungry then find food.. the tree emits food so they realise this and ask for food.. they then consume until not hungry and wander around again favouring the "Town Center"

i think a state based style is what i will adopt.
moving state

Let me know what you think of my WIP.

This topic is closed to new replies.

Advertisement