How to write a Mind

To write a new Mind for a World, you will need to understand the state and action formats of the World. (Each World can have different state and action formats.) These formats will be explained by the World author in comments or in sample Minds.

Proceed as follows:

  1. Create your new Mind.
    Either clone an existing Mind:
    • Find a Mind that already works with the World. Go to the page for that Mind and click: to make your own copy of it. The Mind's code will show you how to parse the World state and generate correct World actions.
    Or start with a blank Mind:
    • Go to the World page and click: to make a new blank Mind.

  2. You now have a new Mind, that you own. To edit it, click:
  3. At any point, you may click: to see what your code does.
  4. Your modified code is not saved to the server until you click:

Example Mind

Here is an example Mind that you can clone and edit.

The World is a simple 3D world. The Mind makes random movements.

Simple Mind
World: Simple World
648 runs ♦ 2 likes
Starter user

Minds may have memory

Minds may have memory. They may update a data structure on every step. In JavaScript:

function Mind() 

// private variables:

  var i;				// or any other data structure

// public API:

	this.newRun = function()
	  i = 1;			// or any other initialisation of the data structure

	this.getAction = function ( x )		 
	  i = i + 1;		// or any other update to the data structure
	  return ( action );

Calling other Minds

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

When responding to getAction (state), the Mind may decide to 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 function: Mind(). So we must rename the function defined by the called Mind. Proceed as follows:

  1. Clone the Mind you want to call.
  2. Edit its code and rename its function Mind() to some different name like Mind_nnn().
  3. What if it is obfuscated? It should be no problem. We are not trying detailed edits. We just need to find the function name and change it, and then leave. This should be easy even with obfuscated code.
  4. The other Mind won't run on its own now, but you don't care.
  5. Your Mind will load the other JS and then call the other Mind using its new function name.

Something like this:

// The other Mind has been cloned. The clone has id nnnnnnnn.
// The clone has been edited and Mind() renamed to Mind_2()
// My Mind looks like:

function Mind() 
  var m2;       // the other Mind 

  this.newRun = function()
    // include the JS:
    var s = document.createElement("script");     
    s.src = "/minds/nnnnnnnn.js";
    s.onload = function() {      // JS is loaded asynchronously. Call this function when it is loaded. 
      m2 = new Mind_2();         // initialise m2 

  this.getAction = function ( state )     
    // need some default in case JS is not yet loaded:
    if ( typeof m2 == 'undefined' ) return ( defaultaction );     
    // else we can call the other Mind: 
    if ( condition )
      return  ( m2.getAction(state) );                   
      return  ( myaction );                      

Other people can use your Mind

When you write a new Mind, it will appear on the list of Minds for this World. Other people can run your Mind. Other people can clone it, and call it from their Minds.


Document your Mind

If your Mind needs 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.

The background is a program, showing the JavaScript graphics used on this site.
Customise background:  

© Ancient Brain Ltd. All rights reserved.

Ancient Brain ™ is a trademark of Ancient Brain Ltd.

Beta      Bug bounty      Contact      Stats      The name      Terms and conditions