AI Rework – Hunting

So, here’s where we left our “Seek Food” behavior tree (simplified somewhat):

SeekFood1

new Sequence(
    //Browsing
    new FindClosestTree()
    new WalkTo(ClosestTree),
    new Eat(ClosestTree)
)

… which was then upgraded to include…

SeekFood2

new Selector(
    //Scavenging
    new Sequence(
        new FindClosestCreatureMatch(
            new Inverter(new IsAlive))),
        new WalkTo(ClosestMatch),
        new Eat(ClosestMatch)
        ),
    //Browsing
    new Sequence(
        new FindClosestTree(),
        new WalkTo(ClosestTree),
        new Eat(ClosestTree)
    ),
)

There is a problem here I haven’t quite worked out the best way to solve (the predeliction of creatures to scavange a distant corpse when surrounded by perfectly browsable trees, because of the way the Selector at the top works), but right now I’m working on hunting.

Hunting itself is (at least at the moment) a relatively simply behavior: find something alive, walk over to it, make it not be alive, and eat. The complexities arise not from the plan itself, but from interaction of the other emotions. Fear and anger are the two arbiters of the fight-or-flight responce, and hunting needs to influence these emotions in both the hunter and huntee.

This is where a brand new system comes in:

Ping().

Ping is the way information is transferred from one creature to another. Eventually, everything from “I’m hunting you” to “I need a mate” to “I require aid” will go through the ping system. It works in a relatively simple manner: creature’s Ping others when they have information that might be of relevance to the other creature.

new Sequence(
    new Ping(HuntingYou),
    new RunTo(ClosestMatch),
    new Ping(KillingYou),
    new Kill(ClosestMatch)
)

Now just because a creature recieves a ping, doesn’t mean they will react to it. Pings are analogous to noise: a creature might not hear it, they might hear it and not be able to locate the source, or they might locate the source but deem it inconsequential. That will all depend on the (yet to be implemented) perception system.

Assuming the huntee does recieve the ping, spots the source of it, and responds, it’s fear and anger will go up. Chances are good one of these will go above their current emotion, and with an urgency threhold of 0, they will react immediately.

This reaction will in turn be accompanied by a ping back to the hunter, letting it know its preys intentions. Now it’s the hunters turn to have an emotional reaction. Seeing a large, violent creature turn to fight might well be enough to amp up its fear and send it running for the hills.

The best part of the ping system is that it’s very CPU-friendly. Rather than continually scanning the area every frame for potential threats, prey just needs to wait for and respond to a single ping. This reduces the number of checks that need to be done and ensures we only need to track relevant information.

Results

So, what’s the end result? I outfitted P. specium with the new Hunt/Flee behaviors and put 250 identical wannabe predators on the map.

The results were interesting. About half chose to flee while the others chased them, based I think on the order in which the pings were sent. I was actually expecting them to get caught in a both-creatures-hunt-both-creatures-flee loop, but it didn’t turn out that way at all.

They didn’t last: I’m not sure they even managed to reproduce. This was at least somewhat thanks to the problem I mentioned earlier: if there were still any creatures in the area, they would hunt them down rather than browsing the vegetation. It was like a zombie apocalypse if the zombies ate other zombies.

All that said, even “zombie” intelligence is a significant step up from their previous AI. Even with their animations not working (I broke them back when I was dismantling the old ai, and haven’t gotten around to fixing them), they now have a sense of purpose and agency that was notably absent before, and I can’t overstate how much of a difference this makes.

…..

More Changes

Since I wrote this, I’ve made yet another change. Creatures will now have different run/walk speeds: running for maximum meters-per-second, walking for maximum meters-per-calorie. I’ll need to change a variety of formula and perhaps add a few new stats to support this.

In addition to the implications for the simulation, running makes creatures more communicative to the player, since it is only used when hunting or fleeing. To help emphasise this, I’ll probably also adjust their leg animation using the existing Step Size system, to give them a longer gait when running.

For now I’ve just put in a placeholder run speed of 3x walk speed. This results in admittedly freakish sight of predatory Primum specium pointing themselves at an unfortunate victim and sliding across the map at a speed that is just a bit faster than what you’d think they were capable of.

They couldn’t run down a human, but if there were enough of them they might be able to swarm you, especially if you weren’t expecting it. And nobody expects the Primum inquisition.

Still a lot of work to do, but things are starting to take shape.

Next time on The Wriggling Dead: the hordes. Oh god the hordes.

They're eating that plant! And then they're going to eat me! Oh nooooooo!

They’re eating that plant! And then they’re going to eat me! Oh nooooooo!

Advertisements
  1. #1 by anarchcassius on November 27, 2014 - 7:40 am

    > There is a problem here I haven’t quite worked out the best way to solve (the predilection of creatures to scavenge a distant corpse when surrounded by perfectly browsable trees, because of the way the Selector at the top works), but right now I’m working on hunting.

    You’re going to need an If Selector in the framework, sort of like a trigger in a Blizzard RTS.

    If X is comparison Y then do sequence 1, else do sequence 2.

    For this

    X is in this case is the distance to the closest creature block found from your first sequence

    Y is the find closest plant is the distance to the closest plant found

    The comparison is greater than

    And you just replace your top Selector with the new If Selector. Creatures are one step closer to being Turing complete.

    Of course the If control is needed but you might choose to make it a bit more fall through like the rest of the system. Instead of an If Selector you could add an If modifier to your Sequence object like the IsAlive and Inverter go on Find Closest. Then you would have something more like

    If X is comparison Y then do sequence, else ignore this sequence and continue.

    That’s probably better.

    All in all I really like how this system is going. The only other games I’ve seen with individual behavoirs use fixed AI (Spore, Zoo Tycoon, many MMOs) or complex but inefficient neural nets (Creatures). I’m very curious to see how macro structure behaviors develop when they can mutate and evolve as genetic algorithms.

    The creatures having drives and ability to evaluate their environment combined with complex behavior structures is going to be a huge leap forward.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: