Carnegie Mellon Worcester Polytechnic Institute Programming Assignment 6

  • Slides: 9
Download presentation
Carnegie Mellon Worcester Polytechnic Institute Programming Assignment #6 Professor Hugh C. Lauer CS-2303 —

Carnegie Mellon Worcester Polytechnic Institute Programming Assignment #6 Professor Hugh C. Lauer CS-2303 — System Programming Concepts Slides include materials from The C Programming Language, 2 nd edition, by Kernighan and Ritchie, Absolute C++, by Walter Savitch, The C++ Programming Language, Special Edition, by Bjarne Stroustrup, and from C: How to Program, 5 th and 6 th editions, by Deitel and Deitel CS-2303, C-Term 2017 Programming Assignment #6 1

Carnegie Mellon Worcester Polytechnic Institute Assignment ¢ ¢ Design and implement a simple predator-prey

Carnegie Mellon Worcester Polytechnic Institute Assignment ¢ ¢ Design and implement a simple predator-prey simulation At least one abstract base class and at least two derived classes Virtual functions in the base class § Concrete implementations in each of the derived classes This is Project #3 of Chapter 15 of Absolute C++ CS-2303, C-Term 2017 Programming Assignment #6 2

Carnegie Mellon Worcester Polytechnic Institute Simulation ¢ ¢ N-by-N grid of cells § Similar

Carnegie Mellon Worcester Polytechnic Institute Simulation ¢ ¢ N-by-N grid of cells § Similar to Game of Life Each cell may be occupied by at most one organism Two types of organisms § Ants § Doodlebugs Simulate a sequence of steps § Each step represents an action by each organism CS-2303, C-Term 2017 Programming Assignment #6 3

Carnegie Mellon Worcester Polytechnic Institute Simulation steps Ants ¢ Doodlebugs Move: – ¢ §

Carnegie Mellon Worcester Polytechnic Institute Simulation steps Ants ¢ Doodlebugs Move: – ¢ § Try to move in random direction § Up, down, left, right § If all occupied, stay put § No moving off edge of grid ¢ ¢ Breed: – § If survive >= 3 steps § Give birth to new ant in adjacent cell § No empty cell, no birth CS-2303, C-Term 2017 ¢ Move: – § Move to adjacent cell with ant § Eat ant § If no ant, move to empty cell § If no empty cell, stay put Breed: – § If survive >= 8 steps § Give birth in adjacent cell § No empty cell, no birth Starvation: – § If no eat in 3 steps, die Programming Assignment #6 4

Carnegie Mellon Worcester Polytechnic Institute Simulation steps (continued) ¢ ¢ Doodlebugs move before ants

Carnegie Mellon Worcester Polytechnic Institute Simulation steps (continued) ¢ ¢ Doodlebugs move before ants § I. e. , a doodlebug can eat an ant before the ant moves Starvation takes precedence over breeding § I. e. , a starving doodlebug cannot give birth before dying If an organism cannot breed due to lack of space, § … it remains eligible to breed on next move Print a summary at end of simulation § See Project Assignment document CS-2303, C-Term 2017 Programming Assignment #6 5

Carnegie Mellon Worcester Polytechnic Institute Implementation ¢ ¢ Any design for implementing grid §

Carnegie Mellon Worcester Polytechnic Institute Implementation ¢ ¢ Any design for implementing grid § E. g. , array of C++ vectors § C-style 2 -D array (as in Game Of Life) § Anything else appropriate § Size determined at run time Grid elements are organism * § Null pointer empty cell § Invoke move() method of non-empty cell § move() method may invoke other methods § CS-2303, C-Term 2017 E. g. , eat, breed, etc. Programming Assignment #6 6

Carnegie Mellon Worcester Polytechnic Institute Implementation (continued) ¢ Command Line arguments. /PA 6 grid.

Carnegie Mellon Worcester Polytechnic Institute Implementation (continued) ¢ Command Line arguments. /PA 6 grid. Size #doodlebugs #ants #time_steps seed pause ¢ ¢ Any argument can be omitted § See project specification for default values § All subsequent values defaulted Pause value may be zero or non-negative § If n > 0, pause every nth step, print grid, wait for any key before proceeding CS-2303, C-Term 2017 Programming Assignment #6 7

Carnegie Mellon Worcester Polytechnic Institute Teams ¢ Optional two-person teams ¢ Due Thursday, March

Carnegie Mellon Worcester Polytechnic Institute Teams ¢ Optional two-person teams ¢ Due Thursday, March 2 @ 6: 00 PM ¢ I. e. , evening before last day of term! CS-2303, C-Term 2017 Programming Assignment #6 8

Carnegie Mellon Worcester Polytechnic Institute Questions? CS-2303, C-Term 2017 Programming Assignment #6 9

Carnegie Mellon Worcester Polytechnic Institute Questions? CS-2303, C-Term 2017 Programming Assignment #6 9