Designing Agent Strategies
Once again, the basic steps for implementing an agent based agent strategy are:
Submitted by jk on Wed, 2006-09-20 09:44.
- Get data about the environment from sensors
- Process sensor data
- Preform an action based on the data
Techniques for Designing An Agent's Strategy
To design agent strategies, you'll need to get your feet wet with the "steve" language. In particular, you'll want to learn how to write simple expressions and how to define instance variables.
As in the example on the previous page, the basic foundation of any Capture the Flag agent strategy is to sense the location of other objects and to react accordingly, typically by deciding to move towards or away from the object. The particular challenge is designing an agent strategy around which objects to react to in which contexts. Here are some examples of the types of behaviors an agent might want to implement:
- Is the other team's flag visible? If so, go towards it. If not, search for the flag by going towards the opponents' home.
- Am I holding the flag? If so, try to get back to my own home.
- Are most of my teammates jailed? If so, try for a jail break.
- Is an agent from the other team near me? If so, and if we're on my own side, try to tag the agent; otherwise, avoid the agent.
if( controller get-jailed-red-count ) > 5: {
jail = ( self sense-other-jail ).
if( self get-angle to ( jail get-location ) ) > 0: {
self turn-right.
} else {
self turn-left.
}
self set-speed to 1.0.
}
In the above example, we show a single bit of agent logic: try for a jailbreak when most of the red team is in prison. In an actual strategy, we typically need code to deal with many different situations. Here's some template code which shows how to detect different scenarios and to act accordingly:
+ to iterate:
if ( controller get-jailed-red-count ) > 5: {
...
} else if ( self sense-other-flag ): {
...
} else if ( ... ): {
...
} else: {
...
}
super iterate.
Testing A Strategy in a Tournament
Here are the instructions to run a tournament between two strategies. You can leave one strategy empty if you simply wish to test how a strategy will behave. To run a match between two strategies:- Edit the file Tournament.tz (included with the CaptureTheFlag files).
- Include the proper source files for your strategy with "@use" lines
- Change the classnames on the two "new" lines (16 & 18) to create the proper object types.
- Run the simulation!
