Java
We currently only support Minds and Worlds written in Java.
We will support other languages in the future.
The instructions below should work on all operating systems.
General strategy
- Pick a World to write a Mind for.
- Write and debug your Mind offline, with an offline copy of the World.
- When ready, upload your Mind to be hosted online.
- Now that your Mind is online, other people can run it, and can call it from their Minds.
Customise these instructions
Hint: View the list of all
Worlds, pick a World,
click on "Write Mind",
and it will send you back here
with the World name filled in.
Command-line
Below we provide the actual command-line that will build a Mind.
Your
Java development environment
may automate these steps.
You may also script it
in many different ways.
1. Gather materials
- Java
- Make sure you have the
Java Development Kit (JDK) installed.
- World-Wide-Mind generic files
- Download
Skeleton.zip and extract it to yield the following files:
- w2m.jar (core World-Wide-Mind functionality)
- xerces.jar (XML parser)
- World-specific files
- Download
w2m.Tyrrell10.jar
into the directory where you put the files above.
(This is an offline copy of the World.)
- If your browser tries to re-name this to extension
.zip
just re-name it back to extension
.jar
- The
World description
should include a skeleton Mind you can download.
2. Write the Mind
- Rename the skeleton Mind to the name you picked for your Mind:
AMind.java
- Change the class name:
public class AMind implements Mind
- Edit the Mind code to send appropriate actions to the World.
The
World description
should explain State and Action format.
- Compile the Mind:
javac -cp "*" AMind.java
Newer versions of JDK on Windows:
You may need to use this syntax for a
wildcard classpath:
-cp *;
|
- Build the Mind JAR file:
jar cf0 AMind.jar AMind.class
3. Run the Mind in the World offline
- Run the Mind in the World offline
to test it:
java -cp "*" org.w2mind.toolkit.Main -mind AMind -world w2m.Tyrrell10
This will output an XML log of the run in:
runs/runid/runid.xml
- If the World can produce images of each step,
to get a run to generate images use:
java -cp "*" org.w2mind.toolkit.Main -mind AMind -world w2m.Tyrrell10 -g
This will output images of each step in:
runs/runid/step.jpg
- If you are logged in through ssh (or any other setup where there is no display) run with images as follows:
java -Djava.awt.headless=true -cp "*" org.w2mind.toolkit.Main -mind AMind -world w2m.Tyrrell10 -g
4. Upload the Mind
-
Upload AMind.jar through the
Upload Mind form.
- Optionally include an
index.html
file to describe your Mind.
This may link to multiple supporting files.
- You can (but do not have to) upload the Java source code for your Mind
to help explain how it works.
Ensure that
index.html
links to it.
- Consider whether your Mind needs any instructions for use, if it is being called by other Minds.
For example:
"If you are writing a MindM
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 better map of the problem."
- Your Mind is now on the list of
all Minds
for this World.
It will not be on the
scoreboard
list of Minds until you run it online.
- Click to run the Mind in the World online.
It should now be on the scoreboard.
- Other people can now run your Mind online, and can call it from their Minds.
Some extra notes
Minds with Memory
Minds may have memory. They may update a data structure on every step:
public class MindWithMemory
{
int i; // or any other data structure
public void newrun()
{
i = 1; // or any other initialisation of the data structure
}
public Action getaction ( State s )
{
i = i + 1; // or any other update to the data structure
}
}
|
Minds calling other Minds
When responding to getaction(state),
Minds may call other Minds,
and use their suggested actions (this is the whole point of the World-Wide-Mind):
public Action getaction ( State s )
{
return ( remotemind.getaction(s) );
}
|
If your Mind is offline, and the called Mind is on our server, this makes a network call.
When you upload your Mind to our server, this automatically becomes a direct method call.
To see how to write a MindM (a Mind that calls other Minds)
see the MindM example
in the
Skeleton World.
Writing separate classes
If you write any separate classes, they must be
serializable.
This is achieved as follows:
import java.io.Serializable;
class CLASSNAME implements Serializable
{
...
}
|
Outputting to stdout
You can output debug information to stdout when running offline:
public Action getaction ( State s )
{
System.out.println ( debug info );
}
|
|