Capture the Flag!
1 Where to work
2 Common commands
offense-has-flag?
offense-lives-left
set-motors
get-left-input
get-right-input
radians-mode
degrees-mode
normalize-angle
angle-to-opp
dist-to-opp
angle-to-flag
dist-to-flag
get-robot-angle
get-opp-angle
looking-dist
3 Defense bot
shoot-laser
load-laser
restock-laser
laser-cooldown-left
4 Offense bot
boost
boost-cooldown-left
opp-just-fired?
8.1

Capture the Flag!

 (require ctf)

Welcome to a new Virtual Robotics competition! This year’s competition is a step up in the complexity of the tasks, but writing bots should still be easy for beginners.

Everyone is going to work in teams of two, and those teams need to make two different robots together:

The defense bot can stop the offense bot by firing lasers at it. The offense bot starts out with 3 lives, and each laser by default will make the offense bot lose 1 life. If the offense bot loses all of their lives, it will lose the flag and be teliported back to the start.

Also, for every 3 kills the defense bot gets, the offense bot will lose 1 flag.

1 Where to work

Each kind of robot (defense or offense) has its own library of commands. If you look in the manias/ctf directory, you should find three files, with starting templates and some very basic bots to build off of.

Here’s an overview of the commands you have at your disposal for controlling your bot. Some of the commands work for both bots, and some are only available for offense or defense.

2 Common commands

procedure

(offense-has-flag?)  bool?

Returns #t if offense has the flag, #f otherwise.

procedure

(offense-lives-left)  number?

Returns number of lives that the offense bot has left.

procedure

(set-motors left right)  nothing?

  left : number?
  right : number?
The left and right motors on your car determine the force on that side of the car. The power to each motor ranges from -1 (maximum push in the reverse direction) to 1 (maximum push forward).

Numbers beyond the range from -1 to 1 have no extra effect, so (set-motors -10 5) does the same thing as (set-motors -1 1).

Some examples.

procedure

(get-left-input)  number?

procedure

(get-right-input)  number?

These calls allow you to read off the state of your motors. So, if in a previous round you called (set-motors 0.3 0.6), then (get-left-input) will return 0.3, and (get-right-input) will return 0.6

procedure

(radians-mode)  nothing?

Causes all angle-returning and angle-taking functions in the game to use radians.

procedure

(degrees-mode)  nothing?

Causes all angle-returning and angle-taking functions in the game to use radians. This is the default

procedure

(normalize-angle angle)  angle?

  angle : angle?
(normalize-angle angle) returns an angle with equivilant direction, but between 180 and -180 if you are in degree mode, or between pi and -pi if you are in radians mode.

For example, in degrees mode, (normalize-angle 320) will return -40.

procedure

(angle-to-opp)  number?

Returns the angle to the opponent, relative to the bot’s current direction. (angle-to-opp) returns i0 if the opponent is directly in front of the bot, a positive angle if it’s to your left, and a negative angle if it’s to your right.

Whether the value is returned in radians or degrees depends on the mode you’re running in.

procedure

(dist-to-opp)  distance?

Returns the distance to the opponent.

procedure

(angle-to-flag)  angle?

Like angle-to-opp, except for the flag. Note that it still works when the flag has been picked up by your opponent!

procedure

(dist-to-flag)  distance?

Like dist-to-opp, except for the flag instead of the opponent.

procedure

(get-robot-angle)  angle?

This returns the absolute angle of your robot. i.e., 0 degrees means you’re pointed to the right, 90 degrees is straight up, 180 degrees is to the left, and so on.

procedure

(get-opp-angle)  angle?

Like get-robot-angle, but for your opponent!

procedure

(looking-dist theta)  distance?

  theta : angle?
tells you how much distance there is to the next obstacle, be it a wall, a robot or a laser.

3 Defense bot

These calls are only for the defense bot, and you should only use them in defense.rkt.

procedure

(shoot-laser)  nothing?

(shoot-laser) fires a laser in the direction your car is pointed. But you can’t do it too often! Note that you can’t always shoot a laser. That’s what the next command is for.

procedure

(load-laser)  nothing?

(load-laser) let’s you increase the power of your laser shot.

procedure

(restock-laser)  nothing?

Let’s you exit loading mode, without firing the laser

Here’s how it works.

procedure

(laser-cooldown-left)  number?

(laser-cooldown-left) tells you how many ticks need to elapse until you can fire or load your laser again.

4 Offense bot

procedure

(boost)  nothing?

If your cooldown from the previous boost is over, (boost) will immediatly give you a speed multiplier, as well as increase the power of your motors for a couple of seconds.

procedure

(boost-cooldown-left)  integer?

(boost-cooldown-left) will return the number of ticks until you can use (boost) again.

procedure

(opp-just-fired?)  bool?

(opp-just-fired?) will tell you if this past tick, the defense bot fired.