title: Design pattern for large decision tree based AI in c++
body: <p>I'm currently writing an AI for a game that is written in c++. The AI is conceptually fairly simple, it just runs through a decision tree and picks appropriate actions. I was previously using prolog for the decision engine but due to the other developers using c++ and some issues with integrating the prolog code I'm now trying to port it to c++.</p>
  
  <p>Currently I have a bunch of facts and rules in prolog (100+). Many express things in the form, if game_state then do action xyz. Most of the rules are fairly simple with a few being rather complex. I looked at a finite state machine approach, but that didn't seem to scale to the larger situations so well.
  My first attempt at coding this up in c++ was a huge nightmare of if then else case statements. I had this sort of code popping up everywhere:</p>
  
  <pre><code>    if( this-&gt;current_game_state-&gt;some_condition == true ){
          if( this-&gt;current_game_state-&gt;some_other_condition == false ){      
                  //some code
          }else{
              return do_default_action();
          }
      }else if( this-&gt;current_game-&gt;another_condition ){
          //more code
      }
  </code></pre>
  
  <p>The complexity became quickly unmanageable.</p>
  
  <p>If there a good way to code this sort of problem in c++? Are there any good design patterns to deal with this type of situation? There is no requirement that the logic has to be contained within the source, it just needs to be accessible from c++. The only real requirement is that it is reasonably fast.</p>
  
  <p>I also looked at rules engines and if fast enough they could be appropriate. Do you know if there is a open source c++ rules engine that would be appropriate?</p>