LMU ☀️ CMSI 186
PROGRAMMING LABORATORY
LAB 4: ROBOT SOCCER Due: 2020-03-05

Learning Outcomes

Students will (1) understand the mathematics of simple animation with collisions and friction, and (2) have gained experience with Java animation (in particular, how one cleanly separates the notion of updating a data model from the drawing of each frame).

Reading

None for this lab. I’m so sorry.

Activities

robotsoccer.png

You've been hired to build a robot soccer team, but you’ve been having trouble raising funds, because you forgot to take Dr. Choi’s entrepreneurship classes. With no money for robot players, you decide to make the soccer balls themselves robotic! Your main ball relentlessly powers toward the goal. The enemies are themselves robotic soccer balls which relentlessly charge toward the player. Money is so tight you can’t even afford proper power engines; each ball just starts at an initial velocity and, subject to friction, slows down until it stops. Before building your robots, you wish to build a simulation so you can better program actual robot balls.

Here’s how the simulation proceeds. Note that you didn’t have enough money for a net, so you can enter the goal from the side.

In the codesandbox widget above, note that you can edit the code. Go to the index.js tab and play around with the five simulation parameters. See if you can trap the blue ball by making big fast enemy balls. Try to make the main ball fast enough to score without being bumped by an enemy.

Initialize a repository

As in the previous labs, go to GitHub, select Import Repository. Then:

For Your old repository’s clone URL
Enter https://github.com/rtoal/cmsi-186-lab-4-starter-code
For Your new repository details
Enter the repository name cmsi-186-lab-4.

The import might take a few minutes. When done, clone the repo and get ready to work.

Write the simulation

For this lab, you will be working entirely in one file. The starter code has holes for you to fill in, to be sure; you should begin by filling in the missing pieces so that the simulation works.

After you get the simulation working, you MUST refactor the application so that the five simulation parameters are entered on the command line. In particular, make it so:

$ java RobotSoccerSimulation 15 20 1.3 1.8 0.0009

runs a simulation in which the radius of the player ball is 15, the radius of the enemy balls is 20, the speed of the player ball is 1.3, the speed of the enemy ball is 1.8, and the friction is 0.0009. In your program, you should set reasonable upper and lower bounds for each of the arguments (so the simulation is not ridiculous). Make sure to check and handle NumberFormatException, too!

Yes, I know the JavaScript code above is visible, yes, but JavaScript is not Java so if you choose to use the JavaScript code as a guide, you will have to do some non-trivial translation. This is good real life experience, believe it or not!

And note that unlike the JavaScript hack on this assignment page, the Java starter code you are given separates the graphics from the simulation code. Your job, as you can determine form reading the starter code, is to generate each “step” of the simulation; that is, you simply update the positions of each robot soccer ball. The drawing code is done for you.

What to turn in

Online:

On hardcopy or email:

  1. Give a command line argument set where the ball just flies right into the net without getting bumped by an enemy robot.
  2. Give a command line argument set where the ball takes a really long time to get into the goal, because the enemies push it all around the field.
  3. Give a command line argument set where the ball gets “trapped” by enemies until the simulation ends.
  4. Give a command line argument set where the ball is on its way to the goal (has a clear path), but friction is too strong and the ball stops short.