1 / 26

Marine Biology Simulation Part II: Assignment, Milestone 1

Marine Biology Simulation Part II: Assignment, Milestone 1. Dung “Zung” Nguyen Mathias Ricken Stephen Wong. TeachJava 2004! June 25, 2004. Rice MBS Assignment. Target Audience Students at the end of an objects-first CS2 Length of Assignment Two milestones Approximately 10 hours of work

jbryan
Download Presentation

Marine Biology Simulation Part II: Assignment, Milestone 1

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Marine Biology SimulationPart II: Assignment, Milestone 1 Dung “Zung” Nguyen Mathias Ricken Stephen Wong TeachJava 2004! June 25, 2004

  2. Rice MBS Assignment • Target Audience • Students at the end of an objects-first CS2 • Length of Assignment • Two milestones • Approximately 10 hours of work • Probably supported by one or two labs

  3. Re-implement as per given specs. Re-implement as per given specs. SimpleFish UnboundedEnv Studying the Case Study White-box Framework: Extension by Subclassing Unit tests guide the way Variant Environment Behavior Variant Fish Behavior

  4. + void move() + void move() + void move() Studying the Case Study Static Behavior! Separate the variants from the invariants Strategy Pattern Dynamic Behavior Change

  5. Rice MBS Assignment • Milestone 1 • Part 1: KnightFish Add a new fish species to the simulation • Part 2: WrappingEnv Add a new kind of environment • Milestone 2 • Part 3: Internals Re-implement parts of the simulation framework • Part 4: Behavior Strategies Refactor framework to allow dynamic behavior changes

  6. Preparation • Read assignment document • Download materials for Milestone 1 • milestone1.zip • Unzip into empty directory • Open DrJava • Copy your drjava.jar into the project directory

  7. Configuring DrJava • Add RiceMBSfw.jar file to “Extra Classpath” • Edit, Preferences, Resource Locations • Click on “Add” button • Click on RiceMBSfw.jar file and “Select” • Click on “OK” at the bottom of the dialog • Now the framework has been added and can be used without source • Make sure you run in “Full Java”

  8. Running the Simulation • In the “Interactions” pane, type • java controller.MBSController • Play around with the simulation • Create new environment • Edit environment • Add fish • Run simulation

  9. Part 1: KnightFish • Randomly pick one of 8 targets • Example: 3 1 2 8 3 7 4 6 5

  10. Part 1: KnightFish • Turn into right direction • Attempt one step forward • If blocked, done • If open, go there 3

  11. Part 1: KnightFish • Attempt a second step • If blocked, done • If open, go there • Turn into right direction 3

  12. Part 1: KnightFish • Attempt the third and last step • If blocked, done • If open, go there 3

  13. Part 1: KnightFish • Moves almost like a knight, except… • No jumping • If blocked, might stop on the way 3 Stop here Stop here Stop here

  14. Part 1: KnightFish • Complicated behavior • Procedural programming: many nested if-statements • Delegation method • Nested visitors • Cannot forget to handle a situation (compiler error!) • Process flow diagramming • Makes designing complex algorithm a systematic process

  15. Part 1: KnightFish • Students do this assignment • Most of the code can be taken from existing examples • For lack of time, we will do something simpler • Fish attempts to move forward • If blocked, turn around 180 degrees • If open, go there • Open TeachFish.java in model.fish

  16. Part 1: KnightFish Ask local environment to move forward protected void move() tryMoveFwd( , ); } new ILambda() { public Object apply(Object notUsed) { turnRight(Math.PI); return null; } } Command to execute if blocked new ILambda() { public Object apply(Object moveCmd) { ((ILambda)moveCmd).apply(null); return null; } } ((ILambda)moveCmd).apply(null); Tell the local environment to actually move the fish Command to execute if unblocked

  17. Part 1: KnightFish • Compile the file • Run the simulation • Create a new environment, and edit it • Add a fish • Select “Add…” • Enter model.fish.TeachFish and hit “Create” • Click somewhere on the map • Run the simulation New fish class loaded at runtime!

  18. Part 2: WrappingEnv Grid-based, bounded, and rectangular environment If the fish leaves on one side, it re-enters from the other side Topology: torus (donut)

  19. Part 2: WrappingEnv • Very similar to BoundedEnv • In BoundedEnv, the Location class computes a neighboring location by adding a direction vector to its own coordinates. • The new coordinates might be inside or outside the environment. • Can new coordinates ever be outside in WrappingEnv? Answer is part of class assignment and has been removed

  20. Part 2: WrappingEnv • The leftmost x-coordinate that is still inside the environment is 0. The rightmost one is (width-1). • In BoundedEnv, the x-coordinate of the neighbor from there to the left is -1. • What’s the x-coordinate of the left neighbor in WrappingEnv? Answer is part of class assignment and has been removed

  21. Part 2: WrappingEnv • The necessary changes are centralized in a single method, WrappingEnv.Location.getNeighbor. • Since BoundedEnv and WrappingEnv are so similar, what OO technique can we apply to maximize code-reuse? Answer is part of class assignment and has been removed

  22. Part 2: WrappingEnv • Need to write constructors • The framework uses factory methods • Abstract creation • To complete the environment, we have to override the factory methods • WrappingEnv.makeLocation • WrappingEnv.makeEnvFactory (code provided for makeEnvFactory) • Students’ code is still based on existing code, but cannot simply be copied and modified anymore

  23. Part 2: WrappingEnv • Open WrappingEnv.java in sysModel.env • The project was split into “model” and a “sysModel” packages to clearly separate system code (environments) from user code (fish) • Fish more likely to get changed than environments • Edit the WrappingEnv.Location.getNeighbor method • Students would have to do a little bit more

  24. Part 2: WrappingEnv Code is part of a class assignment and has been removed

  25. Part 2: WrappingEnv • Compile the file • Run the simulation • Create a new environment • Select “Add…” • Enter sysModel.env.WrappingEnv and hit “Create” • Pick a size and create the environment • Add fish • Run the simulation

  26. End of Milestone 1 • Students submit code for Part 1 and Part 2 • Material for Milestone 2 gets released after submission deadline • Contains solutions for Milestone 1

More Related