//CMPT-212, ASSIGNMENT 3 1/2 - Field Header File //Raymond Kin Hei Lee //March 23, 2008 //Anything different from the field.h template are commented #ifndef FIELD_H_ #define FIELD_H_ #include #include using namespace std; class Agent { public: enum Action {STAY, DIE, MOVE, CLONE}; 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; 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; } }; ostream& operator<<(ostream& C, const Point &p); typedef pair Region; typedef pair,vector> agentInfo; typedef pair direction; class Field { private: vector> grid; //The outside vector represents the whole grid, using // i = (sizex*p.y + p.x) relationship. Within each point on the grid, there is //still a vector of Agent pointers, so more than one agent can fit at a single location long convert(const Point &p) const; //Converts a Point, to an integer that vector can understand void sort(const long &point); //For a single point on the grid, sorts the agents by priorities agentInfo findInfo(const Point &p); //Finds the representative agent information for a single point // agentInfo is a pair with vector findDirection(Point, vector dir); //Changes the directions (N, NE, S, etc..) into meaningful Points int sizex;//Keeps track of xMax int sizey;//keeps track of yMax public: Field(int sizex, int sizey); ~Field(); void plant_agent(const Point &p, Agent *a); long n_of_agents() const; long n_of_agents(const Point &p) const; const Agent *get_agent(const Point &p, long i) const; void remove_agent(const Point &p, long i); void remove_agent(const Point &p); void remove_agent(const Region &r); char get_state(const Point &p) const; void step(long n=1); friend ostream & operator<<(ostream &os, const Field &s); }; #endif