Simulations Barb Ericson



Yüklə 449 b.
tarix24.12.2017
ölçüsü449 b.
#17032


Simulations

  • Barb Ericson

  • ericson@cc.gatech.edu

  • Jan 2005


Learning Goals



Computers as Simulators

  • “The computer is the Proteus of machines. Its essence is its universality, its power to simulate. Because it can take on a thousand forms and serve a thousand functions, it can appeal to a thousand tastes.” Seymour Papert in Mindstorms



History of Turtles

  • Seymour Papert at MIT in the 60s

    • By teaching the computer to do something the kids are thinking about thinking
      • Develop problem solving skills
      • Learn by constructing and debugging something
        • Learn by making mistakes and fixing them


Using Turtles

  • Classes created at Georgia Tech

    • As part of a undergraduate class
  • Add bookClassesFinal to your classpath



Turtle Basics

  • The turtle starts off facing north and in the center of the world by default

    • World world1 = new World();
    • Turtle turtle1 = new Turtle(world1);
  • Turtles can move forward

    • turtle1.forward(100);


Turning a Turtle

  • Turtles can turn

    • Positive turns to right
      • turtle1.turn(90);
      • turtle1.forward(100);
    • Negative turns to the left
      • turtle1.turn(-90);
      • turtle1.forward(50);


The Pen

  • Each turtle has a pen

    • The default is to have the pen down to leave a trail
    • You can pick it up:
      • turtle1.penUp();
      • turtle1.turn(-90);
      • turtle1.forward(70);
    • You can put it down again:
      • turtle1.penDown();
      • turtle1.forward(100);


More Turtle Behaviors

  • Turtles can move to a specific location

    • turtle1.moveTo(400,10);
  • Of course, you can create many turtles and move them all

    • Run TurtleTest
      • Creates 1000 turtles and puts them in an array of turtles. Has each turn by a random amount from 0 to 359 and go forward by 100


Objects can Refuse

  • Turtles won’t move completely out of the boundaries of the world

    • World world2 = new World();
    • Turtle turtle2 = new Turtle(world2);
    • turtle2.forward(600);


Objects send Messages

  • Objects don’t “tell” each other what to do

    • They “ask” each other to do things
      • Ask don’t tell
  • Objects can refuse to do what they are asked



Challenge

  • Write a method to have a turtle draw some basic shapes

    • Square
    • Triangle
    • Hexagon
    • Circle
    • Spiral
  • Use these methods to draw a simple house



Karel J. Robot

  • Set of classes developed to teach object-oriented programming



Using Karel J. Robot

  • Karel code is in karelpremeir0407

    • I modified the directories to match the package name
    • I also modified the constructor to be public
  • Follow the on-line book at http://csis.pace.edu/~bergin/KarelJava2ed/ch1/index.html

  • Add KarelJRobot.jar to the classpath. You may need to add the directory karelpremeir0407 as well.

  • Edit KarelMain.java to try things out

    • World.setVisible(true); // not visible to start
    • World.readWorld(String file) // reads the file
    • UrRobot karel = new UrRobot(1, 1, East, 0, Color.red); // create a robot at 1,1 facing east with 0 beepers and a red badge


Robot Behaviors

  • move() // moves 1 block

  • turnLeft() // turns 90 degrees left

  • pickBeeper() // picks up a beeper

  • putBeeper() // drops a beeper

  • userPause(String message) // wait for user



World Builder



Using the World Builder

  • Double click on KarelJRobot.jar to bring up the world builder

  • Use it to position walls and beepers

  • Save it to a file

  • Modify KarelMain to read that file



Robot Challenges

  • Create a maze of walls and write a method to get the robot through the maze

  • Have the robot create a pattern by dropping beepers (like a pyramid)

  • Have several robots work together to gather beepers



Card Games

  • There are public domain card images available at

    • http://www.waste.org/~oxymoron/files/cards
  • Dr. Estell of Ohio Northern University has some card game projects at http://nifty.stanford.edu/2004/EstellCardGame/index.html

    • CardAssingment.doc


Fish

  • Alyce Brady of Kalamazoo College

    • Page of resources
      • http://max.cs.kzoo.edu/AP/MBS/index.html
    • Aquarium Lab Series
      • Review of basics and set-up for Marine Biology Case Study
        • http://max.cs.kzoo.edu/patterns/JavaPatternLabs/AquariumLabSeries/index.shtml
    • Minnow Project
      • http://max.cs.kzoo.edu/AP/MBS/RelatedAssignments/Minnow/MinnowProj.html


Summary

  • Object-oriented programs are simulations

    • Consist of interacting objects who send each other messages
      • Objects can refuse to do what you ask
  • Objects belong to classes

    • An object is an instance of a class
    • Classes describe the data and operations that all objects of the class will have
    • A class creates objects
  • Objects are responsible

    • They should control their data
    • They each have their own copy of their data


Yüklə 449 b.

Dostları ilə paylaş:




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©genderi.org 2024
rəhbərliyinə müraciət

    Ana səhifə