I've been creating an interactive fiction game in javascript that uses an entity component system as described here. The problem I've encountered is in developing the AI system for the game. Ideally, I'd like to use Goal Oriented Action Planning (GOAP) for the AI. Unfortunately, this seems to be at odds with using an ECS, largely because the state pattern doesn't seem to work with such entity frameworks.

Here's a simple example of a series of actions that might be taken to achieve the goal of answering a phone within the game.

Goal: answer the phone when it rings

Walk to desk -> sit on chair -> pick up phone

The route taken to answering the phone might end up differing based on the presence of numerous other preconditions. Maybe there's an obstacle in the way, or perhaps the actor no longer has a chair to sit on. In addition to this, the actor may be given other priorities in a queue.

At the moment, even simple goals are causing headaches with a lot of conditional checks.

I'm wondering, it it possible to implement something like GOAP within such a game, and how would I go about accomplishing this? Or should I give up on using GOAP for some alternative AI system?

  • 4
    \$\begingroup\$ Despite some folks insisting on exceptionally strict definitions, your own Entity Component System can be as flexible as you need it to be. The goal isn't to make the most perfect ECS, but to let ECS ease the work of building your game. As soon as an ECS rule starts making it harder instead of easier, consider breaking that rule. There's no particular reason your "state machine system" can't delegate most of its work to state objects, while the rest of your ECS maintains a more strict logic/data divide, if you find that useful. \$\endgroup\$ – DMGregory Dec 13 '17 at 14:12
  • 1
    \$\begingroup\$ I've taken this into consideration and have come up with some code that functions, but is a bit of a mess at the moment. I'll update my question with details of my solution once I've cleaned it up a bit. \$\endgroup\$ – pigasus Dec 15 '17 at 9:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.