#ifndef POSITION_H #define POSITION_H #include #include struct Position { virtual bool connected(Position *) = 0; virtual int distance(Position *) = 0; virtual ostream &display(ostream &o) = 0; friend inline ostream &operator<< (ostream &out, Position &pos) { return pos.display(out); } }; typedef Position* (*PosInit) (const void *&, int i); template struct Point : public Position { T coord[Dim]; int ind; Point(const void *&data, int i) {read(data, i);} bool connected(Point *p) { if ((p->ind&1)==(ind&1)) return false; return ((ind<=(p->ind+3)) && (ind>=(p->ind-3))); } bool connected(Position *p) { return connected((Point*)p); } int distance(Point *p) { double diff, sum = 0.0; for (int i=0; icoord[i] - coord[i]; sum += diff*diff; } return ((int)(1.0+(100.0*sqrt(sum)))); } int distance(Position *p) { return distance((Point*)p); } void read(const void *&data, int i); ostream &display(ostream &o); }; template void Point::read(const void *&data, int i) { T* x = (T*)data; for (int i=0; i ostream& Point::display(ostream& o) { o << "(" << coord[0]; for (int i=1; i struct PointB : public Point { PointB(const void *&data, int i) : Point(data,i) {} bool connected(Position *p) { return true; } }; #endif /* POSITION_H */