In this assignment, you will write a team strategy to control robots
playing soccer. For each robot, you will need to determine at every
given moment, its velocity and turning angle, analogous to the
simple car seen in CarSim.
To get started:
- Download and unpack soccer.jar.
- Inside that directory, execute Soccer using the
commandline argument gui as follows:
java Soccer gui
- Then click "reset" and then "go". You will see a sample game
being played between two teams.
- Now examine the files in the directory. Of importance to you
are two interfaces called
TeamController
and
SensorPack.
- Let's look at
TeamController:
- Your strategy will implement the interface. Then, to run your
strategy, simply type the name of your class file in either
the team-0 or team-1 textfield.
- To see what a "dummy" implementation looks like, look at
the code in
TestTeam0.java.
- Most of the "intelligence" is in the
move() method.
Here is where you will decide what controls you will issue to
each player.
- Each robot has two main controls: velocity and turn-angle.
The first control (i==1 in getControl())
is velocity, and the second one is the turn-angle,
the same as in CarSim.
- Each robot can also decide to grab the ball when it's
nearby. You can think of the robot's construction has having
a little inward wedge - if the ball is held there, it allows
the robot to "dribble" (or carry the ball forward while it moves).
- And, finally, a robot can kick the ball.
- The SensorPack is given to you in one of the
two init() methods. This allows you to "see" the
field and obtain the location of the ball, and the other players.
Next, we'll describe both the "physics" and the rules of the game:
- The field is 100 units in length and 40 units wide. Each
goal is 20 units wide, and each goal has a goal area around it.
- The objective of the team on the left is to score goals on the right side, and vice-versa.
- There are also some penalty and foul points. You incur a penalty for
each time step that a player from your team is inside your own
goal area. The idea is, we want to discourage mere blocking of the goal
by standing right in front.
- You incur a foul if you collide with a player from the other team
who is not moving. If both players are moving, neither is fouled.
- The overall score is the sum of your goal points,
and the fouls and penalties incurred by your opponent.
We will play off every one in the class against everyone else,
and compute a ranking. Your score in the assignment will
depend on your ranking - so please do take this seriously!
- Both the players and the ball are treated as hard discs that
bounce off of each other. The collision calculations are very
approximate and have a little random error added, so don't expect
to pre-compute collisions exactly. You can see how this works,
if you like, by examining the code in Soccer.java.
- The players and ball also bounce off the walls, a little
like indoor soccer, except for when the ball hits the goal.
At that time, it's considered a goal and the ball is placed
at a random location on the center line.
- A player that's grabbed the ball can't hold on to it for
more than 8 seconds - after this, the ball is automatically
kicked. If a player has the ball and is bumped by another,
the ball automatically pops out.
- A player can kick the ball only if the player has the ball.
A kicked ball decelerates so that a kick placed just after
the half line will land in the goal. A kick placed before
will not.
This is how the simulator works:
- At each time step (one tenth of a second), the simulator calls
the move() method of each team controller. Each
team controller computes but does not (yet) return anything.
- After the two move() methods are called, the
simulator then calls getControl(p,i) for every
possible combination of player and control. There are
only two controls, i==1 for velocity and i==2
for turn-angle.
- The velocity needs to be in the range [0,10] whereas the
turn control needs needs to be in the range of [-10, 10].
- Once the simulator knows the controls, it applies them to
each of the players to compute the next locations and orientations
(given by theta in the code). Then, the simulator
applies the physics of collisions to compute the new orientations.
How to write a strategy:
- Your strategy will implement the TeamController
interface. See the code in TestTeam0.java for an example of
how the interface is implemented.
- Of course, to do anything reasonable, you'll need to know where
the "enemy" is, where the ball is etc. You will have a pack of
sensors given to you, via the SensorPack interface. Simply call the
appropriate methods in there to learn about the current
configuration of the soccer field. For example, you could get the
ball's location and move a player towards it.
- Note that angles are measured in radians from 0 to 2π. Thus,
a robot whose orientation is π/2 will travel upwards on the
screen. These are the same conventions as in CarSim (whose code we
are using for the dynamics).
- Once you have written a strategy, enter the name of the
class file in the left field (team-0). Then, you can play against
your strategy manually or play it against another strategy.
- NOTE: this is obviously not a professionally written simulator
and so there are very likely some simple "hacks" or "backdoors" that
can break the simulator. It would be quite improper to exploit these in
your strategy.
About the GUI/command-line options:
- In this assignment, we will stick with the simple unicycle model.
- You can manually play against any strategy. For example, you
can upload a strategy as team-0 and play against it manually.
To choose the controls for any individual player, simply use
the two sliders (one for each control: velocity and turn-angle).
You can also decide which player to apply the controls to.
- There are four teams whose code has already been written, for
you to test your strategy against. The two trivial ones are
TestTeam0.java and TestTeam1.java. These are
present merely for you to examine how the interface is implemented.
Obviously, it should be possible to beat these quite easily.
Two other teams, whose source code is not included are the
Schlemiels and the Schlimazels. These have
a little "intelligence" in them, as you should be able to
discern by watching them play each other. A good goal for you
is to regularly win against them.
- Once you have debugged your strategies and you want to run
multiple games, you can use the "competition" mode. For this
purpose, edit the competition method
in Soccer.java to include your team. Then,
run the program as java Soccer competition.
Submission:
- You may submit one or two strategies, and each must be
in its own class file with full source provided (so that
we can compile).
- Make sure your usename is embedded in the name of your
classes. For example, if your username is Karel,
then your first strategy should be called Karel.java
while the second should be Karel2.java.
- If you need to make additional classes, include those
classes in the same file.
- Please submit only your strategies, not the rest of the game.
We will copy over all strategies into a single directory and
run them competition-style.
- Submit via Blackboard in the usual way.
Thus, if your username is
Karel, you can call the file Karel5.jar.