2
\$\begingroup\$

I am developing a RTS (real-time strategy) game involving robber and cops. I have designed a simple rule based AI system for the robber.

Goals of the robber AI:

  • Escape from the cops (robber should not get caught)
  • Conduct robbery

Current implementation:

The robber AI uses a rule based system to escape from the cops. I have written IF-THEN clauses to build the rule based AI system. The robber AI uses the knowledge of cops’ current positions.

Future requirements:

I am worried about the current architecture of this robber AI system. I read that rule based systems are inefficient and difficult to maintain. For the future,

  1. I want the robber AI to use some power-ups (to escape)
  2. The AI should consider the power-ups used by the cops before making decisions.
  3. For conducting the robbery, the robber has to move to a specific location escaping from the cops.

Questions:

  1. Is the current rule based AI system will flexible enough (and easy to maintain) to meet the future requirements?
  2. What can be better alternatives for the existing rule based system? (Like decision trees or state machines etc.)
  3. I read people suggesting that the rule based systems are difficult to debug. Can anyone explain why?

I would appreciate any thought/suggestions on this topic. Thank you.

\$\endgroup\$
2
\$\begingroup\$

Is the current rule based AI system will flexible enough (and easy to maintain) to meet the future requirements?

This really depends on your specific implementation. Are all your rules defined in one giant class which has to maintain many states and check those constantly? Are the rules easily readable and understandable? When you want to expand the system how hard would it be to add a rule to the system And would adding that rule lead to problems with the existing rules?

For example if rule A wants to get left and rule B wants to go right what happens? Is rule A checked first and executed without consideration for rule B? Are both rules executed with the delta difference actually happening (Moving left + moving right = standing still).

When you're making the system you have to watch out for what takes priority and what should happen when multiple rules clash. If you don't you will get those hard to debug situations!

Updated

Example2: You add a rule that the robber should run away when fired at. Makes sense right? Now you go and add power-ups and one of those is a shield (no bullet damage for X seconds). Now you have to go in and add a rule that when the police is shooting at the robber and there is a shield power up next to him he goes and grabs it and shoots back at the police. You play the game and the robber entirely ignores the power up and runs away. Ok, you switch the priority and it works, awesome. You then decide to spawn more police and run the scenario again.

Like before the robber grabs the shield and shoots back at the police, but once the shield runs out the robber is immediately killed since the shield is no longer protecting him. So then you go and add a new rule that is if there are lots police and they are shooting and you have a shield powerup, use the opportunity and run away. You do that but he doesn't get far enough and is gunned down. So you add a new rule that if he has a shield and is running away from the police but the shield is about to run out find cover.

You can see how this gets out of control quickly... Just add 2-3 more power ups and you will need an exponential amount of rules to cover the different situations that the robber can get into. Then you have to manage priorities for each of of those situations too!

What can be better alternatives for the existing rule based system? (Like decision trees or state machines etc.)

Have a look at Task based AI. It is kind of similar to rule based except that a task must be complete before the next one is started (or i suppose you could cancel one and start another based on what is happening around it) this avoids the problem that you face in question 1 as there is always a defined next step in the middle of a task and the only points where it could be troublesome are during the period of time were the next task must be chosen.

A better solution but one that may be harder to implement is an AI which does what is best for the current situation, Goal based AI. Basically you have a bunch of possible actions that the AI can take and you essentially evaluate how useful every action is at the current moment and then do the one which is best. So for a shooter you will want to shoot at the enemy but as you shoot the ammo will be go lower and lower until the point where the score for shooting is lower than reloading (and you reload). I think this would be better in your case as you could just pop in new actions and tweak the scoring function to get the correct behaviour for the game.

I read people suggesting that the rule based systems are difficult to debug. Can anyone explain why?

This about the examples from question 1. How would you debug that? You could print out everything that the rules are looking at and try to follow the program but that only works with very few rules, the more you add the more possibility the AI has to go crazy because of X rule. You could make a program which visualises why the AI chose to do a certain action but thats a lot of work that you could avoid by using a different AI technique.

Funnily enough the developers of Sims did have a program which would show why a Sim did a certain thing See this GDC Video (it's a perfect example)

\$\endgroup\$
  • \$\begingroup\$ Thank you for the response. Regarding question 1, I have given priority to the rules. Regarding question 2, are talking about "Goal oriented AI"? The AI in which actions are taken to meet the immediate needs/goals. \$\endgroup\$ – Nimesh Chandramaniya Oct 4 '17 at 3:53
  • \$\begingroup\$ Will there be any advantage of using decisions trees instead of rule based system? \$\endgroup\$ – Nimesh Chandramaniya Oct 4 '17 at 4:03
  • \$\begingroup\$ Yep goal based AI was it, thanks. You could use decision trees and they might be easier to maintain and debug since you can follow a path down to the action taken. There is a cool little mobile game which is essentially decision trees mixed with robot fights "gladiabots", give it a go and see how you could apply the AI to your game. \$\endgroup\$ – user3797758 Oct 4 '17 at 10:04
  • \$\begingroup\$ I added another example which should better illustrate why rules can get hard to maintain \$\endgroup\$ – user3797758 Oct 4 '17 at 11:43
  • \$\begingroup\$ Out of interest did this solve your problem? \$\endgroup\$ – user3797758 Nov 23 '17 at 14:03

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.