-- -*- Mode: Sather; -*- -- File: creature.sa -- Author: Chu-Cheow Lim (clim@ICSI.Berkeley.EDU) -- Copyright (C) International Computer Science Institute, 1993 -- -- COPYRIGHT NOTICE: This code is provided "AS IS" WITHOUT ANY WARRANTY -- and is subject to the terms of the SATHER LIBRARY GENERAL PUBLIC -- LICENSE contained in the file: "sather/doc/license.txt" of the Sather -- distribution. The license is also available from ICSI, 1947 Center -- St., Suite 600, Berkeley CA 94704, USA. --*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --* FUNCTION: --* --* CLASSES: --* --* REQUIRED FILES: --* --* RELATED FILES: --* --* HISTORY: --* Last edited: Jun 1 16:17 1993 (clim) --* Created: Fri May 21 12:08:08 1993 (clim) --*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ class ABSTRACT_CREATURE is -- Abstract ancestor class of "SHARK" and "FISH". shared breed_age:INT := 10; -- Breeding age to be re-determined by each descendent. age:INT; -- Age. pos_x,pos_y:INT; -- Position. -- Instead of using COMPLEX, we could use integers for the creature position -- when the grid is discretized. -- Eg of extensibility: -- * Suppose the position is continuous instead of discrete, then only -- the definitions in "ABSTRACT_CREATURE" need be changed. create(x,y:INT):SELF_TYPE is -- Allocate a creature at (x,y) position. res := new; res.pos_x := x; res.pos_y := y; end; -- create init(x,y:INT) is -- Initialize creature's attribute ((x,y) position in this case). update_pos(x,y); end; -- init update_pos(x,y:INT) is pos_x := x; pos_y := y; end; -- update_pos end; -- class ABSTRACT_CREATURE --~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ class ABSTRACT_PREDATOR is ABSTRACT_CREATURE; shared starve_time:INT := 1; -- Length of time that a predator can go on without eating. starve_age:INT; -- Predators have an additional attribute that indicates how long one has been -- starving. end; -- class ABSTRACT_PREDATOR --~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ class ABSTRACT_PREY is ABSTRACT_CREATURE; end; -- class ABSTRACT_PREY --~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ class SHARK is ABSTRACT_PREDATOR; shared breed_age:INT := 10; shared starve_time:INT := 1; -- Length of time that a shark can go on without eating. create(x,y:INT):SELF_TYPE is -- Allocate a shark at (x,y) position. res := new; res.init(x,y); end; -- create end; -- class SHARK --~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ class FISH is ABSTRACT_PREY; shared breed_age:INT := 1; create(x,y:INT):SELF_TYPE is -- Allocate a fish at (x,y) position. res := new; res.init(x,y); end; -- create end; -- class FISH --~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~