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:
var mind2; mind2.newRun = function() { ... }; mind2.getAction = function ( state ) { ... };
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 ); };
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 ); };
// 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.