Creating an Agent Print E-mail
Article Index
Creating an Agent
Java
Python
C/CPP

This tutorial will assume that you want to create an agent named <myNewAgent>.  In reality, you probably want a different name, so just substitute your name wherever you see <myNewAgent>.

Create the files 

Create a new agent by copying the existing random Java agent:

$>cd agents

#First thing we'll do is clean out the random agent so we don't get extra class files we don't need
$>cd randomAgentJava
$>make clean
$>cd ..


#Now, make a copy of this agent
$>cp -R randomAgentJava <myNewAgent>

Change the appropriate file names

$>cd <myNewAgent>
$>cd src

#First, rename the package
$>mv RandomAgent <myNewAgent>

#Now, rename the source java file
$>cd <myNewAgent>
$>mv RandomAgent.java <myNewAgent>.java

Note: In this example we named the agent and the agent's package the same thing.  This is not absolutely necessary.  In fact, you could have one package with many agents, or many packages with many agents in this directory.  We're keeping it simple to make this tutorial straightforward, but you can extend this and write all of your agents in this one directory with a couple of small changes to the Makefile and run scripts.

Edit the source file

$>emacs RandomAgent.java #Use your favorite editor

Now, you can either find-and-replace RandomAgent with <myNewAgent> or make the there specific changes mentioned below:

1)  Near the top, you will see the line:
package RandomAgent;

Change this to:
package <myNewAgent>;

2)  Now look for the class declaration:
public class RandomAgent implements Agent {

Change it to:
public class <myNewAgent> implements Agent {

3)  And finally, find the constructor:
public RandomAgent(){

And change it to:
public <myNewAgent>(){

Save the file.

Edit the Makefile

Go back up to the main directory for your new agent:
$>cd ../../

Edit the Makefile with your favorite editor:
$>emacs Makefile

The only compile line is:
javac -d bin -cp $(RLVizPath)/RLVizLib.jar src/RandomAgent/RandomAgent.java

Change this to:
javac -d bin -cp $(RLVizPath)/RLVizLib.jar src/<myNewAgent>/<myNewAgent>.java

Save the file.

Note: If you wanted to move your agent folder to a new location, even outside of the rl-competition distribution, all you need to do is update one line of the Makefile.  Find the first line:
RLVizPath = ../../system/libraries

Change this to:
RLVizPath=/path/to/rl-competition/system/libraries  #this can be a relative or absolute path

Edit the run script

Edit run.bash with your favorite editor:
$>emacs run.bash

The first few lines of this file contain all of the things you need to change:
basePath=../..               #Path to the main rl-competition directory                                                                                   
packageName=RandomAgent      #Name of the package the Agent is in.                                                                                
className=RandomAgent        #Name of the agent class                                                                                             
maxMemory=128M              #Max amount of memory to give the agent (Java default is often too low)                                      

Change them to:
basePath=../..               #Path to the main rl-competition directory                                                                                   
packageName=<myNewAgent>      #Name of the package the Agent is in.                                                                                
className=<myNewAgent>        #Name of the agent class                                                                                             
maxMemory=128M              #Max amount of memory to give the agent (Java default is often too low)                                      

Note: If you've moved your agent folder to a new location, you'll have to update $basePath just like you did to point to the main rl-competition directory.

Save this file.

Try it out

In one terminal window, go run the graphical Java trainer:
$>cd trainers/guiTrainerJava
$>bash run.bash

In another terminal window, build and run your new agent:
$>cd agents/<myNewAgent>
$>make
$>bash run.bash


With any luck at all, you should be able to load and start an experiment and your agent will be running!  Congratulations! 



 

Login to Message Boards

Separate username & password from team login.





Lost Password?
NOTE: Registration for message boards has been DISABLED because of SPAM. Please e-mail brian@rl-competition.org for an account.