Rule Based AI

Published October 16, 2008
Advertisement
Welcome to another week of Milkshake development.

At the end of last week's entry, I'd laid out my basic idea for handling AI in a way that would support lots of different AI paradigms. In theory, it was very appealing - but the more examples I tried out, the more questions that popped up around how the AI "program" controls how its tasks are run. A complex bit of AI can have some main background logic, several event handlers, any of which can fire off a set of sub-tasks, which might in turn run event handlers and background tasks. Not only is working out how to prioritise/mediate between all these tasks complicated in itself, but providing a simple, intuitive and deterministic interface for the program author makes it that much harder again.

This was definitely a problem that wasn't going to solve itself in a day - so I set out to write a few basic Tasks to play with while I thought about it.

The first two blocks I've created are Moove and PhysicsSensor. The Moove Task allows you to directly drive an Agent around the game world, by propelling him forward and/or turning him. And the PhysicsSensor allows you to react to bumping into things.

Even with just two blocks, I've been able to build lots of different rule-based motion reminiscent of the mighty Head Over Heels. I've got enemies that turn left or right whenever they hit something, enemies which patrol back and forward, enemies which spin for a bit and head off in a new direction ... and I guess that's about as far as I've got. But it's still encouraging to see how easy it is to re-use even just two very simple blocks in lots of different ways and then pushing blocks in front of them to see them react.

Here's a simple "walk forward until you hit something, and then spin for 0.7 of a second" program:
Disabled

And here are the little Elephants running about using those instructions:
Disabled

The hardest bit to get right was the super-dooper accurate angle motion (turn exactly 90 degrees then walk forward) because even a slight error sends you into the wall and ruins the predictability (and hence the game play). In the end, I realised I'd never get it 100% accurate due to the numerical error in the arctan calculation used to determine the current direction - but I got it accurate to within 1/256th of a degree and then made the collision detection code ever-so-slightly-forgiving.

Anyway, with my little toy in place, I got back to thinking about the bigger problems of Task management. And I'm glad to say, I'm now the proud owner of an 8 page design document that lays it all out! It's a lot of relatively dry work (months of work I suspect), so don't expect to see the finished problem for quite a while, but I'm optimistic it will be pretty powerful once it's done.

Cheers!

Previous Entry Pretty Dumb AI
Next Entry Space Prawns Only!
0 likes 7 comments

Comments

rip-off
Looks very nice.
October 17, 2008 04:31 PM
Milkshake
Thanks Brian - it's always a little disappointing to write up a bunch of work and then not to get any replies, so thanks for taking the time to comment =)
October 17, 2008 07:53 PM
Ravuya
I meant to comment on the earlier entries, but I always get distracted with work while I'm reading your journal. [sad]

I think the game is starting to really come together. Will AI behaviour always be fixed to the room, or will it have some degree of autonomy? I assume it will be patterned like the old Spectrum isometric puzzle games.
October 19, 2008 04:48 AM
Milkshake
Quote:Original post by Ravuya
I meant to comment on the earlier entries, but I always get distracted with work while I'm reading your journal. [sad]

I think the game is starting to really come together. Will AI behaviour always be fixed to the room, or will it have some degree of autonomy? I assume it will be patterned like the old Spectrum isometric puzzle games.


Hey Rav - nice to hear from you =)

So a few different answers to your question.

The first answer (a purely technical one) would be that my serialisation mechanism supports incremental load/save. So the enemy file itself can come pre-loaded with some autonomous/general AI. But then you're free to override some/all of this when you drop the guy into the room, so you can create custom/room-specific AI on any dude you load in, and it will be incrementally applied to whatever is in the default enemy file.

Second answer (relating to the AI Task stuff I'm designing now) is that one of the main reasons I'm doing this Task architecture is that it bridges the gap between simple rule-based behaviour reminiscent of the old Speccy games, and more modern behaviours. And it allows the two to sit side-by-side (so you can have some simple rule-based motion, next to some fancy-pants combat, or some script-driven A* path finding malarky). And it was exactly that problem which had me putting off AI for so long - because I wanted to be able to experiment with newer AI techniques - but at the same time, I definitely wanted to be able to do the old-school stuff too, and I didn't want to have two totally different systems for doing them both.

Third answer is I guess the current game. I'm definitely planning to have lots of well-defined rule-based motion enemies (i.e. the Spectrum style dudes) as I think they lend themselves really well to puzzles/challanges. And this behaviour really needs to be fully predictable (when you see the little robot with the flashing orange light on his head, he always needs to behave the same way or you won't rely on him to do that). But, as well as that, I'm wanting to put more of an interactive story into the game - and to do that, I'll want to have lots of location-specific behaviour too. The elephant guard is my AI test bed right now - but I suspect in the final game, he'll end up with some higher level, more autonomous AI than the average spectrum enemy.

So a bit of both I guess =)
October 19, 2008 10:04 PM
Jotaf
Awesome, I was a bit scared that the design was too ambitious to get some immediate results! I see it's not the case. I'm also intrigued by the possibility of mixing predictable enemies / puzzle aspects with more intelligent opponents, it seems to have the potential for great fun! :)

BTW you have a decent share of loyal readers so don't be discouraged if not everyone replies all of the time, sometimes a blog post is *really* good but I'm just not in the mood to write (many hours of coding have the tendency to do that). ;)
October 25, 2008 04:55 PM
Todo
As one of your trusted readers I could basicly quote everyone above this post (excluding you yourself of course :)). Having no one reply from the get go probably means they're still in awe (I know I am).
October 27, 2008 01:03 PM
Milkshake
Thanks dudes =)
October 28, 2008 10:45 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement

Latest Entries

Moose Sighting

1394 views

Constraints

1563 views

Moose

1296 views

Melon Golf

1855 views

Toon

1358 views

Spaceships

1110 views

Rendering Pt2

1201 views

Hardware Shaders

1240 views
Advertisement