#ifndef FIELD_H_ #define FIELD_H_ #include #include #include using namespace std; class Agent { public: enum Action {STAY, DIE, MOVE, CLONE}; // this defines a new type which can have only above possible values // (see p. 141 in the textbook for details) // to access the type or values you have to use scope resolution operator // (for instance, Agent::Action a=Agent::STAY) enum Dir {E, NE, N, NW, W, SW, S, SE}; Agent() {} virtual ~Agent() {} virtual Agent *clone() const =0; virtual long priority() const =0; virtual char state() const =0; typedef pair > Answer; // shortcut virtual Answer act(const vector &surrounding, const vector& myposition,long level) =0; }; class Point { public: int x,y; Point(int ix=0,int iy=0) : x(ix), y(iy) {} bool operator==(const Point &p) const { return (x==p.x && y ==p.y); } bool operator <(const Point &p) const { return (x Region; class Field { //private interface private: //data structure to hold all cell with corresponding agents sorted by their priority map > grid; long no_agents; //structure used in step() struct temp_ { long level; Point p; Agent *agent; vector mypos; vector surr; } ; typedef temp_ tmp; //field size int sx , sy; //returns a point corresponding to the direction and point provided. Point getP (Agent::Dir , Point p); public: // public interface: Field(int sizex, int sizey); // construct field with no agents of size sizex x sizey ~Field(); // call delete on all pointers to agents stored in the field // ADDING AGENTS: void plant_agent(const Point &p, Agent *a); // put agent a to the cell p // EXAMINING AGENTS: long n_of_agents() const; // return the total number of agents currently on the field long n_of_agents(const Point &p) const; // return the number of agents in the cell p const Agent *get_agent(const Point &p, long i) const; // return a pointer to the i-th agent in the cell p // if i<0 or i>=n_of_agents(p) return NULL pointer // REMOVING AGENTS: void remove_agent(const Point &p, long i); // if i>=0 or i