When you create a new agent, the code should be in its own project, so that you don't have to change anything in the client project directory. There are many ways to do this, of course. This page describes the way I've been making my agent projects.
First, create a maven project for your agent. Maven includes template projects called "archetypes" that you can use. To start, type
This will give you a list of known archetypes. Accept the default, which should be "maven-archetype-quickstart". Next, maven will ask some questions that tell where the project JAR file will be stored in the maven repository, and what you package structure is. Here are some example answers:
groupId: orst.stratagusai artifactId: mylogin-myproject version: 1.0-SNAPSHOT package: orst.stratagusai.agents.mine.project
The project directory and a maven pom.xml file will be generated for you. Next, you need to edit the pom.xml to configure the project and add your dependencies. You'll probably want to use at least Java 1.5 features, so add this section:
<build> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.5</source> <target>1.5</target> </configuration> </plugin> </plugins> </build>
You'll also need to add the Java API dependency in the <dependencies> section:
<dependencies> <dependency> <!-- stratagus socket protocol --> <groupId>orst.stratagusai</groupId> <artifactId>stratagusai-client</artifactId> <version>3.0-SNAPSHOT</version> </dependency> ...
Look at stratagusai/client/trunk/pom.xml for a complete example of how a pom.xml file is structured.
Now that you have your own agent project, you can build an agent. Create a class in your project that implements the orst.stratagusai.Controller interface. It could have empty methods just to get started. BaseController? provides some common implementation, and you can look at HeuristicAgent? and RandomAgent? for some examples of how to implement a controller. Build your project using
OK, Two steps left to go.
You'll need a script file to set up the java class paths and to call the main method. Copy client.sh or client.bat and add your newly created JAR to the listed JARS in the class path.
Lastly, you'll need to create a configuration file. Copy stratagusai/client/trunk/players.config or use the example below. Let's call it "myconfig.yaml". Make it look look something like:
!!orst.stratagusai.config.Config mapPaths: [maps/5v5_PvP_36x36.smp] episodes: 3 agentConfigs: - !!orst.stratagusai.config.ControllerConfig controllerClassName: orst.stratagusai.agents.mine.project.MyAgent
Ready to run!
./client.sh -c myconfig.yaml
At this point the client will wait to connect to the Stratagus engine. You will need to run the stratagus program in stratagusai/engine/trunk.