#include "field.h" #include // boundless Game of Life - long test class LiveCell : public Agent { bool check; // false - clone offsprings, true - check whether to stay bool proper; // true - proper live cell, false - candidate for cell public: static int nagents; LiveCell(bool isnew=true) : check(!isnew), proper(isnew) { nagents++; } ~LiveCell() { nagents--; } Agent* clone() const { return new LiveCell(false); } long priority() const {return proper; } // proper cell have higher priority char state() const { return proper?'X':'.'; } Answer act(const vector &surrounding, const vector& myposition,long level) { if (!check) { // check next turn check=true; // clone offsprings vector offsprings; for (Dir d=E; d<=SE; d=Dir(d+1)) offsprings.push_back(d); return Answer(CLONE,offsprings); } else { // clone offsprings next turn check=false; if (proper) // stay alive only if 2 or 3 neighbors, i.e., 2 or 3 clones if (myposition.size()==3 || myposition.size()==4) return Answer(STAY,vector()); else return Answer(DIE,vector()); else // if not the first candidate die if (level!=0) return Answer(DIE,vector()); // if number of canditates is exactly 3 stay else if (myposition.size()==3) { // become proper proper=true; return Answer(STAY,vector()); } else // die return Answer(DIE,vector()); } } }; int LiveCell::nagents=0; int main() { vector living(5); living[0]=Point(3,1); living[1]=Point(2,2); living[2]=Point(3,2); living[3]=Point(3,3); living[4]=Point(4,3); { Field F(30,20); for (vector::iterator i=living.begin(); i!=living.end(); i++) F.plant_agent(Point(i->x+20,i->y+6),new LiveCell); cout <<"Initial state:"<