stochastic simulation, predator/prey

Dependencies:   mbed

Committer:
manitou
Date:
Mon Dec 23 18:56:56 2019 +0000
Revision:
0:fc1335b7b54f
stochastic simulation

Who changed what in which revision?

UserRevisionLine numberNew contents of line
manitou 0:fc1335b7b54f 1 #ifndef ORGANISM_H
manitou 0:fc1335b7b54f 2 #define ORGANISM_H
manitou 0:fc1335b7b54f 3
manitou 0:fc1335b7b54f 4 enum OrganismType {ANT, BUG};
manitou 0:fc1335b7b54f 5
manitou 0:fc1335b7b54f 6 // forward declaration
manitou 0:fc1335b7b54f 7 class World;
manitou 0:fc1335b7b54f 8
manitou 0:fc1335b7b54f 9 class Organism {
manitou 0:fc1335b7b54f 10 public:
manitou 0:fc1335b7b54f 11 // Create an organism at the given coordinates.
manitou 0:fc1335b7b54f 12 Organism(World* aWorld, int xcoord, int ycoord);
manitou 0:fc1335b7b54f 13 virtual ~Organism() { }
manitou 0:fc1335b7b54f 14
manitou 0:fc1335b7b54f 15 // In the given world moves this organism.
manitou 0:fc1335b7b54f 16 virtual void move() = 0;
manitou 0:fc1335b7b54f 17
manitou 0:fc1335b7b54f 18 // Makes this organism breed.
manitou 0:fc1335b7b54f 19 virtual void breed() = 0;
manitou 0:fc1335b7b54f 20
manitou 0:fc1335b7b54f 21 // Returns the type of this organism.
manitou 0:fc1335b7b54f 22 virtual OrganismType getType() const = 0;
manitou 0:fc1335b7b54f 23
manitou 0:fc1335b7b54f 24 // Flags this organism as moved or not.
manitou 0:fc1335b7b54f 25 void setMoved(bool hasMoved);
manitou 0:fc1335b7b54f 26
manitou 0:fc1335b7b54f 27 // The character representation of this organism.
manitou 0:fc1335b7b54f 28 virtual char representation() const = 0;
manitou 0:fc1335b7b54f 29
manitou 0:fc1335b7b54f 30 // The size of this organism.
manitou 0:fc1335b7b54f 31 virtual int size() const = 0;
manitou 0:fc1335b7b54f 32
manitou 0:fc1335b7b54f 33 // Has this organism moved in this time slot or not?
manitou 0:fc1335b7b54f 34 bool hasMoved() const;
manitou 0:fc1335b7b54f 35
manitou 0:fc1335b7b54f 36 // Returns true if organism is dead, false otherwise.
manitou 0:fc1335b7b54f 37 virtual bool isDead() const;
manitou 0:fc1335b7b54f 38
manitou 0:fc1335b7b54f 39 bool in_range(int xx, int yy);
manitou 0:fc1335b7b54f 40
manitou 0:fc1335b7b54f 41 protected:
manitou 0:fc1335b7b54f 42 // Generates an offspring at the given position.
manitou 0:fc1335b7b54f 43 virtual void generateOffspring(int whereX, int whereY) = 0;
manitou 0:fc1335b7b54f 44
manitou 0:fc1335b7b54f 45 // Moves this organism from coordinates (x,y) to (xNew,yNew).
manitou 0:fc1335b7b54f 46 void movesTo(int xNew, int yNew);
manitou 0:fc1335b7b54f 47
manitou 0:fc1335b7b54f 48 // Breeds a new organism at an adjacent cell. Tries to produce one new
manitou 0:fc1335b7b54f 49 // organism in UP, DOWN, LEFT, or RIGHT cell (in that order). Makes
manitou 0:fc1335b7b54f 50 // sure not to breed off the grid.
manitou 0:fc1335b7b54f 51 void breedAtAdjacentCell();
manitou 0:fc1335b7b54f 52
manitou 0:fc1335b7b54f 53 // This organism's x position in the world.
manitou 0:fc1335b7b54f 54 int x;
manitou 0:fc1335b7b54f 55
manitou 0:fc1335b7b54f 56 // This organism's y position in the world.
manitou 0:fc1335b7b54f 57 int y;
manitou 0:fc1335b7b54f 58
manitou 0:fc1335b7b54f 59 // Has moved this turn?
manitou 0:fc1335b7b54f 60 bool moved;
manitou 0:fc1335b7b54f 61
manitou 0:fc1335b7b54f 62 // Number of ticks since breeding.
manitou 0:fc1335b7b54f 63 int breedTicks;
manitou 0:fc1335b7b54f 64
manitou 0:fc1335b7b54f 65 // A pointer to the world in which this organism lives.
manitou 0:fc1335b7b54f 66 World* world;
manitou 0:fc1335b7b54f 67 private:
manitou 0:fc1335b7b54f 68 };
manitou 0:fc1335b7b54f 69
manitou 0:fc1335b7b54f 70 #endif // ORGANISM_H