Docs


Calling other Minds

A MindM is a Mind that calls other Minds. See the AI model behind Ancient Brain.

In its definition of the getAction function, the Mind may call another Mind to find out what its suggested action would be. The Mind might ask multiple other Minds for suggested actions, and either use one or return an action of its own.

The basic issue with a Mind calling a Mind is that both of them are trying to define the same functions of AB.mind:

 
AB.mind.newRun = function() { ... };  
AB.mind.getAction = function ( state ) { ... };     
So we must rename the functions defined by the called Mind. Proceed as follows:
  1. Clone the Mind you want to call.
  2. Edit its code and rename its functions to different names like:
    var mind2;
    mind2.newRun = function() { ... };  
    mind2.getAction = function ( state ) { ... };
    
The other Mind won't run on its own now, but you don't care. We have the following approaches to calling it.

Mind in separate JS

Keep the Mind in a separate JS file. The calling Mind will load the separate JS and then call the function names. Something like:

 var mind2 = new Object();   
 // global variable that the other JS will now assign methods to 
  
 AB.mind.newRun = function()
 {
   $.getScript ( "/minds/nnnnnnnn.js", function() 
   {
     // JS is loaded, mind2.functions are now assigned 
     mind2.newRun();
   });	
 };
 
 AB.mind.getAction = function ( state )     
 { 
    // need some default in case JS is not yet loaded:
    if ( typeof mind2.getAction == 'undefined' ) return ( defaultaction );     
 
    // else we can call the other Mind: 
    if ( condition )
      return  ( mind2.getAction(state) );                   
    else 
      return  ( myaction );                      
 };

Mind in same JS

An alternative is to just copy the Mind code into your Mind JS file. Then you can go ahead and call its functions. Something like:

 var mind2 = new Object();   
 mind2.newRun = function() { ... };  
 mind2.getAction = function ( state ) { ... };      
  
 AB.mind.newRun = function()
 {
     mind2.newRun();
 };
 
 AB.mind.getAction = function ( state )     
 { 
    if ( condition )
      return  ( mind2.getAction(state) );                   
    else 
      return  ( myaction );                      
 };
 

Document your Mind

If your Mind needs special instructions for use, you can document this in comments in your code. For example:

// If you are writing a Mind_M to call MyMind, make sure you call MyMind on every step:
//   MyMind.getaction(state);  
// even if you are going to ignore the result.  
// This is to keep MyMind informed of every step of the run to help it build up a map of the problem.