Object Orientated Programming in Perl Simulated Models of Termites.

Slides:



Advertisements
Similar presentations
CATHERINE AND ANNIE Python: Part 3. Intro to Loops Do you remember in Alice when you could use a loop to make a character perform an action multiple times?
Advertisements

A MATLAB function is a special type of M-file that runs in its own independent workspace. It receives input data through an input argument list, and returns.
INTRODUCTION Chapter 1 1. Java CPSC 1100 University of Tennessee at Chattanooga 2  Difference between Visual Logic & Java  Lots  Visual Logic Flowcharts.
June 1, 2000 Object Oriented Programming in Java (95-707) Java Language Basics 1 Lecture 6 Object Oriented Programming in Java Language Basics Objects.
GoogleTest Primer. Outline Basic Concepts Assertions Basic Assertions Binary Comparison String Comparison Floating-Point Comparison Simple Tests Test.
Games and Simulations O-O Programming in Java The Walker School
1 An intro to programming concepts with Scratch Session 3 of 10 sessions Repetition and variations.
Week 9: Methods 1.  We have written lots of code so far  It has all been inside of the main() method  What about a big program?  The main() method.
Road Map Introduction to object oriented programming. Classes
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Software Development Software Life Cycle UML Diagrams.
CS 330 Programming Languages 10 / 11 / 2007 Instructor: Michael Eckmann.
Alice Variables Pepper. Set to Java look Edit / preferences restart.
CS 117 Spring 2002 Repetition Hanly Chapter 4 Friedman-Koffman Chapter 5.
Terms and Rules Professor Evan Korth New York University (All rights reserved)
Chapter 3: Arrays, Linked Lists, and Recursion
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 1 Introduction to Object-Oriented Programming and Software Development.
Robot? What’s a Robot? Introducing Karel-the-Robot.
Copyright 2010 by Pearson Education 1 Assignment 11: Critters.
Python. What is Python? A programming language we can use to communicate with the computer and solve problems We give the computer instructions that it.
Games and Simulations O-O Programming in Java The Walker School
Shorter of two objects and changing color Functions, events and setting the color Susan Rodger, Duke University June 2008.
01-Intro-Object-Oriented-Prog-Alice1 Barb Ericson Georgia Institute of Technology Aug 2009 Introduction to Object-Oriented Programming in Alice.
Week 10 - Monday.  What did we talk about last time?  Method overloading  Lab 9.
Nachos Phase 1 Code -Hints and Comments
1 JavaScript. 2 What’s wrong with JavaScript? A very powerful language, yet –Often hated –Browser inconsistencies –Misunderstood –Developers find it painful.
CPSC1301 Computer Science 1 Chapter 11 Creating Classes part 1.
REVIEW On Friday we explored Client-Server Applications with Sockets. Servers must create a ServerSocket object on a specific Port #. They then can wait.
Image Synthesis Rabie A. Ramadan, PhD D Images.
(Chapter 10 continued) Our examples feature MySQL as the database engine. It's open source and free. It's fully featured. And it's platform independent.
Collecting Things Together - Lists 1. We’ve seen that Python can store things in memory and retrieve, using names. Sometime we want to store a bunch of.
Genericity Ranga Rodrigo Based on Mark Priestley's Lectures.
COSC 235: Programming and Problem Solving Ch. 4 or… Everything is an Object Instructor: Dr. X.
Week 3 : Last step with Hubo, Python objects
1 FUNCTIONS - I Chapter 5 Functions help us write more complex programs.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2: Methods and Data Programming with Alice and Java First Edition.
CSE 351 GDB Introduction. Lab 1 Status? How is Lab 1 going? I’ll be available at the end of class to answer questions There are office hours later today.
CS305j Introduction to Computing Classes 1 Topic 23 Classes – Part I "A 'class' is where we teach an 'object' to behave." -Rich Pattis Based on slides.
M1G Introduction to Programming 2 5. Completing the program.
CSI 3125, Preliminaries, page 1 Compiling the Program.
CRE Programming Club - Class 2 Robert Eckstein and Robert Heard.
1 Printing in Python Every program needs to do some output This is usually to the screen (shell window) Later we’ll see graphics windows and external files.
Week 61 Introduction to Programming Ms. Knudtzon C Period Tuesday October 12.
More on OO Programming Our programs will no longer just be a main method or a main which calls a collection of other methods –instead, a program will be.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Programming Fundamentals. Topics to be covered Today Recursion Inline Functions Scope and Storage Class A simple class Constructor Destructor.
Georgia Institute of Technology More on Creating Classes part 1 Barb Ericson Georgia Institute of Technology Oct 2005.
CS2102: Lecture on Abstract Classes and Inheritance Kathi Fisler.
Aquarium Lab Series Developed by Alyce BradyAlyce Brady of Kalamazoo CollegeKalamazoo College.
Week 10 - Wednesday.  What did we talk about last time?  Method example  Roulette simulation  Types in Java.
Week 10 - Monday.  What did we talk about last time?  Method overloading  Lab 9.
World of Wokcraft The very best in Single pan cooking themed fantasy gaming!
Georgia Institute of Technology More on Creating Classes Barb Ericson Georgia Institute of Technology June 2006.
Computer Science Up Down Controls, Decisions and Random Numbers.
World of Wokcraft The very best in Single pan cooking themed fantasy gaming!
TERMITE model Colin Broderick Stjepan Rajcic. The termites wander around randomly until they hit a wood chip When the hit a wood chip they pick it up.
Python Lesson 12 Mr. Kalmes.
Copyright © 2008 by Helene G. Kershner
Copyright © 2008 by Helene G. Kershner
Other Kinds of Arrays Chapter 11
Python Lesson 12 Mr. Kalmes.
Methods The real power of an object-oriented programming language takes place when you start to manipulate objects. A method defines an action that allows.
CS2102: Lecture on Abstract Classes and Inheritance
Lesson 2: Building Blocks of Programming
Programming using Alice 3
Remembering lists of values lists
Barb Ericson Georgia Institute of Technology Oct 2005
© A+ Computer Science - GridWorld The GridWorld case study provides a graphical environment where visual objects inhabit and interact.
More on Creating Classes
Magpie/Chatbot Activity 5
CS1316: Representing Structure and Behavior
Presentation transcript:

Object Orientated Programming in Perl Simulated Models of Termites

A Version of the Termite Model This program explores the behavior of termites in a Java simulation. This program explores the behavior of termites in a Java simulation. mites mites mites mites To do this well we should take a look at a different kind of programming, Object Orientated programming. To do this well we should take a look at a different kind of programming, Object Orientated programming.

What is an Object? An object is a single entity that holds both the data for a part of a program and the code that works on that data. An object is a single entity that holds both the data for a part of a program and the code that works on that data. This idea came from looking at how things are organized in the world. For example, a gene has a set of properties that define it and there is a set of actions that can be done to it. This idea came from looking at how things are organized in the world. For example, a gene has a set of properties that define it and there is a set of actions that can be done to it. In Perl object orientation is expressed in the form of classes that hold information about variables and methods. In Perl object orientation is expressed in the form of classes that hold information about variables and methods.

An Object GenePropertiesName Chromosome Location MethodsTranscribeBlock Gene

Properties and Methods Properties Properties are the actual data values that tell you what exactly the object is. Properties are the actual data values that tell you what exactly the object is. For our example each termite needs to have information on where it is on the grid and whether or not it is holding a chip. For our example each termite needs to have information on where it is on the grid and whether or not it is holding a chip. Methods Methods are the things that you can do to your object. Methods are the things that you can do to your object. For this example our termites need to be able to walk around the grid and both pick up and drop woodchips. For this example our termites need to be able to walk around the grid and both pick up and drop woodchips.

Objects in Perl An object in perl is a reference to a special kind of hash, also called a class, and is marked by the class name. An object in perl is a reference to a special kind of hash, also called a class, and is marked by the class name. Calling methods is different in OO programming also. This is done by first identifying the object to be acted upon and then specifying which method in that object you want to use. Calling methods is different in OO programming also. This is done by first identifying the object to be acted upon and then specifying which method in that object you want to use. In perl this is done with arrow notation (->). So to call the method step for our termite you would type: $termite->step(args). In perl this is done with arrow notation (->). So to call the method step for our termite you would type: $termite->step(args).

Constructors To make a new object of the termite class you need to use a constructor. A constructor is a method inside the termite class called new. To make a new object of the termite class you need to use a constructor. A constructor is a method inside the termite class called new. This method takes in all of the arguments passed to the constructor and returns a scalar reference to a hash and puts the information from the arguments into the proper places in the hash. This method takes in all of the arguments passed to the constructor and returns a scalar reference to a hash and puts the information from the arguments into the proper places in the hash.

Gene Example Let’s write a short program that makes a new ‘gene’ and then asks for information about that gene. Let’s write a short program that makes a new ‘gene’ and then asks for information about that gene. We are going to need to write a class and the program that uses it. We are going to need to write a class and the program that uses it.

The Termite Class The termite wanders around randomly until it bumps into a wood chip. The termite wanders around randomly until it bumps into a wood chip. If the termite is carrying a chip, it drops the chip and continues to wander. If the termite is carrying a chip, it drops the chip and continues to wander. If the termite is not carrying a chip, it picks up the one it bumped into and continues to wander. If the termite is not carrying a chip, it picks up the one it bumped into and continues to wander.

The Grid Perl doesn’t particularly like two-dimensional arrays, but we need an area for our termites to run around and play. Perl doesn’t particularly like two-dimensional arrays, but we need an area for our termites to run around and play. To solve this problem let’s just make a one- dimensional array that we know how to work with. To solve this problem let’s just make a one- dimensional array that we know how to work with.

The Step Method We need to add in a feature that will randomly pick a direction for the termite to step in. We need to add in a feature that will randomly pick a direction for the termite to step in. The termite checks its location to see if there is a chip there. Let’s add this in. The termite checks its location to see if there is a chip there. Let’s add this in.

Object Orientation and Termites Part 2

The Termite Class What do you remember about our simulation from last week? What do you remember about our simulation from last week? We need to finish up the logic for how the termite walks around the grid. We want the termite to immediately turn 180 degrees and take a step after each time it drops a chip. We also want to see what happens if we let the termite have the option of moving in all four cardinal directions as compared to just east and west. We need to finish up the logic for how the termite walks around the grid. We want the termite to immediately turn 180 degrees and take a step after each time it drops a chip. We also want to see what happens if we let the termite have the option of moving in all four cardinal directions as compared to just east and west.

Test it! What would happen if after dropping a woodchip the termite it would randomly jump to an empty place on the grid? What would happen if after dropping a woodchip the termite it would randomly jump to an empty place on the grid? How long do we want our termites to run around the grid? Let’s try it out! How long do we want our termites to run around the grid? Let’s try it out! We can take the grid file that we saved at the end of the program and view it in Matlab to see where the termites moved our chips. We can take the grid file that we saved at the end of the program and view it in Matlab to see where the termites moved our chips.