UW Home     CSE Home   Announcements    Discussion Board    Contact Info 

 
 
 

CSE143 Winter 2005 Project #1 Part B

Traffic Jam! - Animated Vehicles

Due: Friday, Jan 28, at 9:00 pm. No late assignments will be accepted.

This is the second part of a project to create a simulation of roads and vehicles. For this part you will take your road and vehicle classes from Part A and add a time-based animation and a graphical display to show the vehicles driving around the road network in a Java Swing window.

You should continue to work with your assigned partner on this project using the pair programming style discussed in class. While it makes sense to think about the project, sketch ideas, and try them out on the computer yourself (when your partner is not around), it works best if the two of you write the actual project together at a single computer, trading off the keyboard regularly. You and your partner should turn in a single set of files under the same name you used for part A.

Grading: As with part A, this part of the project will be evaluated on a scale of 0-3 to give you quick feedback on whether there are any significant problems that need to be addressed. Be sure to include appropriate JavaDoc and other comments in your code, use meaningful names, indent sensibly, and so forth.

Overview 

In Part A of this project we created a set of classes to model various kinds of roads and vehicles with various behaviors. In this part of the project we want to add a graphical view and introduce a time-based simulation so we can watch the vehicles as they drive around. This should not require many changes to the existing road or vehicle classes and few, if any, changes to existing JUnit tests. At the end of this part of the project we will have a model (containing the information about the state of the simulation), one or more viewers (regular Java Swing windows and panels), and a way to make the vehicles move as the simulation progresses. There are no interactive controls like buttons, mouse clicks, or keyboard events yet. (That's next!)

A key difference between this part of the project and part A is that instead of driving for arbitrary intervals, as done in the JUnit tests from part A, we want the vehicles to move smoothly under control of a time-based simulation. During each clock tick, or cycle, of the simulation, we want each vehicle to move a small amount -- this will create the illusion of smooth movement. You should be able to use the methods you implemented in part A to move the vehicles.

The main difference between the code moving the vehicles for this part of the project is that the model needs to be aware of the passage of time in the external world of the people watching the display, and needs to wait appropriate amounts of time (again, in the external world) between requests to the vehicles to move. That doesn't mean that simulated time has to match real time. The simulator clock ticks about 20 times per second. You need to decide how much simulated time (in seconds or minutes) each tick of the simulator clock represents. As long as the simulated time interval per clock tick is reasonably short the animation will appear to move smoothly.

We suggest that you start with the bouncing ball simulation, shown in class, as an example of how to set up the time-based simulation and how to partition the code into a model and viewer. You'll need to make some minor changes to your code from part A so that each moving object implements the SimThing interface and can participate in the simulation. But you shouldn't need to make major changes to your existing code, and your existing JUnit tests should continue to work, unless you deliberately change how your objects work. You'll also need graphics methods to draw each vehicle, road piece, and any other items you want in the display.

What to do for part B

Add a Swing-based viewer to show the road network and the locations of the various vehicles as they drive around. This can be fairly simple, but at a minimum should be able to show the roads as lines or rectangles, and each vehicle using a small graphic (a small circle is fine, or perhaps a rectangle to indicate the vehicle's length). More elaborate views and multiple viewers are fine, but get a simple version working first before you try something more elaborate.

Provide appropriate methods in your vehicles and roads, as needed, to support the view and the animation.

Unless your simulation is a completely closed road network, you will probably want to have some way to add vehicles to the simulation to model new cars arriving from the outside world (maybe randomly?), and also, if your vehicles can drive out of the simulated world, you'll need some way to remove them from the simulation. One possible way to do this would be to create additional road subclasses that create new vehicles and then transfer them to a lane, the same way that vehicles are already transfered between lanes and intersections. Another class could accept vehicles from the end of a road and remove them from the simulation.

Testing

You should retain the JUnit tests from part A and run them every now and then to be sure that any changes you make to the code don't introduce bugs. You should also add tests if needed to check significant new code.

Minimum Requirements

This project is very open ended, with plenty of opportunities for creativity and extensions. But your graphical simulation should meet the following minimal requirements:

  • Add a Swing viewer and the time-based simulation. Your program must be based on the MVC or Model-Viewer architecture, with as minimal a coupling between parts as possible. In particular, your vehicle objects should continue to calculate and store positions using the virtual world's coordinates, not pixels, and use the virtual world's time scale. The conversion from real coordinates to screen coordinates must be done by the viewer object (the one dealing with the graphics).
  • There must be at least one instance of each of your two required vehicle subclasses in the animation. (If you have more vehicle subclasses, please feel free to throw them in too.) You should also have at least one instance of each of your road subclasses (lane, intersection, etc.).
  • You should retain the JUnit tests from part A and add a few JUnit tests if needed to verify that the control of the vehicles works as expected.
  • Include JavaDoc as usual.

Possible Extensions

Some amount of extra credit will be awarded at the final end of the project for particularly impressive technical, artistic, or other extensions that go beyond the basic requirements. Here are some possibilities to get your imagination going - but you don't need to limit yourself to these.

  • See the extra credit suggestions at the end or part A.
  • More realistic vehicle and driving style behavior.
  • Smooth turns in intersections.
  • Spiffy vehicle graphics.
  • Crashes, stalled cars, other obstacles.
  • Dead ends.
  • Scenery.
  • Have your roads change while the simulation is going on - maybe drawbridges?
  • Compute useful simulation "statistics", for instance:
    • Average speed of all vehicles.
    • Average "throughput" of lanes -- How many vehicles per minute are coming out of the lanes?
    • Congestion -- What fraction of all road length is occupied by vehicles
  • Display the simulation statistics either in the main view or in a separate window
  • Path planning -- Give your vehicles a specific destination, and have them try to pick a route that reaches that destination. If there are several possible routes, they could try to pick one that gets them to the destination in a reasonable time, or has the shortest distance.
  • Teleportation, UFOs, 3-D, ....

You might also start thinking about extensions you could make when user input (keyboard, mouse, etc.) is added in the final part of the project, in case that influences your decisions about what to do now.

What to turn in

Use this online turnin form to turn in the Java source files that make up your project, including your JUnit tests. If your project uses any other files, such as images, turn those in also. If you have many files, including things like images, you can bundle them into an archive file (zip, jar, or tar) and turn that in. Multiple turnins are fine and highly suggested if you are planning to add extensions. Once you've got something that meets the basic requirements, turn that in. Then if you add to your project, turn in the extended version(s) later - we'll grade the last one you turn in.