Adapted from slides by Marty Stepp and Stuart Reges

Slides:



Advertisements
Similar presentations
CS 112 Introduction to Programming
Advertisements

Copyright 2010 by Pearson Education 1 Assignment 11: Critters reading: HW11 assignment spec.
Copyright 2010 by Pearson Education 1 Assignment 11: Critters.
Copyright 2008 by Pearson Education Building Java Programs Chapter 9 Lecture 9-x: Critters reading: HW9 Spec.
Copyright 2010 by Pearson Education Homework 9: Critters (cont.) reading: HW9 spec.
Copyright 2008 by Pearson Education Building Java Programs Chapter 9 Lecture 9-2: Interacting with the Superclass ( super ) reading:
Building Java Programs Chapter 8 Lecture 8-3: Object state; Homework 8 (Critters) reading:
Copyright 2008 by Pearson Education Building Java Programs Chapter 9 Lecture 9-2: Interacting with the Superclass ( super ); Discussion of Homework 9:
Copyright 2010 by Pearson Education Building Java Programs Homework 8: Critters reading: Critters Assignment Spec.
Copyright 2010 by Pearson Education Homework 8: Critters reading: HW8 spec.
Copyright 2008 by Pearson Education Building Java Programs Chapter 9 Lecture 9-2: Interacting with the Superclass ( super ); Discussion of Homework 9:
Copyright 2009 by Pearson Education Building Java Programs Chapter 8: Classes Lecture 8-3: More Critters, static.
CS 112 Introduction to Programming Method Overriding; Object Hierarchy; Event-Driven Programming Yang (Richard) Yang Computer Science Department Yale University.
Adapted from slides by Marty Stepp and Stuart Reges
Adapted from slides by Marty Stepp and Stuart Reges
CSc 110, Autumn 2016 Lecture 26: Sets and Dictionaries
CSc 110, Autumn 2017 Lecture 15: Strings and Fencepost Loops
Adapted from slides by Marty Stepp and Stuart Reges
CSc 110, Autumn 2017 Lecture 16: Fencepost Loops and Review
CSc 110, Spring 2017 Lecture 12: Random Numbers
Adapted from slides by Marty Stepp and Stuart Reges
Adapted from slides by Marty Stepp and Stuart Reges
Building Java Programs
CSc 110, Spring 2017 Lecture 29: Sets and Dictionaries
Weds, Nov. 26th Reading: Section Handout
Homework 8: Critters reading: HW8 spec.
The software crisis software engineering: The practice of developing, designing, documenting, testing large computer programs. Large-scale projects face.
Adapted from slides by Marty Stepp and Stuart Reges
CSc 110, Autumn 2017 Lecture 18: While loops and File Input
Building Java Programs
Adapted from slides by Marty Stepp and Stuart Reges
CSc 110, Autumn 2017 Lecture 37: searching and sorting
CSc 110, Autumn 2016 Lecture 13: Random Numbers
CSc 110, Autumn 2017 Lecture 5: The for Loop and user input
CSc 110, Autumn 2017 Lecture 31: Dictionaries
CSc 110, Autumn 2016 Lecture 12: while Loops, Fencepost Loops, and Sentinel Loops Adapted from slides by Marty Stepp and Stuart Reges.
HW11 Assignment Specification
Adapted from slides by Marty Stepp and Stuart Reges
Lecture 8-3: Encapsulation, this
Critter exercise: Snake
CSc 110, Spring 2018 Lecture 9: Parameters, Graphics and Random
Homework 8: Critters (cont.)
CSE 142 Critters (IPL) behavior: Ant Bird Hippo Vulture
CSc 110, Autumn 2016 Lecture 9: input; if/else
CSc 110, Autumn 2017 Lecture 9: Graphics and Nested Loops
Adapted from slides by Marty Stepp and Stuart Reges
CSc 110, Autumn 2016 Lecture 10: Advanced if/else; Cumulative sum
Adapted from slides by Marty Stepp and Stuart Reges
The software crisis software engineering: The practice of developing, designing, documenting, testing large computer programs. Large-scale projects face.
Building Java Programs
Adapted from slides by Marty Stepp and Stuart Reges
CSc 110, Spring 2018 Lecture 7: input and Constants
CSc 110, Spring 2018 Lecture 5: The for Loop and user input
Adapted from slides by Marty Stepp and Stuart Reges
Building Java Programs
Building Java Programs
Building Java Programs
CSc 110, Spring 2018 Lecture 5: Loop Figures and Constants
CSc 110, Spring 2018 Lecture 8: input and Parameters
CSc 110, Spring 2018 Lecture 10: More Graphics
Adapted from slides by Marty Stepp and Stuart Reges
For loops Taken from notes by Dr. Neil Moore
CSc 110, Autumn 2017 Lecture 8: More Graphics
Homework 8: Critters (cont.)
Building Java Programs
Building Java Programs
Homework 9: Critters (cont.)
Building Java Programs
Building Java Programs
Adapted from slides by Marty Stepp and Stuart Reges
Presentation transcript:

Adapted from slides by Marty Stepp and Stuart Reges CSc 110, Autumn 2016 Lecture 32: Critters Adapted from slides by Marty Stepp and Stuart Reges

CSc 110 Critters behavior: Ant Bird Hippo Vulture WildCat (creative) eat eating food fight animal fighting get_color color to display get_move movement __str__ letter to display

A Critter subclass class name(Critter): class Critter: def eat() # returns True or False def fight(opponent) # ROAR, POUNCE, SCRATCH def get_color() # returns a hex string def get_move() # returns NORTH, SOUTH, EAST, WEST, CENTER def __str__()

How the simulator works Next move? "Go" → loop: move each animal (get_move) if they collide, fight if they find food, eat Simulator is in control! get_move is one move at a time (no loops) Keep state (fields) to remember future moves %

Development Strategy Simulator helps you debug Write your own main smaller width/height fewer animals "Tick" instead of "Go" Write your own main call your animal's methods and print what they return

Critter exercise: Cougar Write a critter class Cougar: Method Behavior __init__ eat Always eats. fight Always pounces. get_color Blue if the Cougar has never fought; red if he has. get_move Walks west until he finds food; then walks east until he finds food; then goes west and repeats. __str__ "C"

Ideas for state You must not only have the right state, but update that state properly when relevant actions occur. Counting is helpful: How many total moves has this animal made? How many times has it eaten? Fought? Remembering recent actions in fields is helpful: Which direction did the animal move last? How many times has it moved that way? Did the animal eat the last time it was asked? How many steps has the animal taken since last eating? How many fights has the animal been in since last eating?

Critter exercise: Anteater Write a critter class Cougar: Method Behavior __init__ eat Eats 3 pieces of food and then stops fight randomly chooses between pouncing and roaring get_color pink if hungry and red if full get_move walks up two and then down two __str__ "a" if hungry "A" otherwise