1 / 21

Simulations

Simulations. Barb Ericson ericson@cc.gatech.edu Jan 2005. Learning Goals. Understand that object-oriented programs are simulations of turtles of robots of card games of fish. Computers as Simulators.

rex
Download Presentation

Simulations

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. Simulations Barb Ericson ericson@cc.gatech.edu Jan 2005 Georgia Institute of Technology

  2. Learning Goals • Understand that object-oriented programs are simulations • of turtles • of robots • of card games • of fish Georgia Institute of Technology

  3. 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 Georgia Institute of Technology

  4. 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 Georgia Institute of Technology

  5. Using Turtles • Classes created at Georgia Tech • As part of a undergraduate class • Add bookClassesFinal to your classpath Georgia Institute of Technology

  6. 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); Georgia Institute of Technology

  7. 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); Georgia Institute of Technology

  8. 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); Georgia Institute of Technology

  9. 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 Georgia Institute of Technology

  10. 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); Georgia Institute of Technology

  11. 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 • The object must protect it’s data • Not let it get into an incorrect state Georgia Institute of Technology

  12. 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 Georgia Institute of Technology

  13. Karel J. Robot • Set of classes developed to teach object-oriented programming Georgia Institute of Technology

  14. 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 Georgia Institute of Technology

  15. 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 Georgia Institute of Technology

  16. World Builder Georgia Institute of Technology

  17. 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 Georgia Institute of Technology

  18. 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 Georgia Institute of Technology

  19. 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 Georgia Institute of Technology

  20. 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 Georgia Institute of Technology

  21. 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 Georgia Institute of Technology

More Related