Difference between revisions of "RoboTweaker"
RobertWalker (talk | contribs) m (→Example: Grammar fix) |
RobertWalker (talk | contribs) m (→Example: Typo) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 8: | Line 8: | ||
After reading the [[Selecting Fire Power]] article on RoboWiki, you begin to wonder whether it might not be a good idea to experiment with the amount of energy you pour into each shot. You could tweak the FIRE_POWER constant, run your bot, and repeat until you zero in on a good value; but RoboTweaker can do that grunt work for you. | After reading the [[Selecting Fire Power]] article on RoboWiki, you begin to wonder whether it might not be a good idea to experiment with the amount of energy you pour into each shot. You could tweak the FIRE_POWER constant, run your bot, and repeat until you zero in on a good value; but RoboTweaker can do that grunt work for you. | ||
− | The first task is to convert your constants so that they read values from the system properties. | + | The first task is to convert your constants so that they read values from the system properties. I'm providing the [[RoboTweaker/Props.java|Props class]] here to facilitate this. Using this class, you can change the FIRE_POWER constant to look like this: |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
<syntaxhighlight>private static final Props PROPS = new Props("myname.mybot"); | <syntaxhighlight>private static final Props PROPS = new Props("myname.mybot"); | ||
− | private static final double FIRE_POWER = PROPS.get("firePower", | + | private static final double FIRE_POWER = PROPS.get("firePower", 3.0);</syntaxhighlight> |
This means that now you can alter the amount of energy your robot uses when it shoots by setting the myname.mybot.firePower system property. RoboTweaker automates the process of trying many different values for a property and running battles for each. At its most basic level, you can directly use the BattleRunner class like this: | This means that now you can alter the amount of energy your robot uses when it shoots by setting the myname.mybot.firePower system property. RoboTweaker automates the process of trying many different values for a property and running battles for each. At its most basic level, you can directly use the BattleRunner class like this: | ||
Line 97: | Line 41: | ||
* Create a results listener that will provide fancy charts. | * Create a results listener that will provide fancy charts. | ||
* Create a results listener to dump the data to CSV for further analysis. | * Create a results listener to dump the data to CSV for further analysis. | ||
− | * Create a | + | * Create a mechanism that will allow you to tweak multiple properties at once and run battles for all permutations. |
+ | * If more than two robots are specified to participate, provide an option to either select one robot and have all the others go one-on-one with it, or put them all together in a single melee battle. |
Latest revision as of 18:00, 13 May 2016
RoboTweaker is a tool currently under development by RobertWalker to help you optimize your bot's performance. It's not currently available, but below is a description of how it is intended to work.
Example
Let's say you have the following constant declared in your bot:
private static final double FIRE_POWER = 3.0;
After reading the Selecting Fire Power article on RoboWiki, you begin to wonder whether it might not be a good idea to experiment with the amount of energy you pour into each shot. You could tweak the FIRE_POWER constant, run your bot, and repeat until you zero in on a good value; but RoboTweaker can do that grunt work for you.
The first task is to convert your constants so that they read values from the system properties. I'm providing the Props class here to facilitate this. Using this class, you can change the FIRE_POWER constant to look like this:
private static final Props PROPS = new Props("myname.mybot");
private static final double FIRE_POWER = PROPS.get("firePower", 3.0);
This means that now you can alter the amount of energy your robot uses when it shoots by setting the myname.mybot.firePower system property. RoboTweaker automates the process of trying many different values for a property and running battles for each. At its most basic level, you can directly use the BattleRunner class like this:
import rjw.robotweaker.*;
import java.util.Iterator;
public class Test {
public static final void main(String[] args) {
DoubleTweak tweak = new DoubleTweak("myname.mybot.firePower", 0.1, 3.0, 0.1);
for (Iterator<Void> iter = tweak.iterator(); iter.hasNext(); ) {
System.out.println();
System.out.println(iter);
iter.next();
new BattleRunner("C:\\robocode")
.rounds(100)
.addRobots("myname.mybot*", "sample.Crazy")
.go();
}
}
}
Objects which implement the Tweak interface define properties that can be tweaked. In this case, it's a double value, which we want to start at 0.1 and end at 3.0, incrementing by 0.1 each time. We then pit our bot against sample.Crazy with 100 rounds per battle. The DoubleTweak class sets the system property through each iteration, then BattleRunner will execute the battle. Eventually, I'll provide the ability to provide custom handlers for analyzing the results, but as it currently stands BattleRunner dumps the results to the console, allowing you to see what happened at each setting.
Future Plans
- Execute tweak runs from a configuration file so that you don't have to write any code to use RoboTweaker.
- Provide a mechanism to use results listeners instead of just dumping to the console.
- Create a results listener that will provide fancy charts.
- Create a results listener to dump the data to CSV for further analysis.
- Create a mechanism that will allow you to tweak multiple properties at once and run battles for all permutations.
- If more than two robots are specified to participate, provide an option to either select one robot and have all the others go one-on-one with it, or put them all together in a single melee battle.