Marine Biology Simulation Part II Assignment Milestone 1

  • Slides: 26
Download presentation
Marine Biology Simulation Part II: Assignment, Milestone 1 Dung “Zung” Nguyen Mathias Ricken Stephen

Marine Biology Simulation Part II: Assignment, Milestone 1 Dung “Zung” Nguyen Mathias Ricken Stephen Wong Teach. Java 2004! June 25, 2004

Rice MBS Assignment Target Audience Students at the end of an objects-first CS 2

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

Studying the Case Study White-box Framework: Extension by Subclassing Re-implement as per given specs.

Studying the Case Study White-box Framework: Extension by Subclassing Re-implement as per given specs. Unbounded. Env Re-implement as per given specs. Variant Environment Variant Fish Behavior Simple. Fish

Studying the Case Study Static Behavior! Separate the variants from the invariants + void

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

Rice MBS Assignment Milestone 1 Part 1: Knight. Fish Add a new fish species

Rice MBS Assignment Milestone 1 Part 1: Knight. Fish Add a new fish species to the simulation Part 2: Wrapping. Env 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

Preparation Read assignment document Download materials for Milestone 1 milestone 1. zip Unzip into

Preparation Read assignment document Download materials for Milestone 1 milestone 1. zip Unzip into empty directory Open Dr. Java Copy your drjava. jar into the project directory

Configuring Dr. Java Add Rice. MBSfw. jar file to “Extra Classpath” Edit, Preferences, Resource

Configuring Dr. Java Add Rice. MBSfw. jar file to “Extra Classpath” Edit, Preferences, Resource Locations Click on “Add” button Click on Rice. MBSfw. 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”

Running the Simulation In the “Interactions” pane, type java controller. MBSController Play around with

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

Part 1: Knight. Fish 1 2 8 3 7 4 6 5 Randomly pick

Part 1: Knight. Fish 1 2 8 3 7 4 6 5 Randomly pick one of 8 targets Example: 3

Part 1: Knight. Fish 3 Turn into right direction Attempt one step forward If

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

Part 1: Knight. Fish 3 Attempt a second step If blocked, done If open,

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

Part 1: Knight. Fish 3 Attempt the third and last step If blocked, done

Part 1: Knight. Fish 3 Attempt the third and last step If blocked, done If open, go there

Part 1: Knight. Fish 3 Stop here Moves almost like a knight, except… No

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

Part 1: Knight. Fish Complicated behavior Procedural programming: many nested ifstatements Delegation method Nested

Part 1: Knight. Fish Complicated behavior Procedural programming: many nested ifstatements Delegation method Nested visitors Cannot forget to handle a situation (compiler error!) Process flow diagramming Makes designing complex algorithm a systematic process

Part 1: Knight. Fish Students do this assignment Most of the code can be

Part 1: Knight. Fish 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 Teach. Fish. java in model. fish

environment to Part. Ask 1: local Knight. Fish move forward protected void move() try.

environment to Part. Ask 1: local Knight. Fish move forward protected void move() try. Move. Fwd(new ILambda() { public Object apply(Object not. Used) { turn. Right(Math. PI); Command return null; to execute if blocked } }, new ILambda() { public Object apply(Object move. Cmd) { ((ILambda)move. Cmd). apply(null); return null; } Tell the local Command to }); environment to actually execute if move the fish unblocked }

Part 1: Knight. Fish Compile the file Run the simulation Create a new environment,

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

Part 2: Wrapping. Env Grid-based, bounded, and rectangular environment If the fish leaves on

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

Part 2: Wrapping. Env Very similar to Bounded. Env In Bounded. Env, the Location

Part 2: Wrapping. Env Very similar to Bounded. Env In Bounded. Env, 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 Wrapping. Env? Answer is part of class assignment and has been removed

Part 2: Wrapping. Env The leftmost x-coordinate that is still inside the environment is

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

Part 2: Wrapping. Env The necessary changes are centralized in a single method, Wrapping.

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

Part 2: Wrapping. Env Need to write constructors The framework uses factory methods Abstract

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

Part 2: Wrapping. Env Open Wrapping. Env. java in sys. Model. env The project

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

Part 2: Wrapping. Env Code is part of a class assignment and has been

Part 2: Wrapping. Env Code is part of a class assignment and has been removed

Part 2: Wrapping. Env Compile the file Run the simulation Create a new environment

Part 2: Wrapping. Env Compile the file Run the simulation Create a new environment Select “Add…” Enter sys. Model. env. Wrapping. Env and hit “Create” Pick a size and create the environment Add fish Run the simulation

End of Milestone 1 Students submit code for Part 1 and Part 2 Material

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