/// Traveller.h header  file
/////////////////////////////////////////////////////////////////////

///include  files:
#include <vector>
#include <cmath>
#include <iostream>
#include <fstream>
//...

const  double  step = 0.01; // determines speed
const  double  lakeRadius {1};
const double Pi = 3.14159265358979;

class  Point {
public:
    double x;  //rectangular coordinates
    double y;
    double r; ///polar coordinates
    double theta;
    Point(double x, double y); //constructor
    Point operator+(const Point&); //overload addition operator
    Point operator-(const Point&); //overload subtraction operator
    Point operator*(const double); //overload multiplication operator where right operand is double
    Point operator/(const double); //overload multiplication operator where right operand is double
    Point operator+=(const Point&);
    double setTheta(double,double);

};

/// prototype for overloading insertion operator
std::ostream& operator<<(std::ostream&, const Point& p);

class  Traveller {
public:
    char kind; //'a' for "astronaut" and 'z' for "zorkoid"
    Point currentLoc; // Where's Waldo?
    double speed; // Generally a small number, but zorkoid goes faster
    double bearing{0}; // direction the Traveller is headed (maybe not useful?)
    std::vector<Point> path; // history of locations
    void updateLoc(Point); //engine for moving, depends on 'kind'
    void updateBearing(double ); //not sure this is useful yet
    void updatePath(); // could be built into updateLoc()
    void printPath(std::ofstream&);
    bool onShore(); ///is r >= lakeRadius?
    Traveller(Point p, double s, char kind); //constructor
};

///////////////////////////////////////////////////////////////////////////////
/// Implementation for Traveller.h

#include "Traveller.h"

double Point::setTheta(double xin, double yin) {
    if(xin==0 && yin==0) return 0; /// check for special cases first
    if(xin==0 && yin>0)
        return Pi/2;
    else if(xin==0 && yin<0)
        return -Pi/2;
    else
        return x>0 ? atan(y/x) : Pi+atan(y/x);
}

Point::Point(double xin, double yin) : x(xin), y(yin) {
    r = sqrt(x*x+y*y);
    theta = setTheta(x,y);
}

Point Point::operator+(const Point& p) {
    return Point(x+p.x,y+p.y);
}

Point Point::operator-(const Point& p) {
    ///write code here
}

Point Point::operator*(const double m) {
    ///write code here
}

Point Point::operator/(const double m) {
    if(m==0) return *this;
    ///write code here
}

Point Point::operator+=(const Point& p) {
    ///write code here
}

/// define overloaded insertion operator for Point
std::ostream& operator<<(std::ostream& os, const Point& p) {
    //os << '(' << p.x << ',' << p.y << ')';
    os << p.x << ',' << p.y;
    return os;
}

Traveller::Traveller(Point p, double s, char k)
 : currentLoc(p), speed(s), kind(k) {}

void  Traveller::updateLoc(Point p) { ///p is the location of the other Traveller
    if(kind=='a') { /// update astronaut
        ///write code here
    }
    else { /// update zorkoid
       ///write code here
    }
}

void Traveller::printPath(std::ofstream& of) {
    for(Point p: path)
        ///write code here
}

bool  Traveller::onShore() {
    return  currentLoc.r>=lakeRadius;
}

///... more  definitions , as  needed

//////////////////////////////////////////////////////
///  G. Hagopian : Escape from Zorkon

#include "Traveller.h"
#include <fstream>
using namespace std;

const  int  maxSteps = 2000;
const double fasterFactor = 4.0;

int main() {
    int steps{0}; //count how many times you've moved
    Point east(1,0); /// starting point of zorkoid
    cout << "\neast = " << east;
    Point origin(0,0); /// starting point of astronaut
    Traveller astronaut(origin, step, 'a'); ///construct astronaut
    cout << "\nastronaut starts at " << astronaut.currentLoc;
    Traveller zorkoid(east, fasterFactor*step , 'z'); ///construct zorkoid
    ofstream ofa("aPath.txt"), ofz("zPath.txt");
    while(!astronaut.onShore() && steps < maxSteps) {
        /// update  zorkoid 's position (note  that it must be on  shore) and  path
		/// write code here
        /// update  spaceman 's bearing
        cout << "\nzorkoid is at " << zorkoid.currentLoc;
        /// update  spaceman 's position  and  path
        /// write code here
        ///...
        cout << "\nastronaut is at " << astronaut.currentLoc;
        ++steps;
        //cin.get();
    }
    /// write code here
}